Pdf to Md

Use GroupDocs.Markdown to convert PDF documents to clean Markdown.

Using static method

The simplest way to convert a PDF file:

import os
from groupdocs.markdown import License, MarkdownConverter

def export_pdf_to_markdown():
    """Convert a PDF document to Markdown using the static one-liner API."""

    # Step 1: Apply the license (optional for evaluation)
    if os.path.exists("GroupDocs.Markdown.lic"):
        License.set_("GroupDocs.Markdown.lic")

    # Step 2: Convert the PDF directly to a Markdown file
    MarkdownConverter.to_file("business-plan.pdf", "export-pdf-static.md")

if __name__ == "__main__":
    export_pdf_to_markdown()

business-plan.pdf is sample file used in this example. Click here to download it.

![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAlgAAAC0CAIAAADHHcVbAAAAA3NCSVQICAjb4U/gAAAMWElEQVR4nO3dUWzV130H8L+nSnsgxYTa5kbEnhJgJpJ98aQseTAxUaoiW1RDSiseykoCNE9boyoIZEWLVImosoZSpeve0Ighax4iDRRpky02oWKbh2aVCralhGBANSAu4Lq5NJ60tz0c8t/lf6/h2jjg/M/nIz8c7v/v3z345atz/v9zTkNpaiwBgFj92aPuAAA8SoIQgKgJQgCiJggBiNo3Mv/+53/9r4tXbi6u1t/v/Pa6tjXzXV1cZTXVVFNNNdVc2poZ2SCcmr4xfv7KQr8y+NPc/97j6uIqq6mmmmqqqebS1szIBuH6tjUNDQ0Xp2988T8LqAIAX1NLOSIEgK+dhsyC+p/87FdpEP7dzm+va613jjVJkvVtax5b8efzXb04fWNBY1U11VRTTTXVXJ
[TRUNCATED]

Download full output

Using instance API with options

For more control, use the instance API:

import os
from groupdocs.markdown import License, MarkdownConverter, ConvertOptions, ExportImagesToFileSystemStrategy

def export_pdf_with_options():
    """Convert a PDF to Markdown using the instance API with image export and heading offset."""

    # Step 1: Apply the license (optional for evaluation)
    if os.path.exists("GroupDocs.Markdown.lic"):
        License.set_("GroupDocs.Markdown.lic")

    # Step 2: Open the PDF document with a context manager
    with MarkdownConverter("business-plan.pdf") as converter:
        # Step 3: Configure the image export strategy to save images to disk
        strategy = ExportImagesToFileSystemStrategy("images")
        strategy.images_relative_path = "images"

        # Step 4: Set conversion options
        options = ConvertOptions()
        options.image_export_strategy = strategy
        options.heading_level_offset = 1  # shift all headings down one level

        # Step 5: Convert and save the Markdown output
        converter.convert("export-pdf-instance.md", convert_options=options)

if __name__ == "__main__":
    export_pdf_with_options()

business-plan.pdf is sample file used in this example. Click here to download it.

export-pdf-instance.md (7 KB)
images/img-001.png (3 KB)
images/img-002.jpg (73 KB)
images/img-003.jpg (76 KB)

Download full output

For the full list of input formats, see the supported formats page.

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.