Hello. Please consider the following snippet:
#include <podofo/podofo.h> int main() { using namespace PoDoFo; try{ PdfError::EnableLogging(false); PdfMemDocument doc; PdfPainter painter; PdfFont *font = doc.CreateFont("Arial"); font->SetFontSize(40); PdfMemDocument docToAppend; const int PAGES_COUNT = 2; // enough for test for(int p = 0; p < PAGES_COUNT; ++p) { docToAppend.CreatePage(PdfPage::CreateStandardPageSize( ePdfPageSize_A4)); } for(int p = 0; p < docToAppend.GetPageCount(); ++p) { doc.InsertPages(docToAppend, p, 1); doc.GetPage( p ); // IF comment this line bug dissappears OR uncomment ClearCache } // doc.GetPagesTree()->ClearCache(); for(int p = 0; p < doc.GetPageCount(); ++p) { PdfPage *pPage = doc.GetPage( p ); char text[100]; sprintf(text, "Text for page %d", p+1); painter.SetPage(pPage); painter.SetFont(font); painter.DrawText( 30, pPage->GetPageSize().GetHeight() / 2, text ); painter.FinishPage(); } doc.Write("output.pdf"); } catch(const PdfError &e) { e.PrintErrorMsg(); throw; } return 0; }Firstly I'm creating 2 blank pages. Then one by one inserting that pages into new document, but in every iteration also I'm calling fake GetPage() which apparently creates a cache. Then I draw sample text with page number on each page, but we get "Text for page 2" on first page and nothing on second.
If I comment out fake "GetPage" or explicitly call "ClearCache" it works as expected;
Thanks.
#include <podofo/podofo.h> int main() { using namespace PoDoFo; try{ PdfError::EnableLogging(false); PdfMemDocument doc; PdfPainter painter; PdfFont *font = doc.CreateFont("Arial"); font->SetFontSize(40); PdfMemDocument docToAppend; const int PAGES_COUNT = 2; // enough for test for(int p = 0; p < PAGES_COUNT; ++p) { docToAppend.CreatePage(PdfPage::CreateStandardPageSize( ePdfPageSize_A4)); } for(int p = 0; p < docToAppend.GetPageCount(); ++p) { doc.InsertPages(docToAppend, p, 1); doc.GetPage( p ); // IF comment this line bug dissappears OR uncomment ClearCache } // doc.GetPagesTree()->ClearCache(); for(int p = 0; p < doc.GetPageCount(); ++p) { PdfPage *pPage = doc.GetPage( p ); char text[100]; sprintf(text, "Text for page %d", p+1); painter.SetPage(pPage); painter.SetFont(font); painter.DrawText( 30, pPage->GetPageSize().GetHeight() / 2, text ); painter.FinishPage(); } doc.Write("output.pdf"); } catch(const PdfError &e) { e.PrintErrorMsg(); throw; } return 0; }
------------------------------------------------------------------------------ Get 100% visibility into Java/.NET code with AppDynamics Lite! It's a free troubleshooting tool designed for production. Get down to code-level detail for bottlenecks, with <2% overhead. Download for free and get started troubleshooting in minutes. http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________ Podofo-users mailing list Podofo-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/podofo-users