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

PdfRect PoDoFo::PdfDocument::FillXObjectFromDocumentPage ( PdfXObject pXObj,
const PdfMemDocument rDoc,
int  nPage,
bool  bUseTrimBox 
) [inherited]

Fill an existing empty XObject from a page of another document

Parameters:
pXObjpointer to the XOject
rDocthe document to embedd into XObject
nPagepage-number to embedd into XObject
bUseTrimBoxif true try to use trimbox for size of xobject
Returns:
the bounding box

Definition at line 319 of file PdfDocument.cpp.

References PoDoFo::PdfDictionary::AddKey(), PoDoFo::PdfStream::Append(), PoDoFo::PdfDocument::Append(), PoDoFo::PdfArray::begin(), PoDoFo::PdfStream::BeginAppend(), PoDoFo::PdfArray::end(), PoDoFo::PdfStream::EndAppend(), PoDoFo::ePdfError_InternalLogic, PoDoFo::ePdfFilter_FlateDecode, PoDoFo::PdfVariant::GetArray(), PoDoFo::PdfXObject::GetContentsForAppending(), PoDoFo::PdfPage::GetCropBox(), PoDoFo::PdfVariant::GetDictionary(), PoDoFo::PdfStream::GetFilteredCopy(), PoDoFo::PdfVecObjects::GetFreeObjects(), PoDoFo::PdfDictionary::GetKey(), PoDoFo::PdfPage::GetMediaBox(), PoDoFo::PdfElement::GetObject(), PoDoFo::PdfVecObjects::GetObject(), PoDoFo::PdfDocument::GetObjects(), PoDoFo::PdfDocument::GetPage(), PoDoFo::PdfVariant::GetReference(), PoDoFo::PdfVecObjects::GetSize(), PoDoFo::PdfObject::GetStream(), PoDoFo::PdfPage::GetTrimBox(), PoDoFo::PdfDictionary::HasKey(), PoDoFo::PdfObject::HasStream(), PoDoFo::PdfRect::Intersect(), PoDoFo::PdfVariant::IsArray(), PoDoFo::PdfVariant::IsDictionary(), PoDoFo::PdfVariant::IsReference(), PoDoFo::PdfReference::ObjectNumber(), PODOFO_RAISE_ERROR, and PoDoFo::PdfObject::Reference().

Referenced by PoDoFo::PdfXObject::PdfXObject().

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

      Append( rDoc, false );

    // TODO: remove unused objects: page, ...

    PdfPage*      pPage = rDoc.GetPage( nPage );
    PdfObject*    pObj  = m_vecObjects.GetObject( PdfReference( pPage->GetObject()->Reference().ObjectNumber() + difference, 0 ) );
    PdfRect         box  = pPage->GetMediaBox();

      // intersect with crop-box
      box.Intersect( pPage->GetCropBox() );

      // intersect with trim-box according to parameter
      if ( bUseTrimBox )
            box.Intersect( pPage->GetTrimBox() );

      // link resources from external doc to x-object
    if( pObj->IsDictionary() && pObj->GetDictionary().HasKey( "Resources" ) )
        pXObj->GetContentsForAppending()->GetDictionary().AddKey( "Resources" , pObj->GetDictionary().GetKey( "Resources" ) );

      // copy top-level content from external doc to x-object
    if( pObj->IsDictionary() && pObj->GetDictionary().HasKey( "Contents" ) )
    {
            // get direct pointer to contents
        PdfObject* pContents;
        if( pObj->GetDictionary().GetKey( "Contents" )->IsReference() )
            pContents = m_vecObjects.GetObject( pObj->GetDictionary().GetKey( "Contents" )->GetReference() );
        else
            pContents = pObj->GetDictionary().GetKey( "Contents" );

        if( pContents->IsArray() )
        {
                  // copy array as one stream to xobject
            PdfArray pArray = pContents->GetArray();

            PdfObject*  pObj = pXObj->GetContentsForAppending();
            PdfStream*  pObjStream = pObj->GetStream();

            TVecFilters vFilters;
                vFilters.push_back( ePdfFilter_FlateDecode );
            pObjStream->BeginAppend( vFilters );

                  TIVariantList it;
            for(it = pArray.begin(); it != pArray.end(); it++)
            {
                        if ( it->IsReference() )
                        {
                              // TODO: not very efficient !!
                              PdfObject*  pObj = GetObjects()->GetObject( it->GetReference() );

                        PdfStream*  pcontStream = pObj->GetStream();

                        char*       pcontStreamBuffer;
                          pdf_long    pcontStreamLength;
                        pcontStream->GetFilteredCopy( &pcontStreamBuffer, &pcontStreamLength );
                
                              pObjStream->Append( pcontStreamBuffer, pcontStreamLength );
                              free( pcontStreamBuffer );
                        }
                        else
                        {
                              string str;
                      it->ToString( str );
                      pObjStream->Append( str );
                      pObjStream->Append( " " );
                        }
                  }
            pObjStream->EndAppend();
        }
            else if( pContents->HasStream() )
        {
                  // copy stream to xobject
            PdfObject*  pObj = pXObj->GetContentsForAppending();
            PdfStream*  pObjStream = pObj->GetStream();
            PdfStream*  pcontStream = pContents->GetStream();
            char*       pcontStreamBuffer;
            pdf_long    pcontStreamLength;

            TVecFilters vFilters;
                vFilters.push_back( ePdfFilter_FlateDecode );
            pObjStream->BeginAppend( vFilters );
            pcontStream->GetFilteredCopy( &pcontStreamBuffer, &pcontStreamLength );
            pObjStream->Append( pcontStreamBuffer, pcontStreamLength );
            free( pcontStreamBuffer );
            pObjStream->EndAppend();
        }
            else
        {
              PODOFO_RAISE_ERROR( ePdfError_InternalLogic );
        }
    }

    return box;
}

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