Skip to content

Commit

Permalink
fix(#88): add support for encrypted pdfs in browser version (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
mojoaxel committed Dec 25, 2023
1 parent 390829b commit 7a6a80e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ const globalObject =
class PDFMerger {
constructor () {
this.reset()

this.loadOptions = {
// allow merging of encrypted pdfs (issue #88)
ignoreEncryption: true
}
}

reset () {
Expand Down Expand Up @@ -87,7 +92,7 @@ class PDFMerger {

async _addEntireDocument (input) {
const src = await this._getInputAsUint8Array(input)
const srcDoc = await PDFDocument.load(src)
const srcDoc = await PDFDocument.load(src, this.loadOptions)

const copiedPages = await this.doc.copyPages(srcDoc, srcDoc.getPageIndices())
copiedPages.forEach((page) => {
Expand All @@ -104,7 +109,7 @@ class PDFMerger {
}

const src = await this._getInputAsUint8Array(inputFile)
const srcDoc = await PDFDocument.load(src)
const srcDoc = await PDFDocument.load(src, this.loadOptions)
const pageCount = srcDoc.getPageCount()

if (from >= pageCount || to >= pageCount) {
Expand All @@ -123,7 +128,7 @@ class PDFMerger {
if (pages.length <= 0) return

const src = await this._getInputAsUint8Array(inputFile)
const srcDoc = await PDFDocument.load(src)
const srcDoc = await PDFDocument.load(src, this.loadOptions)

const pagesIndexed1 = pages.map(p => p - 1)
const copiedPages = await this.doc.copyPages(srcDoc, pagesIndexed1)
Expand Down

0 comments on commit 7a6a80e

Please sign in to comment.