else
{
destThreads.addAll( srcThreads );
}
COSName names = COSName.getPDFName( "Names" );
PDDocumentNameDictionary destNames = destCatalog.getNames();
PDDocumentNameDictionary srcNames = srcCatalog.getNames();
if( srcNames != null )
{
if( destNames == null )
{
destCatalog.getCOSDictionary().setItem( names, cloneForNewDocument( destination, srcNames ) );
}
else
{
cloneMerge(destination, srcNames, destNames);
}
}
PDDocumentOutline destOutline = destCatalog.getDocumentOutline();
PDDocumentOutline srcOutline = srcCatalog.getDocumentOutline();
if( srcOutline != null )
{
if( destOutline == null )
{
PDDocumentOutline cloned =
new PDDocumentOutline( (COSDictionary)cloneForNewDocument( destination, srcOutline ) );
destCatalog.setDocumentOutline( cloned );
}
else
{
PDOutlineItem first = srcOutline.getFirstChild();
PDOutlineItem clonedFirst = new PDOutlineItem( (COSDictionary)cloneForNewDocument(
destination, first ));
destOutline.appendChild( clonedFirst );
}
}
String destPageMode = destCatalog.getPageMode();
String srcPageMode = srcCatalog.getPageMode();
if( destPageMode == null )
{
destCatalog.setPageMode( srcPageMode );
}
COSName pageLabels = COSName.getPDFName( "PageLabels" );
COSDictionary destLabels = (COSDictionary)destCatalog.getCOSDictionary().getDictionaryObject( pageLabels );
COSDictionary srcLabels = (COSDictionary)srcCatalog.getCOSDictionary().getDictionaryObject( pageLabels );
if( srcLabels != null )
{
int destPageCount = destination.getNumberOfPages();
COSArray destNums = null;
if( destLabels == null )
{
destLabels = new COSDictionary();
destNums = new COSArray();
destLabels.setItem( COSName.getPDFName( "Nums" ), destNums );
destCatalog.getCOSDictionary().setItem( pageLabels, destLabels );
}
else
{
destNums = (COSArray)destLabels.getDictionaryObject( COSName.getPDFName( "Nums" ) );
}
COSArray srcNums = (COSArray)srcLabels.getDictionaryObject( COSName.getPDFName( "Nums" ) );
if (srcNums != null)
{
for( int i=0; i<srcNums.size(); i+=2 )
{
COSNumber labelIndex = (COSNumber)srcNums.getObject( i );
long labelIndexValue = labelIndex.intValue();
destNums.add( new COSInteger( labelIndexValue + destPageCount ) );
destNums.add( cloneForNewDocument( destination, srcNums.getObject( i+1 ) ) );
}
}
}
COSName metadata = COSName.getPDFName( "Metadata" );
COSStream destMetadata = (COSStream)destCatalog.getCOSDictionary().getDictionaryObject( metadata );
COSStream srcMetadata = (COSStream)srcCatalog.getCOSDictionary().getDictionaryObject( metadata );
if( destMetadata == null && srcMetadata != null )
{
PDStream newStream = new PDStream( destination, srcMetadata.getUnfilteredStream(), false );