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

void PoDoFo::PdfWriter::CreateFileIdentifier ( PdfString identifier,
const PdfObject pTrailer 
) const [protected]

Creates a file identifier which is required in several PDF workflows. All values from the files document information dictionary are used to create a unique MD5 key which is added to the trailer dictionary.

identifierwrite the identifier to this string
pTrailertrailer object

Definition at line 558 of file PdfWriter.cpp.

References PoDoFo::PdfDictionary::AddKey(), PoDoFo::ePdfError_InvalidHandle, PoDoFo::ePdfError_OutOfMemory, PoDoFo::PdfReference::GenerationNumber(), PoDoFo::PdfVariant::GetDictionary(), PoDoFo::PdfDictionary::GetKey(), PoDoFo::PdfOutputDevice::GetLength(), PoDoFo::PdfEncrypt::GetMD5String(), PoDoFo::PdfVecObjects::GetObject(), PoDoFo::PdfVariant::GetReference(), PoDoFo::PdfDictionary::HasKey(), m_vecObjects, PoDoFo::PdfReference::ObjectNumber(), PODOFO_RAISE_ERROR, PODOFO_RAISE_ERROR_INFO, PoDoFo::PdfDate::ToString(), and PoDoFo::PdfObject::WriteObject().

Referenced by PoDoFo::PdfImmediateWriter::PdfImmediateWriter(), and Write().

    PdfOutputDevice length;
    PdfObject*      pInfo;
    char*           pBuffer;
    // create a dictionary with some unique information.
    // This dictionary is based on the PDF files information
    // dictionary if it exists.
    if( pTrailer->GetDictionary().HasKey("Info") )
        const PdfReference & rRef = pTrailer->GetDictionary().GetKey( "Info" )->GetReference();
        const PdfObject* pObj = m_vecObjects->GetObject( rRef );

        if( pObj ) 
            pInfo = new PdfObject( *pObj );
            std::ostringstream oss;
            oss << "Error while retrieving info dictionary: " 
                << rRef.ObjectNumber() << " " 
                << rRef.GenerationNumber() << " R" << std::endl;
            PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidHandle, oss.str().c_str() );
        PdfDate   date;
        PdfString dateString;

        date.ToString( dateString );

        pInfo = new PdfObject();
        pInfo->GetDictionary().AddKey( "CreationDate", dateString );
        pInfo->GetDictionary().AddKey( "Creator", PdfString("PoDoFo") );
        pInfo->GetDictionary().AddKey( "Producer", PdfString("PoDoFo") );
    pInfo->GetDictionary().AddKey( "Location", PdfString("SOMEFILENAME") );

    pInfo->WriteObject( &length, m_eWriteMode, NULL );

    pBuffer = static_cast<char*>(malloc( sizeof(char) * length.GetLength() ));
    if( !pBuffer )
        delete pInfo;
        PODOFO_RAISE_ERROR( ePdfError_OutOfMemory );

    PdfOutputDevice device( pBuffer, length.GetLength() );
    pInfo->WriteObject( &device, m_eWriteMode, NULL );

    // calculate the MD5 Sum
    identifier = PdfEncrypt::GetMD5String( reinterpret_cast<unsigned char*>(pBuffer),
                                           static_cast<unsigned int>(length.GetLength()) );
    free( pBuffer );

    delete pInfo;

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