Commit 33a47d5c3c4402d8d94b00ed9b3aa2c339203d2f

Authored by Jay Berkenbilt
1 parent 42ca1f00

Make QPDF::findPage public (fixes #516)

This was originally not public because I wanted to get rid fo the
pages cache, but I recently realized there were deep reasons not to do
that, and the author of pikepdf wanted this, so I decided to make it
public.
ChangeLog
1 1 2021-11-02 Jay Berkenbilt <ejb@ql.org>
2 2  
  3 + * Add QPDF::findPage to the public API. This is primarily to help
  4 + improve the efficiency of code that wraps the qpdf library, such
  5 + as pikepdf. Fixes #516.
  6 +
3 7 * zlib-flate: warn and exit with code 3 when there is corrupted
4 8 input data even when decompression is possible. We do this in the
5 9 zlib-flate CLI so that it can be more reliably used to test the
... ...
include/qpdf/QPDF.hh
... ... @@ -605,6 +605,15 @@ class QPDF
605 605 QPDF_DLL
606 606 std::vector<QPDFObjectHandle> const& getAllPages();
607 607  
  608 + // These methods, given a page object or its object/generation
  609 + // number, returns the 0-based index into the array returned by
  610 + // getAllPages() for that page. An exception is thrown if the page
  611 + // is not found.
  612 + QPDF_DLL
  613 + int findPage(QPDFObjGen const& og);
  614 + QPDF_DLL
  615 + int findPage(QPDFObjectHandle& page);
  616 +
608 617 // This method synchronizes QPDF's cache of the page structure
609 618 // with the actual /Pages tree. If you restrict changes to the
610 619 // /Pages tree, including addition, removal, or replacement of
... ... @@ -990,8 +999,6 @@ class QPDF
990 999 std::set<QPDFObjGen>& visited,
991 1000 std::set<QPDFObjGen>& seen);
992 1001 void insertPage(QPDFObjectHandle newpage, int pos);
993   - int findPage(QPDFObjGen const& og);
994   - int findPage(QPDFObjectHandle& page);
995 1002 void flattenPagesTree();
996 1003 void insertPageobjToPage(QPDFObjectHandle const& obj, int pos,
997 1004 bool check_duplicate);
... ...
libqpdf/QPDF_pages.cc
... ... @@ -345,6 +345,7 @@ QPDF::findPage(QPDFObjGen const&amp; og)
345 345 this->m->pageobj_to_pages_pos.find(og);
346 346 if (it == this->m->pageobj_to_pages_pos.end())
347 347 {
  348 + QTC::TC("qpdf", "QPDF_pages findPage not found");
348 349 setLastObjectDescription("page object", og.getObj(), og.getGen());
349 350 throw QPDFExc(qpdf_e_pages, this->m->file->getName(),
350 351 this->m->last_object_description, 0,
... ...
qpdf/qpdf.testcov
... ... @@ -595,3 +595,4 @@ QPDF resolve duplicated page in insert 0
595 595 QPDFWriter preserve object streams 1
596 596 QPDFWriter exclude from object stream 0
597 597 check unclosed --pages 1
  598 +QPDF_pages findPage not found 0
... ...