You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Сергей Жиляев <us...@bigmir.net> on 2010/11/13 17:24:28 UTC

Error in Acrobat reader when composing a PDF from several PDF sources and adding text

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

Re: Error in Acrobat reader when composing a PDF from several PDF sources and adding text

Posted by Ad...@swmc.com.
You can also check out org.apache.pdfbox.util.PDFMergerUtility.java to 
make merging the PDFs easier.

---- 
Thanks,
Adam





From:
Сергей Жиляев <us...@bigmir.net>
To:
users@pdfbox.apache.org
Date:
11/13/2010 11:31
Subject:
Error in Acrobat reader when composing a PDF from several PDF sources and 
adding text



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 





- FHA 203b; 203k; HECM; VA; USDA; Conventional 
- Warehouse Lines; FHA-Authorized Originators 
- Lending and Servicing in over 45 States 
www.swmc.com   -  www.simplehecmcalculator.com   
Visit  www.swmc.com/resources   for helpful links on Training, Webinars, Lender Alerts and Submitting Conditions  

This email and any content within or attached hereto from Sun West Mortgage Company, Inc. is confidential and/or legally privileged. The information is intended only for the use of the individual or entity named on this email. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or taking any action in reliance on the contents of this email information is strictly prohibited, and that the documents should be returned to this office immediately by email. Receipt by anyone other than the intended recipient is not a waiver of any privilege. Please do not include your social security number, account number, or any other personal or financial information in the content of the email. Should you have any questions, please call (800) 453 7884.  

Re: Error in Acrobat reader when composing a PDF from several PDF sources and adding text

Posted by Andreas Lehmkühler <an...@lehmi.de>.
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