aspose file tools*
The moose likes Other Open Source Projects and the fly likes PDFBox - PDFMergerUtility Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "PDFBox - PDFMergerUtility Question" Watch "PDFBox - PDFMergerUtility Question" New topic
Author

PDFBox - PDFMergerUtility Question

Sujoy Choudhury
Ranch Hand

Joined: Sep 17, 2008
Posts: 136

Hi,

I recently downloaded Apache PDFBox application to write an application to merge PDF files.
I used the following code.


But the merged file doesn't add sources.
I am trying to merge three different PDF files.
I can see only 1 file copied 3 times on the new document.

Did you anyone face this?
>


Thanks and Regards,
~Sujoy
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

I tried your code without specifying the last file in the array as the destination file and it worked correctly for me. I got a merged document.

When I specified the last file in the array to be the destination file, however, I found that the contents of that file are erased before the merge happens. So, if you want all three merged, you will specify a new file as the destination file (or copy your third file to a temporary file before the merge).

I could not reproduce getting one file containing three copies of the same pdf.
Sujoy Choudhury
Ranch Hand

Joined: Sep 17, 2008
Posts: 136

Hi Tim,
I could not upload my original code earlier due to some reason.
I uploaded some code from web on which I worked.

This is my code:
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

Sujoy,

Your code worked perfectly for me. I combined three sample pdfs into one merged one. When you say "nothing worked", you mean you are still seeing one PDF repeated three times in the final document?

By the way, I want to thank you for introducing me to this easy to use PDF library.
Sujoy Choudhury
Ranch Hand

Joined: Sep 17, 2008
Posts: 136

That's great Tim...atleast this is working for someone
Well, when I run this code, the last file, whichever it is, is getting appended number of times I run the loop( or add manually, my alternate code).
This is very confusing for me that why this doesn't work for me.
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

Sujoy Choudhury wrote:That's great Tim...atleast this is working for someone
Well, when I run this code, the last file, whichever it is, is getting appended number of times I run the loop( or add manually, my alternate code).
This is very confusing for me that why this doesn't work for me.

Which version of PDFBox are you using? I just downloaded the latest. Maybe you have an old version.

Also, this is not related to your problem, but when you iterate through fileNames, you could do it like this:

Sujoy Choudhury
Ranch Hand

Joined: Sep 17, 2008
Posts: 136

Thanks for your input Tim!
I shall try that and shall let you know tomorrow.
Sujoy Choudhury
Ranch Hand

Joined: Sep 17, 2008
Posts: 136

I know this won't solve my problem...this is just a better way to do it...
I do forget that style sometimes...

well I guess I am doing something silly may be...why this is not working...no idea so far...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: PDFBox - PDFMergerUtility Question