aspose file tools*
The moose likes Java in General and the fly likes Concatinating two pdf files in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Concatinating two pdf files in java" Watch "Concatinating two pdf files in java" New topic
Author

Concatinating two pdf files in java

Rizwan Mohammad
Ranch Hand

Joined: Sep 02, 2005
Posts: 445
How can I write java program to concatenate or merge two pdf files into one?
Can I do this using just java or need to use any third party software? If it is not possible, what is the free softwares available for this purpose?
Thanks in advance.


Rizwan
SCJA, SCJP, SCWCD, SCBCD, SCDJWS.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
There is a nice set of libraries called iText that you can use to read and write PDFs. There is also a nice package called pdftk that you can use to manipulate PDFs.
Rizwan Mohammad
Ranch Hand

Joined: Sep 02, 2005
Posts: 445
Thanks Keith. I will go through those site and I know about them earlier.
I dont want to read or write pdfs.. I have all the pdfs and just I have to merge them into one.. Is it possible without them or will there be some functions in those api's to do this job?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30780
    
157

Originally posted by Rizwan Mohammad:
Is it possible without them or will there be some functions in those api's to do this job?

No. A PDF contains hash like data about the whole file along with headers. You can't just concatenate them without reading them in first.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Originally posted by Rizwan Mohammad:
Thanks Keith. I will go through those site and I know about them earlier.
I dont want to read or write pdfs.. I have all the pdfs and just I have to merge them into one.. Is it possible without them or will there be some functions in those api's to do this job?


There are ways in both iText and pdftk. pdftk is probably easier to use for it since it is a command line program and you simply feed in the names of the .pdf files that you want to merge.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42294
    
  64
iText also comes with a ready-to-use example program that shows how to concatenate files.


Ping & DNS - my free Android networking tools app
Rizwan Mohammad
Ranch Hand

Joined: Sep 02, 2005
Posts: 445
Ulf & Keith, Thanks for your solutions. These helped me a lot.
Megan James
Greenhorn

Joined: Nov 21, 2008
Posts: 11
Could any one know how read the pdf with font style, family and size for each and every word or line?.

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42294
    
  64
Vijay,
your question has nothing to do with what was discussed above. Please don't post unrelated questions into existing topics; that's called "hijacking" and is frowned upon. Please start a new thread instead.
 
Consider Paul's rocket mass heater.
 
subject: Concatinating two pdf files in java