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

void PoDoFo::PdfParser::ReadObjects (  ) [protected]

Reads all objects from the pdf into memory from the offsets listed in m_vecOffsets.

If required an encryption object is setup first.

The actual reading happens in ReadObjectsInternal() either if no encryption is required or a correct encryption object was initialized from SetPassword.

Definition at line 820 of file PdfParser.cpp.

References PoDoFo::PdfError::AddToCallstack(), PoDoFo::PdfEncrypt::Authenticate(), PoDoFo::PdfEncrypt::CreatePdfEncrypt(), PoDoFo::PdfError::DebugMessage(), PoDoFo::ePdfError_InvalidEncryptionDict, PoDoFo::ePdfError_InvalidPassword, PoDoFo::PdfReference::GenerationNumber(), PoDoFo::PdfVariant::GetDictionary(), GetDocumentId(), PoDoFo::PdfDictionary::GetKey(), PoDoFo::PdfVariant::GetReference(), PoDoFo::PdfVariant::IsDictionary(), PoDoFo::PdfVariant::IsNull(), PoDoFo::PdfVariant::IsReference(), PoDoFo::PdfReference::ObjectNumber(), PoDoFo::PdfParserObject::ParseFile(), PODOFO_RAISE_ERROR_INFO, ReadObjectsInternal(), PoDoFo::PdfObject::Reference(), PoDoFo::PdfVecObjects::Reserve(), and PoDoFo::PdfParserObject::SetLoadOnDemand().

Referenced by ParseFile().

{
    int              i          = 0;
    PdfParserObject* pObject    = NULL;

    m_vecObjects->Reserve( m_nNumObjects );

    // Check for encryption and make sure that the encryption object
    // is loaded before all other objects
    PdfObject* pEncrypt = m_pTrailer->GetDictionary().GetKey( PdfName("Encrypt") );
    if( pEncrypt && !pEncrypt->IsNull() )
    {
#ifdef PODOFO_VERBOSE_DEBUG
        PdfError::DebugMessage("The PDF file is encrypted.\n" );
#endif // PODOFO_VERBOSE_DEBUG

        if( pEncrypt->IsReference() ) 
        {
            i = pEncrypt->GetReference().ObjectNumber();
            pObject = new PdfParserObject( m_vecObjects, m_device, m_buffer, m_offsets[i].lOffset );
            pObject->SetLoadOnDemand( false ); // Never load this on demand, as we will use it immediately
            try {
                pObject->ParseFile( NULL ); // The encryption dictionary is not encrypted :)
                // Never add the encryption dictionary to m_vecObjects
                // we create a new one, if we need it for writing
                // m_vecObjects->push_back( pObject );
                m_offsets[i].bParsed = false;
                m_pEncrypt = PdfEncrypt::CreatePdfEncrypt( pObject );
                delete pObject;
            } catch( PdfError & e ) {
                std::ostringstream oss;
                if( pObject )
                {
                    oss << "Error while loading object " << pObject->Reference().ObjectNumber() << " " 
                        << pObject->Reference().GenerationNumber() << std::endl;
                    delete pObject;
                }

                e.AddToCallstack( __FILE__, __LINE__, oss.str().c_str() );
                throw e;

            }
        }
        else if( pEncrypt->IsDictionary() ) 
        {
            m_pEncrypt = PdfEncrypt::CreatePdfEncrypt( pEncrypt );
        }
        else
        {
            PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidEncryptionDict, 
                                     "The encryption entry in the trailer is neither an object nor a reference." ); 
        }

        // Generate encryption keys
        // Set user password, try first with an empty password
        bool bAuthenticate = m_pEncrypt->Authenticate( "", this->GetDocumentId() );
#ifdef PODOFO_VERBOSE_DEBUG
        PdfError::DebugMessage("Authentication with empty password: %i.\n", bAuthenticate );
#endif // PODOFO_VERBOSE_DEBUG
        if( !bAuthenticate ) 
        {
            // authentication failed so we need a password from the user.
            // The user can set the password using PdfParser::SetPassword
            PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidPassword, "A password is required to read this PDF file.");
        }

    }

    ReadObjectsInternal();
}

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