How to Create PDF using Python

Aspose.PDF for Python via .NET is a PDF manipulation API that allows developers to create, load, modify, and convert PDF files directly from Python for .NET applications with just a few lines of code.

How to Create Simple PDF File

To create a PDF using Python via .NET with Aspose.PDF, you can follow these steps:

  1. Create an object of Document class
  2. Add a Page object to the pages collection of the Document object
  3. Add TextFragment to paragraphs collection of the page
  4. Save the resultant PDF document

    import aspose.pdf as ap

    # Initialize document object
    document = ap.Document()
    # Add page
    page = document.pages.add()
    # Add text to new page
    page.paragraphs.add(ap.text.TextFragment("Hello World!"))
    # Save updated PDF
    document.save(output_pdf)