Skip to content

Commit

Permalink
Support printing range of last pages
Browse files Browse the repository at this point in the history
  • Loading branch information
uriroos authored and mojoaxel committed Oct 13, 2022
1 parent 581e6a6 commit 0385ec4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class PDFMerger {
const srcDoc = await PDFDocument.load(src, this.loadOptions)
const pageCount = srcDoc.getPageCount()

if (from >= pageCount || to >= pageCount) {
if (from > pageCount || to > pageCount) {
throw new Error(`Invalid function parameter. The document has not enought pages. (from:${from}, to:${to}, pages:${pageCount})`)
}

Expand Down
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/issues.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ describe('issues', () => {
await merger.save(path.join(TMP_DIR, 'issue-88_merged.pdf'))
})

test('merge the last pages of a pdf (#101)', async () => {
const merger = new PDFMerger()
await merger.add(path.join(FIXTURES_DIR, 'UDHR.pdf'), '7 to 8')
await merger.save(path.join(TMP_DIR, 'issue-101_me.pdf'))
})

afterAll(async () => {
await fs.remove(TMP_DIR)
})
Expand Down

0 comments on commit 0385ec4

Please sign in to comment.