diff --git a/lib/appendPage.js b/lib/appendPage.js index b7895dc..8fd079b 100644 --- a/lib/appendPage.js +++ b/lib/appendPage.js @@ -13,8 +13,12 @@ exports.appendPage = function appendPage(pdfSrc, pages = []) { if (!Array.isArray(pages) && !isNaN(pages)) { pages = [pages]; } - const pdfReader = hummus.createReader(pdfSrc); + // Using stream so it can be closed to release reader resource (Issue #61) + const instream = new hummus.PDFRStreamForFile(pdfSrc); + const pdfReader = hummus.createReader(instream); const pageCount = pdfReader.getPagesCount(); + instream.close(); + // prevent unmatched pagenumber const transformPageNumber = (pageNum) => { pageNum = (pageNum > pageCount) ? pageCount : pageNum;