示例#1
0
void PagesTreeTest::CreateTestTreePoDoFo( PoDoFo::PdfMemDocument & rDoc )
{
    for(int i=0; i<PODOFO_TEST_NUM_PAGES; i++) 
    {
        PdfPage* pPage = rDoc.CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ) );
        pPage->GetObject()->GetDictionary().AddKey( PODOFO_TEST_PAGE_KEY, static_cast<long long>(i) );

        CPPUNIT_ASSERT_EQUAL( rDoc.GetPageCount(), i + 1 );
    }
}
void ImageConverter::Work() 
{
    PoDoFo::PdfMemDocument document;

    std::vector<std::string>::const_iterator it = m_vecImages.begin();
    PoDoFo::PdfRect size = PoDoFo::PdfPage::CreateStandardPageSize( PoDoFo::ePdfPageSize_A4, false );
    PoDoFo::PdfPainter painter;
    double dScaleX = 1.0;
    double dScaleY = 1.0;
    double dScale  = 1.0;

    while( it != m_vecImages.end() ) 
    {
        PoDoFo::PdfPage* pPage;
        PoDoFo::PdfImage image( &document );
        image.LoadFromFile( (*it).c_str() );

        if( m_bUseImageSize ) 
        {
            size = PoDoFo::PdfRect( 0.0, 0.0, image.GetWidth(), image.GetHeight() );
        }

        pPage = document.CreatePage( size );
        dScaleX = size.GetWidth() / image.GetWidth();
        dScaleY = size.GetHeight() / image.GetHeight();
        dScale  = PoDoFo::PDF_MIN( dScaleX, dScaleY );

        painter.SetPage( pPage );
        if( dScale < 1.0 ) 
        {
            painter.DrawImage( 0.0, 0.0, &image, dScale, dScale );
        }
        else
        {
            // Center Image
            double dX = (size.GetWidth() - image.GetWidth())/2.0;
            double dY = (size.GetHeight() - image.GetHeight())/2.0;
            painter.DrawImage( dX, dY, &image );
        }

        painter.FinishPage();

        ++it;
    }

    document.Write( m_sOutputFilename.c_str() );
}