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

void ImageExtractor::ExtractImage ( PoDoFo::PdfObject pObject,
bool  bJpeg 
) [private]

Extracts the image form the given PdfObject which has to be an XObject with Subtype "Image"

Parameters:
pObjecta handle to a PDF object
bJpegif true extract as a jpeg, otherwise create a ppm
Returns:
ErrOk on success

Definition at line 92 of file ImageExtractor.cpp.

References PoDoFo::ePdfError_InvalidHandle, FileExists(), PoDoFo::PdfMemStream::Get(), PoDoFo::PdfVariant::GetDictionary(), PoDoFo::PdfStream::GetFilteredCopy(), PoDoFo::PdfDictionary::GetKey(), PoDoFo::PdfMemStream::GetLength(), PoDoFo::PdfVariant::GetNumber(), PoDoFo::PdfObject::GetStream(), PODOFO_RAISE_ERROR, PoDoFo::PdfObject::Reference(), and PoDoFo::PdfReference::ToString().

Referenced by Init().

{
    FILE*       hFile        = NULL;
    const char* pszExtension = bJpeg ? "jpg" : "ppm"; 

    // Do not overwrite existing files:
    do {
        snprintf( m_szBuffer, MAX_PATH, "%s/pdfimage_%04i.%s", m_pszOutputDirectory, m_nCount++, pszExtension );
    } while( FileExists( m_szBuffer ) );

    hFile = fopen( m_szBuffer, "wb" );
    if( !hFile )
    {
        PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
    }

    printf("-> Writing image object %s to the file: %s\n", pObject->Reference().ToString().c_str(), m_szBuffer);

    if( bJpeg ) 
    {
        PdfMemStream* pStream = dynamic_cast<PdfMemStream*>(pObject->GetStream());
        fwrite( pStream->Get(), pStream->GetLength(), sizeof(char), hFile );
    }
    else
    {
        //long lBitsPerComponent = pObject->GetDictionary().GetKey( PdfName("BitsPerComponent" ) )->GetNumber();
        // TODO: Handle colorspaces

        // Create a ppm image
        const char* pszPpmHeader = "P6\n# Image extracted by PoDoFo\n%li %li\n%li\n";
        
        
        fprintf( hFile, pszPpmHeader, 
                 pObject->GetDictionary().GetKey( PdfName("Width" ) )->GetNumber(),
                 pObject->GetDictionary().GetKey( PdfName("Height" ) )->GetNumber(),
                 255 );
                 
        char*    pBuffer;
        pdf_long lLen;
        pObject->GetStream()->GetFilteredCopy( &pBuffer, &lLen );
        fwrite( pBuffer, lLen, sizeof(char), hFile );
        free( pBuffer );
    }

    fclose( hFile );

    ++m_nSuccess;
}

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