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 ); }
void PagesTreeTest::testInsert( PdfMemDocument & doc ) { const int INSERTED_PAGE_FLAG= 1234; const int INSERTED_PAGE_FLAG1= 1234 + 1; const int INSERTED_PAGE_FLAG2= 1234 + 2; PdfPage* pPage = new PdfPage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ), &(doc.GetObjects()) ); pPage->GetObject()->GetDictionary().AddKey( PODOFO_TEST_PAGE_KEY, static_cast<long long>(INSERTED_PAGE_FLAG) ); // Insert page at the beginning doc.GetPagesTree()->InsertPage( ePdfPageInsertionPoint_InsertBeforeFirstPage, pPage ); delete pPage; // Find inserted page (beginning) pPage = doc.GetPage( 0 ); CPPUNIT_ASSERT_EQUAL( IsPageNumber( pPage, INSERTED_PAGE_FLAG ), true ); // Find old first page pPage = doc.GetPage( 1 ); CPPUNIT_ASSERT_EQUAL( IsPageNumber( pPage, 0 ), true ); // Insert at end pPage = doc.CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ) ); pPage->GetObject()->GetDictionary().AddKey( PODOFO_TEST_PAGE_KEY, static_cast<long long>(INSERTED_PAGE_FLAG1) ); pPage = doc.GetPage( doc.GetPageCount() - 1 ); CPPUNIT_ASSERT_EQUAL( IsPageNumber( pPage, INSERTED_PAGE_FLAG1 ), true ); // Insert in middle pPage = new PdfPage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ), &(doc.GetObjects()) ); pPage->GetObject()->GetDictionary().AddKey( PODOFO_TEST_PAGE_KEY, static_cast<long long>(INSERTED_PAGE_FLAG2) ); const int INSERT_POINT = 50; doc.GetPagesTree()->InsertPage( INSERT_POINT, pPage ); delete pPage; pPage = doc.GetPage( INSERT_POINT + 1 ); CPPUNIT_ASSERT_EQUAL( IsPageNumber( pPage, INSERTED_PAGE_FLAG2 ), true ); }
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 ); }