Skip to content

Commit

Permalink
Updated to v1.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
tanaikech committed May 15, 2024
1 parent 574bd10 commit d8f4add
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 9 additions & 5 deletions PDFApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -826,11 +826,15 @@ class PDFApp {
const pdfDoc = await self.PDFLib.PDFDocument.create();
(await pdfDoc.copyPages(pdfData, pdfData.getPageIndices()))
.forEach((page, i) => {
const { width } = page.getSize();
const obj = { center: width / 2, left: 20, right: width - 20 };
const pageFormatObj = { ...object };
pageFormatObj.x = obj[object.x];
page.drawText(`${i + 1}`, pageFormatObj);
if (isNaN(object.x)) {
const { width } = page.getSize();
const obj = { center: width / 2, left: 20, right: width - 20 };
const pageFormatObj = { ...object };
pageFormatObj.x = obj[object.x];
page.drawText(`${i + 1}`, pageFormatObj);
} else {
page.drawText(`${i + 1}`, object);
}
pdfDoc.addPage(page);
});
const bytes = await pdfDoc.save();
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,7 @@ function sample() {
- When this script is run, the page numbers are put to the center of the bottom of each page.
- You can simply customize the page numbers by modifying `const object = { size: 10, x: "center", y: 10 }`. The value of `x` can be selected as one of "left", "center", and "right".
- In this method, a simple format like `{ size: 10, x: "center", y: 10 }` is used for the page numbers. Here, the page numbers are put to only "left", "center", and "right" of the bottom of the page. The page numbers can be customized variously. So, when you want to customize more, I would like to recommend using the script on [my blog](https://medium.com/google-cloud/adding-page-numbers-to-pdf-using-google-apps-script-ae964fb07655) by modifying.
- When a number is used to the property `x` instead of "left", "center", and "right", the inputted number is directly used. For example, you can also use `const object = { size: 10, x: 10, y: 10 };` instead of `const object = { size: 10, x: "center", y: 10 };`.

---

Expand Down Expand Up @@ -1091,4 +1092,8 @@ function sample() {

1. A new method of "addPageNumbers" was added. [Ref](#addpagenumbers) This method adds the page numbers to each page of the PDF.

- v1.0.7 (May 15, 2024)

1. The method of "addPageNumbers" was updated. [Ref](#addpagenumbers) When a number is used to the property `x` instead of "left", "center", and "right", the inputted number is directly used.

[TOP](#top)

0 comments on commit d8f4add

Please sign in to comment.