Example of Hello World using Python
Contents
[
Hide
]
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:
- Instantiate a Document object
- Add a Page to document object
- Create a TextFragment object
- Add TextFragment to paragraphs collection of the page
- 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")