In my current project the user has the option to add pdf file into the system. Recently we got the requirement to add a cover page to each pdf document that user downloads. We were already using the iText API for generating pdf so the task to do that was easy. After going through the documentation of iText I found a way to merge two pdf files.
try{ PdfReader pdfReader1 = new PdfReader("firstFile.pdf"); PdfReader pdfReader2 = new PdfReader("secondFile.pdf"); PdfCopyFields finalCopy = new PdfCopyFields(new FileOutputStream("finalCopy.pdf")); finalCopy.open(); [pdfReader1,pdfReader2].each {PdfReader pdfReader -> finalCopy.addDocument(pdfReader); } finalCopy.close(); } catch (DocumentException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
I hope it helped you
## Uday Pratap Singh ##
uday@intelligrape.com
http://www.IntelliGrape.com/
http://in.linkedin.com/in/meudaypratap
This entry was posted
on July 12th, 2010
at
7:22 pm and is filed under
Groovy, Java tools .
You can follow any responses to this entry through the
RSS 2.0 feed.
You can leave a response, or trackback from your own site.

Thanks! This really helped me out