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

const PdfMemDocument & PoDoFo::PdfMemDocument::InsertPages ( const PdfMemDocument rDoc,
int  inFirstPage,
int  inNumPages 
)

Copies one or more pages from another PdfMemDocument to this document

Parameters:
rDocthe document to append
inFirstPagethe first page number to copy (0-based)
inNumPagesthe number of pages to copy
Returns:
this document

Definition at line 309 of file PdfMemDocument.cpp.

References PoDoFo::PdfDocument::Append(), DeletePages(), and PoDoFo::PdfDocument::GetPageCount().

Referenced by PoDoFo::Impose::PdfTranslator::addToSource(), and PoDoFo::Impose::PdfTranslator::setSource().

{
    /*
      This function works a bit different than one might expect. 
      Rather than copying one page at a time - we copy the ENTIRE document
      and then delete the pages we aren't interested in.
      
      We do this because 
      1) SIGNIFICANTLY simplifies the process
      2) Guarantees that shared objects aren't copied multiple times
      3) offers MUCH faster performance for the common cases
      
      HOWEVER: because PoDoFo doesn't currently do any sort of "object garbage collection" during
      a Write() - we will end up with larger documents, since the data from unused pages
      will also be in there.
    */

    // calculate preliminary "left" and "right" page ranges to delete
    // then offset them based on where the pages were inserted
    // NOTE: some of this will change if/when we support insertion at locations
    //       OTHER than the end of the document!
    int leftStartPage = 0 ;
    int leftCount = inFirstPage ;
    int rightStartPage = inFirstPage + inNumPages ;
    int rightCount = rDoc.GetPageCount() - rightStartPage ;
    int pageOffset = this->GetPageCount();      

    leftStartPage += pageOffset ;
    rightStartPage += pageOffset ;
    
    // append in the whole document
    this->Append( rDoc );

    // delete
    if( rightCount > 0 )
        this->DeletePages( rightStartPage, rightCount ) ;
    if( leftCount > 0 )
        this->DeletePages( leftStartPage, leftCount ) ;
    
    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