Skip to content

Commit 3eb813b

Browse files
committed
Update pvcep_pdf_addon.user.js
1 parent 35a47f0 commit 3eb813b

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

Picviewer CE+/pvcep_pdf_addon.user.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// @name:zh-CN Picviewer CE+ PDF 扩展
44
// @name:zh-TW Picviewer CE+ PDF 擴充
55
// @namespace https://github.com/hoothin/UserScripts
6-
// @version 2024-06-23
6+
// @version 2024-06-29
77
// @description Batch Download as PDF instead of ZIP
88
// @description:zh-CN 取代 ZIP, 打包下载时下载为 PDF
99
// @description:zh-TW 取代 ZIP, 打包下載時下載為 PDF
@@ -56,9 +56,22 @@
5656
try {
5757
let dataUrl = await blobToDataURL(blob);
5858
const imgProps = pdf.getImageProperties(dataUrl);
59-
const pdfWidth = pdf.internal.pageSize.getWidth();
60-
const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width;
61-
pdf.addImage(dataUrl, blob.type, 0, 0, pdfWidth, pdfHeight);
59+
const imgWidth = pdf.internal.pageSize.getWidth();
60+
const pageHeight = pdf.internal.pageSize.getHeight();
61+
const imgHeight = imgProps.height * imgWidth / imgProps.width;
62+
let heightLeft = imgHeight;
63+
let position = 0;
64+
65+
pdf.addImage(dataUrl, blob.type, 0, position, imgWidth, imgHeight);
66+
heightLeft -= pageHeight;
67+
68+
while (heightLeft >= 0) {
69+
position -= pageHeight;
70+
pdf.addPage();
71+
pdf.addImage(dataUrl, blob.type, 0, position, imgWidth, imgHeight);
72+
heightLeft -= pageHeight;
73+
}
74+
6275
progress({percent: (key + 1) / fileLength * 100, currentFile: fileName});
6376
} catch(e) {
6477
console.log(e);

0 commit comments

Comments
 (0)