Skip to content

Commit

Permalink
Updated to v1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
tanaikech committed Feb 5, 2024
1 parent b5144e8 commit 360f7d4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 6 additions & 6 deletions PDFApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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()}`);
Expand Down Expand Up @@ -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}`];
Expand Down Expand Up @@ -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]) : [];
Expand Down Expand Up @@ -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++) {
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 360f7d4

Please sign in to comment.