Example of Hello World using Python

Contents
[ ]

A “Hello World” example shows the simplest syntax and the simplest program in any given programming language. Developers are introduced to the basic programming language syntax by learning how to print “Hello World” on the device screen. Therefore, we will traditionally start our acquaintance with our library from it.

In this article, we are creating a PDF document containing text “Hello World!”. After installing Aspose.PDF for Python via .NET in your environment, you can execute below code sample to see how Aspose.PDF API works.

Below code snippet follows these steps:

  1. Instantiate a Document object
  2. Add a Page to document object
  3. Create a TextFragment object
  4. Add TextFragment to paragraphs collection of the page
  5. save() resultant PDF document

Following code snippet is a “Hello World” program to exhibit working of Aspose.PDF for Python via .NET API.


    import aspose.pdf as ap

    # Initialize document object
    document = ap.Document()
    # Add page
    page = document.pages.add()
    # Initialize textfragment object
    text_fragment = ap.text.TextFragment("Hello,world!")
    # Add text fragment to new page
    page.paragraphs.add(text_fragment)
    # Save updated PDF
    document.save("output.pdf")