[ 
https://issues.apache.org/jira/browse/PDFBOX-2638?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14296740#comment-14296740
 ] 

Maruan Sahyoun commented on PDFBOX-2638:
----------------------------------------

the main issue is that the source documents need to be kept open until the 
final document has been stored, which is not the case with your approach. You 
might want to review the PDFMerger.java source. Using that your code will become

{code}
PDFMergerUtility merger = new PDFMergerUtility();
for(int i = 0; i < docletNamesAsPdf.length; i++)
{
    String sourceFileName = docletNamesAsPdf[i];
    merger.addSource(sourceFileName);
}

merger.setDestinationFileName("MergedDoc.pdf");
merger.mergeDocumentsNonSeq(null);
{code}

using it this way PDFMergerUtility, which you are using anyway, will take care 
of closing the sources after the job has been done.

Please note that usage questions shall be posted to the users mailing list 
[https://pdfbox.apache.org/mailinglists.html].  

> PDF files content lost when multiples pdf files merged in to one file
> ---------------------------------------------------------------------
>
>                 Key: PDFBOX-2638
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-2638
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Rendering
>    Affects Versions: 1.8.2
>         Environment: Oracle Linux 5 (Intel 64-bit, Developer) 
>            Reporter: MANISHA SHARMA
>         Attachments: MergedDoc.pdf, Sample Pdf files.zip
>
>
> I am trying to merge six pdf files. In the merged document, I am seeing
> some boxes in place of text.
> Text got replaced by boxes and images got lost.
> The code used for merging is given below:
> public static void main (String args[])
>   {
>          String[] docletNamesAsPdf =
>          { "RP_OverviewPart1.pdf", "RP_OverviewPart2.pdf",
> "RP_OverviewPart3.pdf", "RP_OverviewPart4.pdf", "RP_OverviewPart5.pdf",
>            "RP_OverviewPart6.pdf" };
>          PDDocument dest = PDDocument.load(docletNamesAsPdf[0]);
>          PDDocument src = PDDocument.load(docletNamesAsPdf[1]);
>          dest = mergePdfs(dest, src);
>          for (int i = 2; i < docletNamesAsPdf.length; i++)
>           {
>              src = PDDocument.load(docletNamesAsPdf[i]);
>              dest = mergePdfs(dest, src);
>           }
>          try {
>              dest.save("MergedDoc.pdf");
>          } catch (COSVisitorException e) {
>              ;
>          }
>          src.close();
>          dest.close();
> }
> public PDDocument mergePdfs(PDDocument dest, PDDocument src) throws
> IOException {
>          new PDFMergerUtility().appendDocument(dest, src);
>          return dest;
>      }
> Please let me know what is wrong with the code and how can we resolve
> this issue. 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to