2024-07-05 13:09:43 +00:00
|
|
|
#include <qpdf/QPDF_private.hh>
|
2012-06-21 13:18:49 +00:00
|
|
|
|
|
|
|
#include <qpdf/QPDFExc.hh>
|
|
|
|
#include <qpdf/QTC.hh>
|
|
|
|
#include <qpdf/QUtil.hh>
|
|
|
|
|
2012-06-21 14:42:18 +00:00
|
|
|
// In support of page manipulation APIs, these methods internally maintain state about pages in a
|
|
|
|
// pair of data structures: all_pages, which is a vector of page objects, and pageobj_to_pages_pos,
|
|
|
|
// which maps a page object to its position in the all_pages array. Unfortunately, the getAllPages()
|
|
|
|
// method returns a const reference to all_pages and has been in the public API long before the
|
|
|
|
// introduction of mutation APIs, so we're pretty much stuck with it. Anyway, there are lots of
|
2021-04-05 14:45:18 +00:00
|
|
|
// calls to it in the library, so the efficiency of having it cached is probably worth keeping it.
|
|
|
|
// At one point, I had partially implemented a helper class specifically for the pages tree, but
|
|
|
|
// once you work in all the logic that handles repairing the /Type keys of page tree nodes (both
|
|
|
|
// /Pages and /Page) and deal with duplicate pages, it's just as complex and less efficient than
|
|
|
|
// what's here. So, in spite of the fact that a const reference is returned, the current code is
|
|
|
|
// fine and does not need to be replaced. A partial implementation of QPDFPagesTree is in github in
|
|
|
|
// attic in case there is ever a reason to resurrect it. There are additional notes in
|
2022-06-25 17:25:52 +00:00
|
|
|
// README-maintainer, which also refers to this comment.
|
2012-06-21 14:42:18 +00:00
|
|
|
|
|
|
|
// The goal of this code is to ensure that the all_pages vector, which users may have a reference
|
|
|
|
// to, and the pageobj_to_pages_pos map, which users will not have access to, remain consistent
|
|
|
|
// outside of any call to the library. As long as users only touch the /Pages structure through
|
|
|
|
// page-specific API calls, they never have to worry about anything, and this will also stay
|
|
|
|
// consistent. If a user touches anything about the /Pages structure outside of these calls (such
|
|
|
|
// as by directly looking up and manipulating the underlying objects), they can call
|
|
|
|
// updatePagesCache() to bring things back in sync.
|
|
|
|
|
|
|
|
// If the user doesn't ever use the page manipulation APIs, then qpdf leaves the /Pages structure
|
|
|
|
// alone. If the user does use the APIs, then we push all inheritable objects down and flatten the
|
|
|
|
// /Pages tree. This makes it easier for us to keep /Pages, all_pages, and pageobj_to_pages_pos
|
|
|
|
// internally consistent at all times.
|
|
|
|
|
|
|
|
// Responsibility for keeping all_pages, pageobj_to_pages_pos, and the Pages structure consistent
|
|
|
|
// should remain in as few places as possible. As of initial writing, only flattenPagesTree,
|
|
|
|
// insertPage, and removePage, along with methods they call, are concerned with it. Everything else
|
|
|
|
// goes through one of those methods.
|
|
|
|
|
2012-06-21 13:18:49 +00:00
|
|
|
std::vector<QPDFObjectHandle> const&
|
|
|
|
QPDF::getAllPages()
|
|
|
|
{
|
2012-06-22 16:11:25 +00:00
|
|
|
// Note that pushInheritedAttributesToPage may also be used to initialize m->all_pages.
|
2024-07-16 13:35:32 +00:00
|
|
|
if (m->all_pages.empty() && !m->invalid_page_found) {
|
2022-06-25 17:55:45 +00:00
|
|
|
m->ever_called_get_all_pages = true;
|
2023-05-18 16:57:47 +00:00
|
|
|
QPDFObjGen::set visited;
|
|
|
|
QPDFObjGen::set seen;
|
2020-02-22 16:00:38 +00:00
|
|
|
QPDFObjectHandle pages = getRoot().getKey("/Pages");
|
|
|
|
bool warned = false;
|
|
|
|
bool changed_pages = false;
|
|
|
|
while (pages.isDictionary() && pages.hasKey("/Parent")) {
|
2023-05-18 16:57:47 +00:00
|
|
|
if (!seen.add(pages)) {
|
2020-02-22 16:00:38 +00:00
|
|
|
// loop -- will be detected again and reported later
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Files have been found in the wild where /Pages in the catalog points to the first
|
|
|
|
// page. Try to work around this and similar cases with this heuristic.
|
|
|
|
if (!warned) {
|
|
|
|
getRoot().warnIfPossible("document page tree root (root -> /Pages) doesn't point"
|
|
|
|
" to the root of the page tree; attempting to correct");
|
|
|
|
warned = true;
|
|
|
|
}
|
|
|
|
changed_pages = true;
|
|
|
|
pages = pages.getKey("/Parent");
|
|
|
|
}
|
|
|
|
if (changed_pages) {
|
|
|
|
getRoot().replaceKey("/Pages", pages);
|
|
|
|
}
|
|
|
|
seen.clear();
|
2024-07-16 13:44:47 +00:00
|
|
|
if (!pages.hasKey("/Kids")) {
|
2022-07-12 11:35:24 +00:00
|
|
|
// Ensure we actually found a /Pages object.
|
2024-07-16 13:44:47 +00:00
|
|
|
throw QPDFExc(
|
|
|
|
qpdf_e_pages, m->file->getName(), "", 0, "root of pages tree has no /Kids array");
|
2022-07-12 11:35:24 +00:00
|
|
|
}
|
2024-09-16 13:05:19 +00:00
|
|
|
try {
|
|
|
|
getAllPagesInternal(pages, visited, seen, false);
|
|
|
|
} catch (...) {
|
|
|
|
m->all_pages.clear();
|
|
|
|
m->invalid_page_found = false;
|
|
|
|
throw;
|
|
|
|
}
|
2024-07-16 13:35:32 +00:00
|
|
|
if (m->invalid_page_found) {
|
|
|
|
flattenPagesTree();
|
|
|
|
m->invalid_page_found = false;
|
|
|
|
}
|
2012-06-21 13:18:49 +00:00
|
|
|
}
|
2017-08-22 01:33:44 +00:00
|
|
|
return m->all_pages;
|
2012-06-21 13:18:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-08-18 22:54:08 +00:00
|
|
|
QPDF::getAllPagesInternal(
|
2023-07-29 12:16:40 +00:00
|
|
|
QPDFObjectHandle cur_node, QPDFObjGen::set& visited, QPDFObjGen::set& seen, bool media_box)
|
2015-02-21 23:22:32 +00:00
|
|
|
{
|
2023-05-18 16:57:47 +00:00
|
|
|
if (!visited.add(cur_node)) {
|
2015-02-21 23:22:32 +00:00
|
|
|
throw QPDFExc(
|
2017-08-22 01:33:44 +00:00
|
|
|
qpdf_e_pages,
|
|
|
|
m->file->getName(),
|
|
|
|
m->last_object_description,
|
|
|
|
0,
|
2015-02-21 23:22:32 +00:00
|
|
|
"Loop detected in /Pages structure (getAllPages)");
|
|
|
|
}
|
2022-07-12 11:35:24 +00:00
|
|
|
if (!cur_node.isDictionaryOfType("/Pages")) {
|
|
|
|
cur_node.warnIfPossible("/Type key should be /Pages but is not; overriding");
|
|
|
|
cur_node.replaceKey("/Type", "/Pages"_qpdf);
|
|
|
|
}
|
2023-07-29 12:16:40 +00:00
|
|
|
if (!media_box) {
|
|
|
|
media_box = cur_node.getKey("/MediaBox").isRectangle();
|
|
|
|
QTC::TC("qpdf", "QPDF inherit mediabox", media_box ? 0 : 1);
|
|
|
|
}
|
2022-07-12 11:35:24 +00:00
|
|
|
auto kids = cur_node.getKey("/Kids");
|
|
|
|
int n = kids.getArrayNItems();
|
|
|
|
for (int i = 0; i < n; ++i) {
|
|
|
|
auto kid = kids.getArrayItem(i);
|
2024-07-10 17:00:36 +00:00
|
|
|
if (!kid.isDictionary()) {
|
2024-07-11 12:27:50 +00:00
|
|
|
kid.warnIfPossible("Pages tree includes non-dictionary object; ignoring");
|
2024-07-16 13:35:32 +00:00
|
|
|
m->invalid_page_found = true;
|
2024-07-10 17:00:36 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-07-12 11:35:24 +00:00
|
|
|
if (kid.hasKey("/Kids")) {
|
2023-07-29 12:16:40 +00:00
|
|
|
getAllPagesInternal(kid, visited, seen, media_box);
|
2022-07-12 11:35:24 +00:00
|
|
|
} else {
|
2023-07-29 12:16:40 +00:00
|
|
|
if (!media_box && !kid.getKey("/MediaBox").isRectangle()) {
|
|
|
|
QTC::TC("qpdf", "QPDF missing mediabox");
|
|
|
|
kid.warnIfPossible(
|
|
|
|
"kid " + std::to_string(i) +
|
|
|
|
" (from 0) MediaBox is undefined; setting to letter / ANSI A");
|
|
|
|
kid.replaceKey(
|
|
|
|
"/MediaBox",
|
|
|
|
QPDFObjectHandle::newArray(QPDFObjectHandle::Rectangle(0, 0, 612, 792)));
|
|
|
|
}
|
2019-01-29 22:01:36 +00:00
|
|
|
if (!kid.isIndirect()) {
|
|
|
|
QTC::TC("qpdf", "QPDF handle direct page object");
|
2022-06-25 15:29:32 +00:00
|
|
|
cur_node.warnIfPossible(
|
|
|
|
"kid " + std::to_string(i) + " (from 0) is direct; converting to indirect");
|
2019-01-29 22:01:36 +00:00
|
|
|
kid = makeIndirectObject(kid);
|
|
|
|
kids.setArrayItem(i, kid);
|
2023-05-18 16:57:47 +00:00
|
|
|
} else if (!seen.add(kid)) {
|
2019-01-29 01:13:10 +00:00
|
|
|
// Make a copy of the page. This does the same as shallowCopyPage in
|
|
|
|
// QPDFPageObjectHelper.
|
|
|
|
QTC::TC("qpdf", "QPDF resolve duplicated page object");
|
2022-06-25 15:29:32 +00:00
|
|
|
cur_node.warnIfPossible(
|
2022-09-21 16:49:21 +00:00
|
|
|
"kid " + std::to_string(i) +
|
2022-06-25 15:29:32 +00:00
|
|
|
" (from 0) appears more than once in the pages tree;"
|
|
|
|
" creating a new page object as a copy");
|
2019-01-29 01:13:10 +00:00
|
|
|
kid = makeIndirectObject(QPDFObjectHandle(kid).shallowCopy());
|
2023-05-18 16:57:47 +00:00
|
|
|
seen.add(kid);
|
2019-01-29 01:13:10 +00:00
|
|
|
kids.setArrayItem(i, kid);
|
|
|
|
}
|
2022-07-12 11:35:24 +00:00
|
|
|
if (!kid.isDictionaryOfType("/Page")) {
|
|
|
|
kid.warnIfPossible("/Type key should be /Page but is not; overriding");
|
|
|
|
kid.replaceKey("/Type", "/Page"_qpdf);
|
|
|
|
}
|
|
|
|
m->all_pages.push_back(kid);
|
2022-02-08 14:18:08 +00:00
|
|
|
}
|
2012-06-21 13:18:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-06-21 14:42:18 +00:00
|
|
|
QPDF::updateAllPagesCache()
|
2012-06-21 13:18:49 +00:00
|
|
|
{
|
2012-06-21 14:42:18 +00:00
|
|
|
// Force regeneration of the pages cache. We force immediate recalculation of all_pages since
|
|
|
|
// users may have references to it that they got from calls to getAllPages(). We can defer
|
|
|
|
// recalculation of pageobj_to_pages_pos until needed.
|
|
|
|
QTC::TC("qpdf", "QPDF updateAllPagesCache");
|
2017-08-22 01:33:44 +00:00
|
|
|
m->all_pages.clear();
|
|
|
|
m->pageobj_to_pages_pos.clear();
|
|
|
|
m->pushed_inherited_attributes_to_pages = false;
|
2012-06-21 14:42:18 +00:00
|
|
|
getAllPages();
|
2012-06-21 13:18:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QPDF::flattenPagesTree()
|
|
|
|
{
|
2012-06-21 14:42:18 +00:00
|
|
|
// If not already done, flatten the /Pages structure and initialize pageobj_to_pages_pos.
|
2012-06-21 13:18:49 +00:00
|
|
|
|
2017-08-22 01:33:44 +00:00
|
|
|
if (!m->pageobj_to_pages_pos.empty()) {
|
2012-06-21 14:42:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-06-21 13:18:49 +00:00
|
|
|
|
2012-06-22 16:11:25 +00:00
|
|
|
// Push inherited objects down to the /Page level. As a side effect m->all_pages will also be
|
2017-08-22 01:33:44 +00:00
|
|
|
// generated.
|
2012-06-22 16:52:13 +00:00
|
|
|
pushInheritedAttributesToPage(true, true);
|
2012-06-21 13:18:49 +00:00
|
|
|
|
2012-06-21 20:05:02 +00:00
|
|
|
QPDFObjectHandle pages = getRoot().getKey("/Pages");
|
2012-06-21 13:18:49 +00:00
|
|
|
|
2019-06-21 03:35:23 +00:00
|
|
|
size_t const len = m->all_pages.size();
|
|
|
|
for (size_t pos = 0; pos < len; ++pos) {
|
2021-04-05 14:45:18 +00:00
|
|
|
// Populate pageobj_to_pages_pos and fix parent pointer. There should be no duplicates at
|
|
|
|
// this point because pushInheritedAttributesToPage calls getAllPages which resolves
|
|
|
|
// duplicates.
|
2019-06-21 03:35:23 +00:00
|
|
|
insertPageobjToPage(m->all_pages.at(pos), toI(pos), true);
|
2017-08-22 01:33:44 +00:00
|
|
|
m->all_pages.at(pos).replaceKey("/Parent", pages);
|
2012-06-21 13:18:49 +00:00
|
|
|
}
|
|
|
|
|
2017-08-22 01:33:44 +00:00
|
|
|
pages.replaceKey("/Kids", QPDFObjectHandle::newArray(m->all_pages));
|
2012-06-21 13:18:49 +00:00
|
|
|
// /Count has not changed
|
2019-06-21 03:35:23 +00:00
|
|
|
if (pages.getKey("/Count").getUIntValue() != len) {
|
2024-07-16 13:35:32 +00:00
|
|
|
if (m->invalid_page_found && pages.getKey("/Count").getUIntValue() > len) {
|
|
|
|
pages.replaceKey("/Count", QPDFObjectHandle::newInteger(toI(len)));
|
|
|
|
} else {
|
|
|
|
throw std::runtime_error("/Count is wrong after flattening pages tree");
|
|
|
|
}
|
2013-10-05 20:37:27 +00:00
|
|
|
}
|
2012-06-21 13:18:49 +00:00
|
|
|
}
|
|
|
|
|
2012-06-21 14:42:18 +00:00
|
|
|
void
|
|
|
|
QPDF::insertPageobjToPage(QPDFObjectHandle const& obj, int pos, bool check_duplicate)
|
2012-06-21 13:18:49 +00:00
|
|
|
{
|
2013-06-14 15:58:37 +00:00
|
|
|
QPDFObjGen og(obj.getObjGen());
|
2012-06-21 16:21:34 +00:00
|
|
|
if (check_duplicate) {
|
2017-08-22 01:33:44 +00:00
|
|
|
if (!m->pageobj_to_pages_pos.insert(std::make_pair(og, pos)).second) {
|
2021-04-05 14:45:18 +00:00
|
|
|
// The library never calls insertPageobjToPage in a way that causes this to happen.
|
2022-09-21 16:49:21 +00:00
|
|
|
setLastObjectDescription("page " + std::to_string(pos) + " (numbered from zero)", og);
|
2017-08-22 01:33:44 +00:00
|
|
|
throw QPDFExc(
|
|
|
|
qpdf_e_pages,
|
|
|
|
m->file->getName(),
|
|
|
|
m->last_object_description,
|
|
|
|
0,
|
2012-06-21 16:21:34 +00:00
|
|
|
"duplicate page reference found; this would cause loss of data");
|
|
|
|
}
|
|
|
|
} else {
|
2017-08-22 01:33:44 +00:00
|
|
|
m->pageobj_to_pages_pos[og] = pos;
|
2012-06-21 13:18:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-06-21 14:42:18 +00:00
|
|
|
QPDF::insertPage(QPDFObjectHandle newpage, int pos)
|
2012-06-21 13:18:49 +00:00
|
|
|
{
|
2012-07-29 18:32:54 +00:00
|
|
|
// pos is numbered from 0, so pos = 0 inserts at the beginning and pos = npages adds to the end.
|
2012-06-21 13:18:49 +00:00
|
|
|
|
2012-06-21 14:42:18 +00:00
|
|
|
flattenPagesTree();
|
|
|
|
|
2012-06-21 16:21:34 +00:00
|
|
|
if (!newpage.isIndirect()) {
|
|
|
|
QTC::TC("qpdf", "QPDF insert non-indirect page");
|
2017-08-22 01:33:44 +00:00
|
|
|
newpage = makeIndirectObject(newpage);
|
2012-07-11 19:29:41 +00:00
|
|
|
} else if (newpage.getOwningQPDF() != this) {
|
|
|
|
QTC::TC("qpdf", "QPDF insert foreign page");
|
2022-09-07 15:29:17 +00:00
|
|
|
newpage.getQPDF().pushInheritedAttributesToPage();
|
2019-01-29 02:53:55 +00:00
|
|
|
newpage = copyForeignObject(newpage);
|
2012-06-21 16:21:34 +00:00
|
|
|
} else {
|
|
|
|
QTC::TC("qpdf", "QPDF insert indirect page");
|
|
|
|
}
|
|
|
|
|
2022-07-13 13:24:19 +00:00
|
|
|
if ((pos < 0) || (toS(pos) > m->all_pages.size())) {
|
2022-05-03 11:41:07 +00:00
|
|
|
throw std::runtime_error("QPDF::insertPage called with pos out of range");
|
|
|
|
}
|
|
|
|
|
2012-06-21 14:42:18 +00:00
|
|
|
QTC::TC(
|
|
|
|
"qpdf",
|
|
|
|
"QPDF insert page",
|
|
|
|
(pos == 0) ? 0 : // insert at beginning
|
2022-07-13 13:24:19 +00:00
|
|
|
(pos == toI(m->all_pages.size())) ? 1 // at end
|
|
|
|
: 2); // insert in middle
|
2012-06-21 13:18:49 +00:00
|
|
|
|
2021-04-05 14:45:18 +00:00
|
|
|
auto og = newpage.getObjGen();
|
|
|
|
if (m->pageobj_to_pages_pos.count(og)) {
|
|
|
|
QTC::TC("qpdf", "QPDF resolve duplicated page in insert");
|
|
|
|
newpage = makeIndirectObject(QPDFObjectHandle(newpage).shallowCopy());
|
|
|
|
}
|
|
|
|
|
2012-06-21 20:05:02 +00:00
|
|
|
QPDFObjectHandle pages = getRoot().getKey("/Pages");
|
2012-06-21 13:18:49 +00:00
|
|
|
QPDFObjectHandle kids = pages.getKey("/Kids");
|
|
|
|
|
|
|
|
newpage.replaceKey("/Parent", pages);
|
2012-06-21 14:42:18 +00:00
|
|
|
kids.insertItem(pos, newpage);
|
|
|
|
int npages = kids.getArrayNItems();
|
|
|
|
pages.replaceKey("/Count", QPDFObjectHandle::newInteger(npages));
|
2017-08-22 01:33:44 +00:00
|
|
|
m->all_pages.insert(m->all_pages.begin() + pos, newpage);
|
2012-06-21 14:42:18 +00:00
|
|
|
for (int i = pos + 1; i < npages; ++i) {
|
2019-06-21 03:35:23 +00:00
|
|
|
insertPageobjToPage(m->all_pages.at(toS(i)), i, false);
|
2012-06-21 13:18:49 +00:00
|
|
|
}
|
2012-06-21 14:42:18 +00:00
|
|
|
insertPageobjToPage(newpage, pos, true);
|
2012-06-21 13:18:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-06-21 14:42:18 +00:00
|
|
|
QPDF::removePage(QPDFObjectHandle page)
|
2012-06-21 13:18:49 +00:00
|
|
|
{
|
2012-06-21 14:42:18 +00:00
|
|
|
int pos = findPage(page); // also ensures flat /Pages
|
|
|
|
QTC::TC(
|
|
|
|
"qpdf",
|
|
|
|
"QPDF remove page",
|
2013-02-24 02:46:21 +00:00
|
|
|
(pos == 0) ? 0 : // remove at beginning
|
2022-07-13 13:24:19 +00:00
|
|
|
(pos == toI(m->all_pages.size() - 1)) ? 1 // end
|
|
|
|
: 2); // remove in middle
|
2012-06-21 13:18:49 +00:00
|
|
|
|
2012-06-21 20:05:02 +00:00
|
|
|
QPDFObjectHandle pages = getRoot().getKey("/Pages");
|
2012-06-21 13:18:49 +00:00
|
|
|
QPDFObjectHandle kids = pages.getKey("/Kids");
|
|
|
|
|
2012-06-21 14:42:18 +00:00
|
|
|
kids.eraseItem(pos);
|
|
|
|
int npages = kids.getArrayNItems();
|
|
|
|
pages.replaceKey("/Count", QPDFObjectHandle::newInteger(npages));
|
2017-08-22 01:33:44 +00:00
|
|
|
m->all_pages.erase(m->all_pages.begin() + pos);
|
|
|
|
m->pageobj_to_pages_pos.erase(page.getObjGen());
|
2012-06-21 14:42:18 +00:00
|
|
|
for (int i = pos; i < npages; ++i) {
|
2019-06-21 03:35:23 +00:00
|
|
|
insertPageobjToPage(m->all_pages.at(toS(i)), i, false);
|
2012-06-21 14:42:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QPDF::addPageAt(QPDFObjectHandle newpage, bool before, QPDFObjectHandle refpage)
|
|
|
|
{
|
|
|
|
int refpos = findPage(refpage);
|
2012-06-21 13:18:49 +00:00
|
|
|
if (!before) {
|
|
|
|
++refpos;
|
|
|
|
}
|
2012-06-21 14:42:18 +00:00
|
|
|
insertPage(newpage, refpos);
|
2012-06-21 13:18:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-06-21 14:42:18 +00:00
|
|
|
QPDF::addPage(QPDFObjectHandle newpage, bool first)
|
2012-06-21 13:18:49 +00:00
|
|
|
{
|
2012-06-21 14:42:18 +00:00
|
|
|
if (first) {
|
|
|
|
insertPage(newpage, 0);
|
|
|
|
} else {
|
2019-06-21 03:35:23 +00:00
|
|
|
insertPage(newpage, getRoot().getKey("/Pages").getKey("/Count").getIntValueAsInt());
|
2012-06-21 14:42:18 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-21 13:18:49 +00:00
|
|
|
|
2012-06-21 14:42:18 +00:00
|
|
|
int
|
|
|
|
QPDF::findPage(QPDFObjectHandle& page)
|
|
|
|
{
|
2013-06-14 15:58:37 +00:00
|
|
|
return findPage(page.getObjGen());
|
2012-06-21 14:42:18 +00:00
|
|
|
}
|
2012-06-21 13:18:49 +00:00
|
|
|
|
2012-06-21 14:42:18 +00:00
|
|
|
int
|
2013-06-14 15:58:37 +00:00
|
|
|
QPDF::findPage(QPDFObjGen const& og)
|
2012-06-21 14:42:18 +00:00
|
|
|
{
|
|
|
|
flattenPagesTree();
|
2022-04-30 17:23:18 +00:00
|
|
|
auto it = m->pageobj_to_pages_pos.find(og);
|
2017-08-22 01:33:44 +00:00
|
|
|
if (it == m->pageobj_to_pages_pos.end()) {
|
2021-11-02 22:12:39 +00:00
|
|
|
QTC::TC("qpdf", "QPDF_pages findPage not found");
|
2022-07-23 15:48:28 +00:00
|
|
|
setLastObjectDescription("page object", og);
|
2017-08-22 01:33:44 +00:00
|
|
|
throw QPDFExc(
|
|
|
|
qpdf_e_pages,
|
|
|
|
m->file->getName(),
|
|
|
|
m->last_object_description,
|
|
|
|
0,
|
2012-06-22 20:25:29 +00:00
|
|
|
"page object not referenced in /Pages tree");
|
2012-06-21 14:42:18 +00:00
|
|
|
}
|
|
|
|
return (*it).second;
|
2012-06-21 13:18:49 +00:00
|
|
|
}
|