Skip to content

Instantly share code, notes, and snippets.

@JoelGeraci-Datalogics
Created September 2, 2015 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoelGeraci-Datalogics/d933ee12d477be4a2f5f to your computer and use it in GitHub Desktop.
Save JoelGeraci-Datalogics/d933ee12d477be4a2f5f to your computer and use it in GitHub Desktop.
This sample allows users to create a new blank PDF and place the text "Hello, World!" onto it. This PDF is saved and written out to a file called HelloWorld.pdf.
/*
* Copyright 2015 Datalogics Inc.
*/
package pdfjt.cookbook.document;
import pdfjt.util.SampleFileServices;
import com.adobe.pdfjt.pdf.document.PDFDocument;
import com.adobe.pdfjt.pdf.document.PDFOpenOptions;
import com.datalogics.pdf.document.DocumentHelper;
import com.datalogics.pdf.layout.LayoutEngine;
import com.datalogics.pdf.text.Paragraph;
/**
* This sample allows users to create a new blank PDF and place the text
* "Hello, World!" onto it. This PDF is saved and written out to a file called
* HelloWorld.pdf.
*/
public final class HelloWorld {
private static final String outputDir = "cookbook/Document/output/";
private static final String outputFile = "HelloWorld.pdf";
public static void main(String[] args) throws Exception {
PDFDocument pdfDocument = PDFDocument.newInstance(PDFOpenOptions.newInstance());
/*
* The default layout engine will have a 1 inch margin around the entire
* page and layout text in 12 point Times New Roman.
*/
try (LayoutEngine layout = new LayoutEngine(pdfDocument)) {
Paragraph paragraph = new Paragraph("Hello, World!");
layout.add(paragraph);
}
SampleFileServices.createDir(outputDir);
DocumentHelper.saveFullAndClose(pdfDocument, outputDir + outputFile);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment