Skip to content

Commit

Permalink
support for nested pages in the pdfUtils.removePages fix #1085
Browse files Browse the repository at this point in the history
  • Loading branch information
pofider committed Aug 21, 2023
1 parent beeceb7 commit 1f64a50
Show file tree
Hide file tree
Showing 3 changed files with 2,555 additions and 2,518 deletions.
14 changes: 13 additions & 1 deletion packages/jsreport-pdf-utils/lib/pdfManipulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,20 @@ module.exports = (contentBuffer, { pdfMeta, pdfPassword, pdfSign, pdfA, outlines
}

const ext = new External(currentBuffer)
function collectPages (pagesObj, pages) {
for (const page of pagesObj.properties.get('Kids').map(k => k.object)) {
if (page.properties.get('Type').name === 'Pages') {
collectPages(page, pages)
} else {
pages.push(page)
}
}
}
const pages = []
collectPages(ext.catalog.properties.get('Pages').object, pages)

const pageIndexesToAppend = []
for (let i = 0; i < ext.catalog.properties.get('Pages').object.properties.get('Kids').length; i++) {
for (let i = 0; i < pages.length; i++) {
if (!pageNumbersToRemove.includes(i + 1)) {
pageIndexesToAppend.push(i)
}
Expand Down
Binary file not shown.

0 comments on commit 1f64a50

Please sign in to comment.