Skip to content

Instantly share code, notes, and snippets.

@aspose-com-kb
Last active November 2, 2024 03:56
Convert Markdown to PDF in Python. For more details: https://kb.aspose.com/html/python/convert-markdown-to-pdf-in-python/
import os
import aspose.html
from aspose.html import *
from aspose.html.converters import *
from aspose.html.saving import *
# Prepare the paths to the files
output_dir = "C:/"
source_path = os.path.join(output_dir, "document.md")
save_path = os.path.join(output_dir, "PDF-output.pdf")
# Prepare a simple Markdown example
code = "### Hello, World!\nConvert Markdown to PDF!"
# Create a Markdown file
with open(source_path, "w") as file:
file.write(code)
# Convert Markdown to HTML document
document = Converter.convert_markdown(source_path)
# Convert HTML document to PDF file format
Converter.convert_html(document, PdfSaveOptions(), save_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment