Please, can you revise your patch again?
What is happening during first page creation is that InsertPage(-1,pPage) is called with special page number ePdfPageInsertionPoint_InsertBeforeFirstPage, and InsertPage() is accepting this value as special case, see code. Anyway, a few lines later, a GetPageNode(0, ...) is called, and critical message is logged. So, it should be regular to call GetPageNode() with page number zero, which does not have any kids yet. At least you could not emit a diagnostic message, for a nPageNUM == 0 and numKids == 0. enum EPdfPageInsertionPoint { ePdfPageInsertionPoint_InsertBeforeFirstPage = -1, ... }; PdfPagesTree.cpp:231 InsertPage( this->GetTotalNumberOfPages() - 1, pPage ); void PdfPagesTree::InsertPage( int nAfterPageIndex, PdfObject* pPage ) { bool bInsertBefore = false; !!! if( ePdfPageInsertionPoint_InsertBeforeFirstPage == nAfterPageIndex ) { bInsertBefore = true; !!! nAfterPageIndex = 0; } else if( nAfterPageIndex < 0 ) { ... return; } PdfObjectList lstParents; *** PdfObject* pPageBefore = this->GetPageNode( nAfterPageIndex, this->GetRoot(), lstParents ); Helloworld.cpp:120 pPage = document.CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ) ); PdfDocument.cpp:259 return m_pPagesTree->CreatePage( rSize ); PdfPagesTree.cpp:231 InsertPage( this->GetTotalNumberOfPages() - 1, pPage ); PdfPagesTree.cpp:120 this->InsertPage( nAfterPageIndex, inPage->GetObject() ); PdfPagesTree.cpp:144 PdfObject* pPageBefore = this->GetPageNode( nAfterPageIndex, this->GetRoot(), lstParents ); const size_t numDirectKids = rKidsArray.size(); const size_t numKids = GetChildCount(pParent); // use <= since nPageNum is 0-based if( static_cast<int>(numKids) <= nPageNum ) { PdfPagesTree.cpp:335 PdfError::LogMessage( eLogSeverity_Critical, "Cannot retrieve page %i from a document with only %i pages.", nPageNum, static_cast<int>(numKids) ); Starting program: D:\export\podofo\build\examples\helloworld\helloworld.exe a.pdf [New Thread 7156.0x1784] Breakpoint 1, Logger::LogMessage (this=0x6ec020 <logger>, eLogSeverity=PoDoFo::eLogSeverity_Critical, pszPrefix=0x689418 <CSWTCH.138+20> "CRITICAL: ", pszMsg=0x694090 <PoDoFo::PdfAnnotation::s_lNumActions+3192> "Cannot retrieve page %i from a document with only %i pages.", args=@0x22f87c: 0x22f898 "") at ..\..\..\examples\helloworld\helloworld.cpp:60 (gdb) where #0 Logger::LogMessage (this=0x6ec020 <logger>, eLogSeverity=PoDoFo::eLogSeverity_Critical, pszPrefix=0x689418 <CSWTCH.138+20> "CRITICAL: ", pszMsg=0x694090 <PoDoFo::PdfAnnotation::s_lNumActions+3192> "Cannot retrieve page %i from a document with only %i pages.", args=@0x22f87c: 0x22f898 "") at ..\..\..\examples\helloworld\helloworld.cpp:60 #1 0x00402be7 in PoDoFo::PdfError::LogMessageInternal (eLogSeverity=PoDoFo::eLogSeverity_Critical, pszMsg=0x694090 <PoDoFo::PdfAnnotation::s_lNumActions+3192> "Cannot retrieve page %i from a document with only %i pages.", args=@0x22f87c: 0x22f898 "") at ..\..\src\base\PdfError.cpp:551 #2 0x00402c8c in PoDoFo::PdfError::LogMessage (eLogSeverity=PoDoFo::eLogSeverity_Critical, pszMsg=0x694090 <PoDoFo::PdfAnnotation::s_lNumActions+3192> "Cannot retrieve page %i from a document with only %i pages.") at ..\..\src\base\PdfError.cpp:510 #3 0x00471d4c in PoDoFo::PdfPagesTree::GetPageNode (this=<optimized out>, nPageNum=<optimized out>, pParent=<optimized out>, rLstParents=...) at ..\..\src\doc\PdfPagesTree.cpp:335 #4 0x00473dbd in PoDoFo::PdfPagesTree::InsertPage (this=this@entry=0x34ac90, nAfterPageIndex=<optimized out>, pPage=<optimized out>) at ..\..\src\doc\PdfPagesTree.cpp:144 #5 0x004742b7 in InsertPage (inPage=<optimized out>, nAfterPageIndex=<optimized out>, this=<optimized out>) at ..\..\src\doc\PdfPagesTree.cpp:120 #6 PoDoFo::PdfPagesTree::CreatePage (this=<optimized out>, rSize=...) at ..\..\src\doc\PdfPagesTree.cpp:231 #7 0x0041dc2c in PoDoFo::PdfDocument::CreatePage (this=this@entry=0x22fb7c, rSize=...) at ..\..\src\doc\PdfDocument.cpp:259 #8 0x00401a4b in HelloWorld (pszFilename=<optimized out>) at ..\..\..\examples\helloworld\helloworld.cpp:120 #9 0x00677ca3 in main (argc=2, argv=0x342ec8) at ..\..\..\examples\helloworld\helloworld.cpp:261 (gdb) q PdfPagesTree::GetChildCount(002ec760) PdfPagesTree::GetIndirectKey(Count) pCount=002ecad0 PdfPagesTree::npages=0 PdfPagesTree::GetChildCount(002ec760) PdfPagesTree::GetIndirectKey(Count) pCount=002ecad0 PdfPagesTree::npages=0 CRITICAL: Cannot retrieve page 0 from a document with only 0 PdfPagesTree::GetChildCount(002ec760) PdfPagesTree::GetIndirectKey(Count) pCount=002ecad0 PdfPagesTree::npages=0 PdfPagesTree::GetChildCount(002ec760) PdfPagesTree::GetIndirectKey(Count) pCount=002ecad0 PdfPagesTree::npages=0 PdfPagesTree::GetChildCount(002ec760) PdfPagesTree::GetIndirectKey(Count) pCount=002edc70 PdfPagesTree::npages=1
------------------------------------------------------------------------------
_______________________________________________ Podofo-users mailing list Podofo-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/podofo-users