Hello World Java Example

Hello World Example

A “Hello World” example is traditionally used to introduce features of a programming language or software with a simple use case.

Aspose.PDF for Java API empowers Java application developers to create, read, edit and manipulate PDF files in their applications. It lets you read and convert several different file types to and from PDF file format. This Hello World article shows how to create a PDF file in Java using Aspose.PDF for Java API. After installing Aspose.PDF for Java in your environment, you can execute the 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 Paragraph collection of the page
  5. Save the resultant PDF document

The following code snippet is a Hello World program to exhibit the working of Aspose.PDF for Java API.

// Initialize document object
Document document = new Document();
//Add page
Page page = document.getPages().add();
// Add text to new page
page.getParagraphs().add(new TextFragment("Hello World!"));
// Save updated PDF