pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Maruan Sahyoun <sahy...@fileaffairs.de>
Subject Re: Merge PDFs, add second pdf as child in outline
Date Tue, 09 Apr 2013 09:59:39 GMT
Hi Marvin,

first I have to say that from your description I didn't fully get what you would like to achieve
and which result you get. 

The PDFMergerUtility already appends the outline of your children as a child to the outline
of your parent. That's why you get it twice.

From the source:


	PDDocumentOutline destOutline = destCatalog.getDocumentOutline();
        PDDocumentOutline srcOutline = srcCatalog.getDocumentOutline();
        if( srcOutline != null )
        {
            if( destOutline == null )
            {
                PDDocumentOutline cloned =
                    new PDDocumentOutline( (COSDictionary)cloner.cloneForNewDocument( srcOutline
) );
                destCatalog.setDocumentOutline( cloned );
            }
            else
            {
                PDOutlineItem first = srcOutline.getFirstChild();
                if(first != null)
                {
                    PDOutlineItem clonedFirst = new PDOutlineItem(
                            (COSDictionary)cloner.cloneForNewDocument( first ));
                    destOutline.appendChild( clonedFirst );
                }
            }
        }

BR
Maruan Sahyoun

Am 09.04.2013 um 11:34 schrieb Marvin B. Lillehaug <marvin.lillehaug@gmail.com>:

> Hi!
> I am trying to create a single pdf from a hierarchy of previously generated
> pdfs, and having some problems with the outline.
> I have two pdfs, one for the parent and one for its children, and want to
> add the existing outline of the children as the child of the existing
> outline for the parent.
> 
> My current code is
> // load pdfs here
> PDFMergerUtility pdfMergerUtility = new PDFMergerUtility();
> pdfMergerUtility.appendDocument(pdf, attachment);
> 
> PDDocumentOutline documentOutline =
> pdf.getDocumentCatalog().getDocumentOutline();
> PDOutlineItem originalRoot = documentOutline.getFirstChild();
> PDOutlineItem appendedRoot = originalRoot.getNextSibling();
> originalRoot.appendChild(appendedRoot);
> 
> //save pdf here
> 
> The resulting pdf looks like it is supposed to and the outline is working,
> i.e. clicking on a node jumps to the correct page. But the children are
> duplicated, they show as both children and siblings of the outline from the
> parent pdf.
> 
> In all my attempts that resulted in the outline looking like it should,
> clicking on the outline nodes had no effect.
> 
> Any pointers?
> 
> -- 
> mvh,
> Marvin B. Lillehaug


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message