Skip to main content

Create PDF in Java

Create PDF in Java

Creating PDFs programmatically from scratch using DynamicPDF Core Suite is very straight forward. You have access to the document, pages in the document and content (using page elements) on each page.

How to Create a PDF in Java​

Below are the steps and sample code to create a PDF document using the Generator product.

Steps for Creating a PDF Document​

  1. Create a Document object.
  2. Create a Page object and add it to the Document.
  3. Create a Label object (or any other page element) and add it to the Page.
  4. Save the PDF document.

Sample Code - Java​

Document objDocument = new Document();

Page objPage = new Page(PageSize.LETTER, PageOrientation.PORTRAIT, 54.0f);
objDocument.getPages().add(objPage);

String labelText = "Hello World...\nFrom DynamicPDF Generator for Java\nDynamicPDF.com";
Label objLabel = new Label(labelText, 0, 0, 504, 100, Font.getHelvetica(), 18, TextAlign.CENTER);
objPage.getElements().add(objLabel);

objDocument.draw("output.pdf");

Over 75 Page Elements​

DynamicPDF Generator contains over 75 page elements so you can add rich content to the PDFs you create:

  • Images
  • Text Objects (TextArea and Label)
  • HTML
  • Barcodes (47 types)
  • Form Fields
  • Charts

Getting Started​

DynamicPDF Generator Information​

More information can be found here:

Available in Other Platforms​

DynamicPDF Generator is available for the following platforms. Refer to the respective product pages for more details.