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 L402 payment using a payment mechanism of your choice. This could be a manual payment (handled by copy and pasting the lightning invoice into a wallet of your choice), but more likely, will be handled using an automated means of programatically manipulating a lightning wallet directly.