Example of Hello World using Python language

Contents
[ ]

A simple use case can help to demonstrate the features of a programming language or software. This is usually done with a “Hello World” example.

Aspose.PDF for Python via C++ is a powerful PDF API that enables the developers to create, manipulate and convert PDF documents in their Python applications. It supports working with various file formats such as PDF, XFA, TXT, HTML, PCL, XML, XPS, EPUB, TEX and image file formats. In this article, we will show you how to create a PDF document with the text “Hello World!” using Aspose.PDF API. You need to install Aspose.PDF for Python via C++ in your environment before running the following code sample.

  1. Import the AsposePdfPython module.
  2. Create a new PDF document object using the document_create function.
  3. Get the pages collection of the document using the document_get_pages function.
  4. Add a new page to the pages collection using the page_collection_add_page function.
  5. Get the paragraphs collection of the page using the page_get_paragraphs function.
  6. Creating a new image object using the image_create function.
  7. Setting the file name of the image object to “sample.jpg” using the image_set_file function.
  8. Adding the image object to the paragraphs collection using the paragraphs_add_image function.
  9. Saving the document to a file named “document.pdf” using the document_save function.
  10. Closing the document handle using the close_handle function.

The following code snippet is a Hello World program that demonstrates how to Aspose.PDF for Python via C++ works.

from AsposePdfPython import *
 
doc = document_create()
pages = document_get_pages(doc)
page = page_collection_add_page(pages)
paragraphs = page_get_paragraphs(page)
image = image_create()
image_set_file(image,"sample.jpg")
paragraphs_add_image(paragraphs,image)
 
document_save(doc, "document.pdf")
close_handle(doc)