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

void PoDoFo::PdfPagesTree::InsertPage ( int  nAfterPageNumber,
PdfObject pPage 
)

Inserts an existing page object into the internal page tree. after the specified page number

Parameters:
nAfterPageNumberan integer specifying after what page

  • may be one of the special values from EPdfPageInsertionPoint. Pages are 0 based.
pPagemusst be a PdfObject with type /Page

Definition at line 109 of file PdfPagesTree.cpp.

References PoDoFo::eLogSeverity_Critical, PoDoFo::eLogSeverity_Information, PoDoFo::PdfElement::GetObject(), GetPosInKids(), GetRoot(), GetTotalNumberOfPages(), PoDoFo::PdfPagesTreeCache::InsertPage(), InsertPageIntoNode(), and PoDoFo::PdfError::LogMessage().

Referenced by PoDoFo::PdfDocument::Append(), CreatePage(), and InsertPage().

{
    bool bInsertBefore = false;

    if( ePdfPageInsertionPoint_InsertBeforeFirstPage == nAfterPageNumber )
    {
        bInsertBefore = true;
        nAfterPageNumber = 0;
    }
    else if( nAfterPageNumber < 0 ) 
    {
        // Only ePdfPageInsertionPoint_InsertBeforeFirstPage is valid here
        PdfError::LogMessage( eLogSeverity_Information,
                              "Invalid argument to PdfPagesTree::InsertPage: %i (Only ePdfPageInsertionPoint_InsertBeforeFirstPage is valid here).",
                              nAfterPageNumber );
        return;
    }

    //printf("Fetching page node: %i\n", nAfterPageNumber);
    PdfObjectList lstParents;
    //printf("Searching page=%i\n", nAfterPageNumber );
    PdfObject* pPageBefore = this->GetPageNode( nAfterPageNumber, this->GetRoot(), lstParents );
    
    //printf("pPageBefore=%p lstParents=%i\n", pPageBefore,lstParents.size() );
    if( !pPageBefore || lstParents.size() == 0 ) 
    {
        if( this->GetTotalNumberOfPages() != 0 ) 
        {
            PdfError::LogMessage( eLogSeverity_Critical,
                                  "Cannot find page %i or page %i has no parents. Cannot insert new page.",
                                  nAfterPageNumber, nAfterPageNumber );
            return;
        }
        else
        {
            // We insert the first page into an empty pages tree
            PdfObjectList lstPagesTree;
            lstPagesTree.push_back( this->GetObject() );
            // Use -1 as index to insert before the empty kids array
            InsertPageIntoNode( this->GetObject(), lstPagesTree, -1, pPage );
        }
    }
    else
    {
        PdfObject* pParent = lstParents.back();
        //printf("bInsertBefore=%i\n", bInsertBefore );
        int nKidsIndex = bInsertBefore  ? -1 : this->GetPosInKids( pPageBefore, pParent );
        //printf("Inserting into node: %p at pos %i\n", pParent, nKidsIndex );

        InsertPageIntoNode( pParent, lstParents, nKidsIndex, pPage );
    }

    m_cache.InsertPage( nAfterPageNumber );
}

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