I have a set of pdf files with links to other pdf files. I would like to
concatenate all of them into one single pdf file. I am able to do this, and
as expected the links are still pointing to the external PDF files. I need
to be able to redirect the links to point to the current page within my
single PDF document that contains the newly merged document. 

If you could please let me know how to perform this, either with page number
or named destinations or any other approach, I would really appreciate it,
thank you.

Best Regards,
Amar

Please find attached my code snippet below. 

<code>
public static boolean concatenate(String args[]) { //Contains the list of
PDF files, followed by the 
                                                                    //Final
OUTPUT file.

        if (args.length < 2) {
            System.err.println("arguments: file1 [file2 ...] destfile");
            return false;
        }
        else {
             try {
                int pageOffset = 0;
                ArrayList master = new ArrayList();
                int f = 0;
                String outFile = args[args.length-1];
                Document document = null;
                PdfCopy  writer = null;

                while (f < args.length-1) {
                    // we create a reader for a certain document
                    PdfReader reader = new PdfReader(args[f]);
                    
                    // we retrieve the total number of pages
                    int n = reader.getNumberOfPages();
                    List bookmarks = SimpleBookmark.getBookmark(reader); 
                    
                    if (bookmarks != null) {
                        if (pageOffset != 0)
                            SimpleBookmark.shiftPageNumbers(bookmarks,
pageOffset, null);
                        master.addAll(bookmarks);
                    }
                    pageOffset += n;
                    
                    if (f == 0) {
                        // step 1: creation of a document-object
                        document = new
Document(reader.getPageSizeWithRotation(1));
                        // step 2: we create a writer that listens to the
document
                        writer = new PdfCopy(document, new
FileOutputStream(outFile));
                        // step 3: we open the document
                        document.open();
                    }
                    // step 4: we add content
                    PdfImportedPage page;
                    for (int i = 0; i < n; ) {
                        ++i;
                        page = writer.getImportedPage(reader, i);
                        writer.addPage(page);
                    }
                    PRAcroForm form = reader.getAcroForm();
                    if (form != null)
                        writer.copyAcroForm(reader);
                    f++;
                }
                if (!master.isEmpty())
                    writer.setOutlines(master);
                // step 5: we close the document
                document.close();
            }
            catch(Exception e) {
                e.printStackTrace();
            }
            
            return true;
        }
    
                
        }
</code>


-- 
View this message in context: 
http://www.nabble.com/Concatenating-PDF-Files-tp23945745p23945745.html
Sent from the iText - General mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to