pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andreas Lehmkühler <andr...@lehmi.de>
Subject Re: Error in Acrobat reader when composing a PDF from several PDF sources and adding text
Date Sun, 14 Nov 2010 00:16:59 GMT
Hi,

Am 13.11.10 17:24, schrieb Сергей Жиляев:
> 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?
Try to close the first stream containing the form and open another one 
for the text.

BR
Andreas Lehmkühler

Mime
View raw message