• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PDFBox - PDFMergerUtility Question

 
Sujoy Choudhury
Ranch Hand
Posts: 136
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
>
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 136
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 136
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 136
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your input Tim!
I shall try that and shall let you know tomorrow.
 
Sujoy Choudhury
Ranch Hand
Posts: 136
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic