|
3 | 3 | // @name:zh-CN Picviewer CE+ PDF 扩展
|
4 | 4 | // @name:zh-TW Picviewer CE+ PDF 擴充
|
5 | 5 | // @namespace https://github.com/hoothin/UserScripts
|
6 |
| -// @version 2024-06-23 |
| 6 | +// @version 2024-06-29 |
7 | 7 | // @description Batch Download as PDF instead of ZIP
|
8 | 8 | // @description:zh-CN 取代 ZIP, 打包下载时下载为 PDF
|
9 | 9 | // @description:zh-TW 取代 ZIP, 打包下載時下載為 PDF
|
|
56 | 56 | try {
|
57 | 57 | let dataUrl = await blobToDataURL(blob);
|
58 | 58 | 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 | + |
62 | 75 | progress({percent: (key + 1) / fileLength * 100, currentFile: fileName});
|
63 | 76 | } catch(e) {
|
64 | 77 | console.log(e);
|
|
0 commit comments