Here is a sample code to add text to a PDF document content using Qoppa’s Java PDF Library, jPDFProcess.
import java.awt.Color; import java.awt.Font; import com.qoppa.pdfProcess.PDFDocument; import com.qoppa.pdfProcess.PDFGraphics; import com.qoppa.pdfProcess.PDFPage; public class AddText { public static void main (String [] args) { try { // load PDF document PDFDocument pdfDoc = new PDFDocument ("C:\\myfolder\\input.pdf", null); // draw text content into a PDF PDFPage page = pdfDoc.getPage(0); // get Helvetica font size 16 Font helveticaFont = PDFGraphics.HELVETICA.deriveFont(16f); // draw text on the page page.drawText("hello!", helveticaFont, Color.BLUE, 494, 14, null); // save the updated PDF document pdfDoc.saveDocument ("C:\\myfolder\\output.pdf"); } catch (Throwable t) { t.printStackTrace(); } } } |
Note: Helvetica® is a trademark Monotype Imaging Inc.