Пример #1
0
void PagesTreeTest::testCreateDelete()
{
    PdfMemDocument  writer;
    PdfPage*        pPage;
    PdfPainter      painter;
	PdfFont *		pFont;

    // create font
	pFont = writer.CreateFont( "Arial" );
    if( !pFont )
    {
        PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
    }
    pFont->SetFontSize( 16.0 );

	// write 1. page
    pPage = writer.CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ) );
    painter.SetPage( pPage );
    painter.SetFont( pFont );
    painter.DrawText( 200, 200, "Page 1"  );
    painter.FinishPage();
    CPPUNIT_ASSERT_EQUAL( writer.GetPageCount(), 1 );

	// write 2. page
    pPage = writer.CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ) );
    painter.SetPage( pPage );
    painter.DrawText( 200, 200, "Page 2"  );
    painter.FinishPage();
    CPPUNIT_ASSERT_EQUAL( writer.GetPageCount(), 2 );

	// try to delete second page, index is 0 based 
	writer.DeletePages( 1, 1 );
    CPPUNIT_ASSERT_EQUAL( writer.GetPageCount(), 1 );

	// write 3. page
    pPage = writer.CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ) );
    painter.SetPage( pPage );
    painter.DrawText( 200, 200, "Page 3"  );
    painter.FinishPage();
    CPPUNIT_ASSERT_EQUAL( writer.GetPageCount(), 2 );
}
Пример #2
0
void EncryptTest::CreatedEncrypedPdf( const char* pszFilename )
{
    PdfMemDocument  writer;
    PdfPage* pPage = writer.CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ) );
    PdfPainter painter;
    painter.SetPage( pPage );

    PdfFont* pFont = writer.CreateFont( "Arial", PdfEncodingFactory::GlobalWinAnsiEncodingInstance(), false );
    if( !pFont )
    {
        PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
    }

    pFont->SetFontSize( 16.0 );
    painter.SetFont( pFont );
    painter.DrawText( 100, 100, "Hello World" );
    painter.FinishPage();

    writer.SetEncrypted( "user", "owner" );
    writer.Write( pszFilename );

    printf( "Wrote: %s\n", pszFilename );
}