You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Eric Douglas <ed...@blockhouse.com> on 2011/06/07 14:24:32 UTC

Create and Merge PDF What Am I Missing?

I used FOP to create a PDF in byte[] form.  Now I load the PDF into
pdfbox.  If I save it looks fine.
If I pass it into a viewer I get problems.

I generated an array of these PDFs and I need to combine them.
I start with just saving the first one.
ByteArrayInputStream myBAIS = new
ByteArrayInputStream(myByteData.get(0));
PDDocument myPDDocument = PDDocument.load(myBAIS);
myPDDocument.save(myJobName + ".pdf");

If I open this PDF in Adobe Acrobat I can see everything just fine.
If I open this PDF in a viewer it shows all graphics, including SVG and
blocks with borders, but no text.
I tried loading it into iText with the sample code found here
(http://technology.amis.nl/blog/4174/java-generating-pdf-and-previewing-
it-as-an-image-itext-and-pdf-renderer).
I tried loading it into PDFRenderer
(http://java.net/projects/pdf-renderer) using the viewer in their trunk
demos, same result.
No errors on either, they just don't display text.
Now I try merging PDFs and again I can save the PDF I created and it
looks fine in Acrobat though it's missing something.
If there's only one PDF in my array, this method saves it about 2k
smaller than saving it directly.
The PDF array is a single document of separate documents, generated
using xsl:initial-page-number.

PDDocument myPDDocument = new PDDocument();
ArrayList<PDDocument> part = new ArrayList<PDDocument>();
for (int pdfLoop = 0; pdfLoop < myByteData.size(); pdfLoop ++) {
     ByteArrayInputStream myBAIS = new
ByteArrayInputStream(myByteData.get(pdfLoop));
     part.add(PDDocument.load(myBAIS));
     myBAIS.close();
     PDDocument partDoc = part.get(pdfLoop);
     @SuppressWarnings("unchecked")
     List<PDPage> list = partDoc.getDocumentCatalog().getAllPages();
     for (PDPage page : list) {
          myPDDocument.addPage(page);
     }
}
myPDDocument.save(myJobName + ".pdf");

I get this error from the PDFRenderer viewer on the merged PDF:
com.sun.pdfview.PDFParseException: No dictionary called Font found in
the resources
	at com.sun.pdfview.PDFParser.findResource(PDFParser.java:912)
	at com.sun.pdfview.PDFParser.getFontFrom(PDFParser.java:1165)
	at com.sun.pdfview.PDFParser.iterate(PDFParser.java:719)
	at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
	at java.lang.Thread.run(Thread.java:662)