From: Gwurk <gw...@fi...> - 2008-04-30 23:30:44
|
Hi again, I noticed a problem where PDFedit seems to write an incorrect /Size entry in the new trailer it adds. Suppose the PDF we're editing has 5 entries in its xref table, but only 2 are used: xref 0 5 0000000001 65535 f 0000000002 00001 f 0000000000 00001 f 0000000123 00000 n 0000000456 00000 n trailer << /Size 5 /Root 4 0 R >> In OldStylePdfWriter::writeTrailer(), we compute the new /Size as: std::max(prevSection.objNum, (size_t)(maxObjNum + 1)) and prevSection.objNum is set by the caller XRefWriter::saveChanges(): secInfo={lastXRefPos, XRef::getNumObjects()}; And looking at XRef::getNumObjects(), it's defined as: virtual int getNumObjects() { int count=0; for(int i=0; i<size; i++) // counts just not free entries if(entries[i].type != xrefEntryFree) count++; return count; } Notice that it just counts the number of used entries; it does not return the number of the LAST used entry. So XRef::getNumObjects() would return 2, even though the xref table had 5 entries. If we wrote a new trailer with this information, it would have the wrong /Size. |