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

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

Reads the xref sections and the trailers of the file in the correct order in the memory and takes care for linearized pdf files.

Definition at line 233 of file PdfParser.cpp.

References PoDoFo::PdfError::AddToCallstack(), PoDoFo::PdfRefCountedInputDevice::Device(), PoDoFo::eLogSeverity_Warning, PoDoFo::ePdfError_NoTrailer, PoDoFo::PdfVariant::GetDictionary(), PoDoFo::PdfDictionary::HasKey(), PoDoFo::PdfVariant::IsDictionary(), PoDoFo::PdfError::LogMessage(), ReadTrailer(), ReadXRef(), ReadXRefContents(), PoDoFo::PdfInputDevice::Seek(), and PoDoFo::PdfInputDevice::Tell().

Referenced by ParseFile(), and QuickEncryptedCheck().

{
// Ulrich Arnold 8.9.2009, deactivated because of problems during reading xref's
//    HasLinearizationDict();
    
    // position at the end of the file to search the xref table.
    m_device.Device()->Seek( 0, std::ios_base::end );
    m_nFileSize = m_device.Device()->Tell();

    try {
        ReadXRef( &m_nXRefOffset );
    } catch( PdfError & e ) {
        e.AddToCallstack( __FILE__, __LINE__, "Unable to find startxref entry in file." );
        throw e;
    }

    try {
        ReadTrailer();
    } catch( PdfError & e ) {
        e.AddToCallstack( __FILE__, __LINE__, "Unable to find trailer in file." );
        throw e;
    }

    if( m_pLinearization )
    {
        try { 
            ReadXRefContents( m_nXRefOffset, true );
        } catch( PdfError & e ) {
            e.AddToCallstack( __FILE__, __LINE__, "Unable to skip xref dictionary." );
            throw e;
        }

        // another trailer directory is to follow right after this XRef section
        try {
            ReadNextTrailer();
        } catch( PdfError & e ) {
            if( e != ePdfError_NoTrailer )
                throw e;
        }
    }

    if( m_pTrailer->IsDictionary() && m_pTrailer->GetDictionary().HasKey( PdfName::KeySize ) )
    {
        m_nNumObjects = static_cast<long>(m_pTrailer->GetDictionary().GetKeyAsLong( PdfName::KeySize ));
    }
    else
    {
        PdfError::LogMessage( eLogSeverity_Warning, "PDF Standard Violation: No /Size key was specified in the trailer directory. Will attempt to recover." );
        // Treat the xref size as unknown, and expand the xref dynamically as we read it.
        m_nNumObjects = 0;
    }

    if (m_nNumObjects > 0)
        m_offsets.resize(m_nNumObjects);

    if( m_pLinearization )
    {
        try {
            ReadXRefContents( m_nXRefLinearizedOffset );
        } catch( PdfError & e ) {
            e.AddToCallstack( __FILE__, __LINE__, "Unable to read linearized XRef section." );
            throw e;
        }
    }

    try {
        ReadXRefContents( m_nXRefOffset );
    } catch( PdfError & e ) {
        e.AddToCallstack( __FILE__, __LINE__, "Unable to load xref entries." );
        throw e;
    }

}

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