pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Сергей Жиляев <us5...@bigmir.net>
Subject Error in Acrobat reader when composing a PDF from several PDF sources and adding text
Date Sat, 13 Nov 2010 16:24:28 GMT
Hello,

I am trying to compose one PDF from different PDF parts (examples line0.pdf,
line1.pdf, line6.pdf, and line ine12.pdf are attached) using the code close
to the following one:

PDDocument document = PDDocument.load(scoreLineFile);
PDPage page = (PDPage)
document.getDocumentCatalog().getAllPages().get(0);
PDStream formStream = page.getContents();
PDXObjectForm xObjectForm = new PDXObjectForm(formStream);
xObjectForm.setResources(page.getResources());
xObjectForm.setBBox(page.getMediaBox());
xObjectForm.setFormType(1);

...... // some code calculating position to output the xObjectForm on the
page

PDDocument outputDocument = new PDDocument();
PDPage outputPage = new PDPage();
outputDocument.addPage(outputPage);
outputPage .setMediaBox(PDPage.PAGE_SIZE_A4);
PDPageContentStream stream = new PDPageContentStream(document,
                page);
stream.drawXObject(xObjectForm, xCoordinate, yCoordinate, 1, 1);
stream.close();
outputDocument.close();
document.close();



It is opened in Acrobat reader fine.
But when I add any text on the same page, for instance with the code written
below (assuming that it is inserted before "stream.close"),

PDFont font = PDType1Font.getStandardFont("Courier");
float fontSize = 14;
contentStream.setFont( font, fontSize );
stream.beginText();
stream.moveTextPositionByAmount(200, 200);
stream.drawString("Any string");
stream.endText();

the Acrobat shows an error (see attached acrobat_error.JPG).
The same document is opened in the Apple Preview without any problems.

Can anyone help me to understand where is the problem?

Thanks,

Sergey

Mime
  • Unnamed multipart/mixed (inline, None, 0 bytes)
View raw message