Created
September 2, 2015 21:22
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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