tags:

views:

114

answers:

2

I tried to use the org.apache.fop.pdf package but not success.

Appreciated if someone can give some working examples to:

  • Create PDFDocument

  • Add PDFPage to PDFDocument

  • Add some text to PDFPage

A: 

You might want to look at Docmosis, JODReports or Jasper. Depending on your requirements you might find one of these easier to use. They all have reasonable documentation.

jowierun
A: 

FOP's PDF library is not particularly suited to generate PDF documents by hand. It wasn't designed to be user-friendly for that use case. It is relatively easy by using org.apache.fop.svg.PDFDocumentGraphics2D but only as long as you don't need special fonts in which cases some additional tricks are required which are not well documented. org.apache.fop.svg.PDFTranscoder could give you some hints in that case.

More easy and flexible is to just use FOP in its natural way: by creating XSL-FO. Creating PDFs directly in Java is often inflexible, especially if requirements change. XSLT + XSL-FO are then easier to handle IMO.

Another library you could look at if you really want to build a PDF by hand in Java code is Apache PDFBox.

Jeremias Märki