PDFBox: Draw rectangle on page


/ Published in: Java
Save to your folder(s)

Creates a new document with one page and draws a rectangle on it.


Copy this code and paste it in your HTML
  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.setNonStrokingColor(Color.RED);
  14. contentStream.addRect(100, 100, 100, 100);
  15. contentStream.fill();
  16.  
  17. contentStream.close();
  18.  
  19. document.save("");
  20. document.close();
  21. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.