pdfbooklet 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/pdfbooklet.js +16 -5
package/package.json
CHANGED
package/pdfbooklet.js
CHANGED
|
@@ -69,13 +69,19 @@ async function createBooklet(inputPdfPath, outputPdfPath) {
|
|
|
69
69
|
const totalPages = pdfDoc.getPageCount();
|
|
70
70
|
|
|
71
71
|
// If no page numbers specified, use the whole range
|
|
72
|
-
const pageNumbers = inputPageNumbers ||
|
|
72
|
+
const pageNumbers = inputPageNumbers || []
|
|
73
|
+
if (pageNumbers.length == 0) {
|
|
74
|
+
for (let i = 0; i < totalPages; i++) {
|
|
75
|
+
pageNumbers.push(i);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
73
79
|
// Align the numbers to a multiple of 4, use blank page for padding
|
|
74
80
|
while (pageNumbers.length % 4 !== 0) {
|
|
75
81
|
pageNumbers.push(-1);
|
|
76
82
|
}
|
|
77
83
|
|
|
78
|
-
console.log(`Total pages in the input PDF: ${totalPages}
|
|
84
|
+
console.log(`Total pages in the input PDF: ${totalPages}, selected pages (0-based) =`, pageNumbers);
|
|
79
85
|
|
|
80
86
|
// Create a new PDF for the booklet
|
|
81
87
|
const bookletPdf = await PDFDocument.create();
|
|
@@ -101,7 +107,10 @@ async function createBooklet(inputPdfPath, outputPdfPath) {
|
|
|
101
107
|
}
|
|
102
108
|
|
|
103
109
|
const drawPageInBox = async (newPage, box, originPageIndex, flip) => {
|
|
104
|
-
if (originPageIndex < 0)
|
|
110
|
+
if (originPageIndex < 0) {
|
|
111
|
+
// Do not draw for page number -1
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
105
114
|
const a = await getEmbedPage(originPageIndex)
|
|
106
115
|
if (a) {
|
|
107
116
|
const {width, height} = a.size()
|
|
@@ -117,6 +126,8 @@ async function createBooklet(inputPdfPath, outputPdfPath) {
|
|
|
117
126
|
xScale: scale,
|
|
118
127
|
yScale: scale,
|
|
119
128
|
})
|
|
129
|
+
} else {
|
|
130
|
+
console.error("getEmbedPage failed at page " + originPageIndnex);
|
|
120
131
|
}
|
|
121
132
|
}
|
|
122
133
|
|
|
@@ -226,7 +237,7 @@ if (outputPdfPath === inputPdfPath) {
|
|
|
226
237
|
}
|
|
227
238
|
|
|
228
239
|
// Usage example
|
|
229
|
-
createBooklet(inputPdfPath, outputPdfPath).catch(
|
|
230
|
-
err(`Error creating booklet: ${
|
|
240
|
+
createBooklet(inputPdfPath, outputPdfPath).catch(e => {
|
|
241
|
+
err(`Error creating booklet: ${e}`);
|
|
231
242
|
});
|
|
232
243
|
|