Skip to main content

Documentation Index

Fetch the complete documentation index at: https://markdown2pdf.ai/llms.txt

Use this file to discover all available pages before exploring further.

Here’s a few examples of how to use markdown2pdf.ai in your code.
pip install markdown2pdf-python
from markdown2pdf import MarkdownPDF

def pay(offer):
    print("⚡ Lightning payment required")
    print(f"Amount: {offer['amount']} {offer['currency']}")
    print(f"Description: {offer['description']}")
    print(f"Invoice: {offer['payment_request']}")
    input("Press Enter once paid...")

client = MarkdownPDF(on_payment_request=pay)
path = client.convert(markdown="# Hello from Python", title="My document title", download_path="output.pdf")
print("Saved PDF to:", path)
You’ll see that, in general, you pass your markdown content, a title and a download path to the convert function and it will handle the markdown conversion for you. A mandatory function must be provided which is used to handle the payment using a mechanism of your choice — either Lightning via L402 or USDC on Solana via X402. This could be a manual payment (copy-and-paste the Lightning invoice into a wallet of your choice, or sign an X402 X-PAYMENT header with a Solana wallet), but more likely will be handled programmatically via a Lightning wallet or a Solana signer.