Logo Search packages:      
Sourcecode: libpodofo version File versions  Download package

const PdfDocument & PoDoFo::PdfDocument::Append ( const PdfMemDocument rDoc,
bool  bAppendAll = true 
) [inherited]

Appends another PdfDocument to this document

Parameters:
rDocthe document to append
bAppendAllspecifies whether pages and outlines are appended too
Returns:
this document

Definition at line 232 of file PdfDocument.cpp.

References PoDoFo::PdfVecObjects::AddFreeObject(), PoDoFo::PdfDictionary::AddKey(), PoDoFo::PdfVecObjects::begin(), PoDoFo::PdfVecObjects::end(), PoDoFo::PdfOutlineItem::First(), PoDoFo::PdfDocument::FixObjectReferences(), PoDoFo::PdfVariant::GetDictionary(), PoDoFo::PdfVecObjects::GetFreeObjects(), PoDoFo::PdfPage::GetMediaBox(), PoDoFo::PdfElement::GetObject(), PoDoFo::PdfVecObjects::GetObject(), PoDoFo::PdfMemDocument::GetObjects(), PoDoFo::PdfDocument::GetOutlines(), PoDoFo::PdfDocument::GetPage(), PoDoFo::PdfDocument::GetPageCount(), PoDoFo::PdfVecObjects::GetSize(), PoDoFo::PdfObject::GetStream(), PoDoFo::PdfDictionary::HasKey(), PoDoFo::PdfOutlineItem::InsertChild(), PoDoFo::PdfPagesTree::InsertPage(), PoDoFo::PdfVariant::IsDictionary(), PoDoFo::PdfOutlineItem::Next(), PoDoFo::PdfReference::ObjectNumber(), PoDoFo::PdfVecObjects::push_back(), PoDoFo::PdfObject::Reference(), PoDoFo::PdfDictionary::RemoveKey(), and PoDoFo::PdfRect::ToVariant().

Referenced by PoDoFo::PdfDocument::FillXObjectFromDocumentPage(), and PoDoFo::PdfMemDocument::InsertPages().

{
    unsigned int difference = static_cast<unsigned int>(m_vecObjects.GetSize() + m_vecObjects.GetFreeObjects().size());


    // Ulrich Arnold 30.7.2009: Because GetNextObject uses m_nObjectCount instead 
    //                          of m_vecObjects.GetSize()+m_vecObjects.GetFreeObjects().size()+1
    //                          make sure the free objects are already present before appending to
      //                          prevent overlapping obj-numbers

    // create all free objects again, to have a clean free object list
    TCIPdfReferenceList itFree = rDoc.GetObjects().GetFreeObjects().begin();
    while( itFree != rDoc.GetObjects().GetFreeObjects().end() )
    {
        m_vecObjects.AddFreeObject( PdfReference( (*itFree).ObjectNumber() + difference, 0 ) );

        ++itFree;
    }

      // append all objects first and fix their references
    TCIVecObjects it           = rDoc.GetObjects().begin();
    while( it != rDoc.GetObjects().end() )
    {
        PdfObject* pObj = new PdfObject( PdfReference( 
                                             static_cast<unsigned int>((*it)->Reference().ObjectNumber() + difference), 0 ), *(*it) );
        m_vecObjects.push_back( pObj );

        if( (*it)->IsDictionary() && (*it)->HasStream() )
            *(pObj->GetStream()) = *((*it)->GetStream());

        FixObjectReferences( pObj, difference );

        ++it;
    }


    // Ulrich Arnold 30.7.2009: Moved to front
#if 0
      // create all free objects again, to have a clean free object list
    TCIPdfReferenceList itFree = rDoc.GetObjects().GetFreeObjects().begin();
    while( itFree != rDoc.GetObjects().GetFreeObjects().end() )
    {
        m_vecObjects.AddFreeObject( PdfReference( (*itFree).ObjectNumber() + difference, 0 ) );

        ++itFree;
    }
#endif

    if( bAppendAll )
    {
        // append all pages now to our page tree
        for(int i=0;i<rDoc.GetPageCount();i++ )
        {
            PdfPage*      pPage = rDoc.GetPage( i );
            PdfObject*    pObj  = m_vecObjects.GetObject( PdfReference( pPage->GetObject()->Reference().ObjectNumber() + difference, 0 ) );
            if( pObj->IsDictionary() && pObj->GetDictionary().HasKey( "Parent" ) )
                pObj->GetDictionary().RemoveKey( "Parent" );

                  // Ulrich Arnold 26.7.2010: make sure inherited mediabox from pages is transferred to page
                  PdfRect mediaboxRect = pPage->GetMediaBox();
                  PdfVariant mediaboxVariant;
                mediaboxRect.ToVariant( mediaboxVariant );
                  pObj->GetDictionary().AddKey( "MediaBox", mediaboxVariant );
            
            //printf("Inserting at: %i\n", this->GetPageCount()-1 );
            m_pPagesTree->InsertPage( this->GetPageCount()-1, pObj );
        }
        
        // append all outlines
        PdfOutlineItem* pRoot       = this->GetOutlines();
        PdfOutlines*    pAppendRoot = const_cast<PdfMemDocument&>(rDoc).GetOutlines( PoDoFo::ePdfDontCreateObject );
        if( pAppendRoot && pAppendRoot->First() ) 
        {
            // only append outlines if appended document has outlines
            while( pRoot && pRoot->Next() ) 
                pRoot = pRoot->Next();
            
            PdfReference ref( pAppendRoot->First()->GetObject()->Reference().ObjectNumber() + difference, 0 );
            pRoot->InsertChild( new PdfOutlines( m_vecObjects.GetObject( ref ) ) );
        }
    }
    
    // TODO: merge name trees
    // ToDictionary -> then iteratate over all keys and add them to the new one
    return *this;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index