Use GroupDocs.Markdown to convert PDF documents to clean Markdown.
Using static method
The simplest way to convert a PDF file:
importosfromgroupdocs.markdownimportLicense,MarkdownConverterdefexport_pdf_to_markdown():"""Convert a PDF document to Markdown using the static one-liner API."""# Step 1: Apply the license (optional for evaluation)ifos.path.exists("GroupDocs.Markdown.lic"):License.set_("GroupDocs.Markdown.lic")# Step 2: Convert PDF to a Markdown string in one callmarkdown=MarkdownConverter.to_markdown("business-plan.pdf")# Step 3: Or save the conversion result directly to a fileMarkdownConverter.to_file("business-plan.pdf","export-pdf.md")if__name__=="__main__":export_pdf_to_markdown()
business-plan.pdf is sample file used in this example. Click here to download it.
importosfromgroupdocs.markdownimportLicense,MarkdownConverter,ConvertOptions,ExportImagesToFileSystemStrategydefexport_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)ifos.path.exists("GroupDocs.Markdown.lic"):License.set_("GroupDocs.Markdown.lic")# Step 2: Open the PDF document with a context managerwithMarkdownConverter("business-plan.pdf")asconverter:# Step 3: Configure the image export strategy to save images to diskstrategy=ExportImagesToFileSystemStrategy("images")strategy.images_relative_path="images"# Step 4: Set conversion optionsoptions=ConvertOptions()options.image_export_strategy=strategyoptions.heading_level_offset=1# shift all headings down one level# Step # Step 5: Convert and save the Markdown outputconverter.convert("export-pdf-options.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.