Thanks for the reply. I am not using PdfStamper because I am loosing the
hyperlink hidden in the pages that I am adding on top of the original Pdf.
Here is the code merging both Pdfs.

public void concatenate(String firstFile, String secondFile, String output)
{

                try {
                        // Step 1
                        Document document = new Document();
                        PdfReader reader;
                        PdfReader.unethicalreading = true;

                        // Step 2.
                        PdfCopy copy = new PdfCopy(document, new 
FileOutputStream(output));
                        
                        // Step 2.5 Copying Pdf Properties.
                        reader = new PdfReader(secondFile);
                        HashMap<String, String> map = reader.getInfo();
                        
                        String title = map.get("Title");
                        String author = map.get("Author");
                        String subject = map.get("Subject");
                        String keywords = map.get("Keywords");
                        String creator = map.get("Creator");
                        
                        if (title != null)
                                document.addTitle(title);
                        if (author != null)
                                document.addAuthor(author);
                        if (subject != null)
                                document.addSubject(subject);
                        if (keywords != null) {
                                document.addKeywords(map.get("Keywords"));
                        }
                        
                        if (creator != null)
                                document.addCreator(creator+"/Forest Service");
                        else
                                document.addCreator("Forest Service");
                        
                        
                        // Step 3.
                        document.open();
                        
                        // Step 4.
                        int n;
                        int page_offset = 0;
                        List<String> listOfPdfs = new ArrayList<String>();
                        listOfPdfs.add(firstFile);                      // Pdf 
with Customed pages.
                        listOfPdfs.add(secondFile);                     // 
Original Pdf.
                        
                        // Create a list for the bookrmarks
                        ArrayList<HashMap&lt;String, Object>> bookmarks = new
ArrayList<HashMap&lt;String, Object>>();
                List<HashMap&lt;String, Object>> tmp;
                         
                        // loop over the documents you want to concatenate
                        for (int i=0; i<listOfPdfs.size(); i++) {
                                reader = new PdfReader(listOfPdfs.get(i));
                                reader.consolidateNamedDestinations();
                                
                                // merge the bookmarks
                                tmp = SimpleBookmark.getBookmark(reader);
                                if (tmp != null) {
                                        LogUtil.debug(log, &quot;Bookmarks from:
&quot;+listOfPdfs.get(i)+&quot; are of size: &quot;+tmp.size());
                                        SimpleBookmark.shiftPageNumbers(tmp, 
page_offset, null);
                                        bookmarks.addAll(tmp);
                                }
                                
                           
                                // add the pages
                    n = reader.getNumberOfPages();
                    page_offset += n;
                                
                    for (int page = 0; page &lt; n;) {
                                        
copy.addPage(copy.getImportedPage(reader, ++page));
                                }
                                
                                copy.freeReader(reader);
                                reader.close();
                        }

                        // Add the merged bookmarks
                if (bookmarks.size() > 0)
                        copy.setOutlines(bookmarks);
                
                        // Step 5.
                document.close();
                
                } catch (FileNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (DocumentException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
                
                
        }

Thanks.


downloaded_SRS_34955.pdf
<http://itext.2136553.n4.nabble.com/file/n4661012/downloaded_SRS_34955.pdf>  



--
View this message in context: 
http://itext.2136553.n4.nabble.com/PdfReader-getInfo-returns-null-for-Keywords-tp4661008p4661012.html
Sent from the iText mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785111&iu=/4140
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to