Posted By

markt22 on 10/12/17


Tagged

PDFBox


Versions (?)

PDFBox: Add text to page


 / Published in: Java
 

Creates a new document with a single page and adds text to it.

  1. /**
  2.  * @param args the command line arguments
  3.  * @throws java.io.IOException
  4.  */
  5. public static void main(String[] args) throws IOException {
  6. PDDocument document = new PDDocument();
  7. PDPage page = new PDPage(PDRectangle.A4);
  8.  
  9. document.addPage(page);
  10.  
  11. PDPageContentStream contentStream = new PDPageContentStream(document, page);
  12.  
  13. contentStream.beginText();
  14.  
  15. contentStream.setFont(PDType1Font.TIMES_ROMAN, 12);
  16. contentStream.newLineAtOffset(25, 500);
  17. contentStream.showText("Hello World");
  18.  
  19. contentStream.endText();
  20.  
  21. contentStream.close();
  22.  
  23. document.save("");
  24. document.close();
  25. }

Report this snippet  

You need to login to post a comment.