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

bool PoDoFo::PdfParser::QuickEncryptedCheck ( const char *  pszFilename )

Quick method to detect secured PDF files, i.e. a PDF with an /Encrypt key in the trailer directory.

Returns:
true if document is secured, false otherwise

Definition at line 767 of file PdfParser.cpp.

References PoDoFo::PdfError::AddToCallstack(), Clear(), PoDoFo::PdfRefCountedInputDevice::Device(), PoDoFo::ePdfError_InvalidHandle, PoDoFo::PdfVariant::GetDictionary(), PoDoFo::PdfDictionary::GetKey(), Init(), PoDoFo::PdfVariant::IsNull(), IsPdfFile(), PODOFO_RAISE_ERROR, ReadDocumentStructure(), and PoDoFo::PdfVecObjects::Reserve().

{
    bool bEncryptStatus   = false;
    bool bOldLoadOnDemand = m_bLoadOnDemand;
    Init();
    Clear();

   
    m_bLoadOnDemand   = true; // maybe will be quicker if true?

    if( !pszFilename || !pszFilename[0] )
    {
        PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
    }

    m_device = PdfRefCountedInputDevice( pszFilename, "rb" );
    if( !m_device.Device() )
    {
        //PODOFO_RAISE_ERROR_INFO( ePdfError_FileNotFound, pszFilename );
        // If we can not open PDF file
        // then file does not exist
        return false;
    }

    if( !IsPdfFile() )
    {
        //PODOFO_RAISE_ERROR( ePdfError_NoPdfFile );
        return false;
    }

    ReadDocumentStructure();
    try {

        m_vecObjects->Reserve( m_nNumObjects );

        // Check for encryption and make sure that the encryption object
        // is loaded before all other objects
        const PdfObject * encObj = m_pTrailer->GetDictionary().GetKey( PdfName("Encrypt") );
        if( encObj && ! encObj->IsNull() ) 
        {
            bEncryptStatus = true;
        }
    } catch( PdfError & e ) {
        m_bLoadOnDemand = bOldLoadOnDemand; // Restore load on demand behaviour
        e.AddToCallstack( __FILE__, __LINE__, "Unable to load objects from file." );
        throw e;
    }

    m_bLoadOnDemand = bOldLoadOnDemand; // Restore load on demand behaviour

    return bEncryptStatus;
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index