Use the much faster new bulk page creation API I contributed to PoDoFo

See https://github.com/podofo/podofo/pull/86
This commit is contained in:
Kovid Goyal 2023-06-17 14:32:31 +05:30
parent 2acd1ee518
commit 5e2dd561b6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -388,13 +388,21 @@ PDFDoc_append(PDFDoc *self, PyObject *args) {
PyThreadState *_save; _save = PyEval_SaveThread();
try {
unsigned total_pages_to_append = 0;
for (auto src : docs) total_pages_to_append += src->GetPages().GetCount();
unsigned base_page_index = dest->GetPages().GetCount();
#if PODOFO_VERSION > PODOFO_MAKE_VERSION(0, 10, 0)
dest->GetPages().CreatePagesAt(base_page_index, Rect(), total_pages_to_append);
#else
while (total_pages_to_append--) dest->GetPages().CreatePage(Rect());
#endif
for (auto src : docs) {
MapReferences ref_map;
std::vector<AppendPagesData> pages;
// append pages first
for (unsigned i = 0; i < src->GetPages().GetCount(); i++) {
const auto& src_page = src->GetPages().GetPageAt(i);
auto& dest_page = dest->GetPages().CreatePage(src_page.GetRect());
auto& dest_page = dest->GetPages().GetPageAt(base_page_index++);
pages.emplace_back(src_page, dest_page);
dest_page.GetObject() = src_page.GetObject();
dest_page.GetDictionary().RemoveKey("Resource");