From 360f7d47a9c759cbecf7a636b64a88df94f7ab34 Mon Sep 17 00:00:00 2001 From: tanaikech Date: Mon, 5 Feb 2024 16:10:34 +0900 Subject: [PATCH] Updated to v1.0.4 --- PDFApp.js | 12 ++++++------ README.md | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/PDFApp.js b/PDFApp.js index 76883fd..526bdcc 100644 --- a/PDFApp.js +++ b/PDFApp.js @@ -267,7 +267,7 @@ class PDFApp { try { const pdfData = await this.getPDFObjectFromBlob_(pdfBlob).catch(err => reject(err)); const pdfDoc = await this.PDFLib.PDFDocument.create(); - const pages = await pdfDoc.copyPages(pdfData, [...Array(pdfData.getPageCount())].map((_, i) => i)); + const pages = await pdfDoc.copyPages(pdfData, pdfData.getPageIndices()); pages.forEach((page, i) => { if (pageNumbers.includes(i + 1)) { pdfDoc.addPage(page); @@ -297,7 +297,7 @@ class PDFApp { const metadata = keys.reduce((o, k) => ((o[k] = pdfData[`get${k.charAt(0).toUpperCase() + k.slice(1)}`]() || null), o), {}); metadata.numberOfPages = pdfData.getPageCount(); const pdfDoc = await this.PDFLib.PDFDocument.create(); - const pages = await pdfDoc.copyPages(pdfData, [...Array(pdfData.getPageCount())].map((_, i) => i)); + const pages = await pdfDoc.copyPages(pdfData, pdfData.getPageIndices()); metadata.pageInfo = pages.map((page, i) => { const { width, height } = page.getSize(); const { x, y } = page.getPosition(); @@ -391,7 +391,7 @@ class PDFApp { skippedPages = [...Array(numberOfPages)].map((_, i) => i + 1).filter(e => !newOrderOfpages.includes(e)); } const pdfDoc = await self.PDFLib.PDFDocument.create(); - const pages = await pdfDoc.copyPages(pdfData, [...Array(numberOfPages)].map((_, i) => i)); + const pages = await pdfDoc.copyPages(pdfData, pdfData.getPageIndices()); [...newOrderOfpages, ...skippedPages].forEach(e => pdfDoc.addPage(pages[e - 1])); const bytes = await pdfDoc.save(); const newBlob = Utilities.newBlob([...new Int8Array(bytes)], MimeType.PDF, `new_${pdfBlob.getName()}`); @@ -620,7 +620,7 @@ class PDFApp { self.loadFontkit_(); pdfDoc.registerFontkit(this.fontkit); } - const pages = await pdfDoc.copyPages(pdfData, [...Array(numberOfPages)].map((_, i) => i)); + const pages = await pdfDoc.copyPages(pdfData, pdfData.getPageIndices()); for (let i = 0; i < pages.length; i++) { const page = pages[i]; const forPage = updatedObject[`page${i + 1}`]; @@ -685,7 +685,7 @@ class PDFApp { } const pdfData = await self.getPDFObjectFromBlob_(pdfBlob).catch(err => reject(err)); const numberOfPages = pdfData.getPageCount(); - const pages = await pdfDoc.copyPages(pdfData, [...Array(numberOfPages)].map((_, i) => i)); + const pages = await pdfDoc.copyPages(pdfData, pdfData.getPageIndices()); const { header, footer } = object; const headers = header ? Object.entries(header).map(([k, v]) => [`header.${k}`, v]) : []; const footers = footer ? Object.entries(footer).map(([k, v]) => [`footer.${k}`, v]) : []; @@ -786,7 +786,7 @@ class PDFApp { } const pdfData = await self.getPDFObjectFromBlob_(blob).catch(err => reject(err)); const numberOfPages = pdfData.getPageCount(); - const pages = await pdfDoc.copyPages(pdfData, [...Array(numberOfPages)].map((_, i) => i)); + const pages = await pdfDoc.copyPages(pdfData, pdfData.getPageIndices()); const xAxisOffset = 0.5; const yAxisOffset = 0.5; for (let i = 0; i < numberOfPages; i++) { diff --git a/README.md b/README.md index 7f57b4f..6ac5fda 100644 --- a/README.md +++ b/README.md @@ -1011,4 +1011,8 @@ function sample2() { 1. From [this discussion](https://github.com/Hopding/pdf-lib/issues/252), I changed the logic of the method `mergePDFs`. The method for using `mergePDFs` and the output are not changed. With this modification, the large PDF data can be merged. +- v1.0.4 (February 5, 2024) + + 1. From [this discussion](https://github.com/Hopding/pdf-lib/issues/252), I changed the logic of `copyPages`. + [TOP](#top)