如何在 pdfkit 中使用 'cover' 选项?

How to use 'cover' option in pdfkit?

我正在尝试制作一个包含图像列表的 pdf 文件,每页一张图像。图像应覆盖整个页面且不应被裁剪。我不想使用 fit 选项,因为我必须提供 widthheight,这会很麻烦。所以我想我应该使用 cover 选项,但我似乎无法弄清楚如何使用它。我也无法在互联网上找到解决方案。甚至它的 documentation 也没有提到如何使用它。我尝试了一些随机代码,如下所示:

doc.image('path/to/image.png', {
  cover: true
});

但运气不好。它显示以下错误:

(node:9004) UnhandledPromiseRejectionWarning: TypeError: options.cover is not iterable
    at PDFDocument.image (/var/www/html/Custom Manga Downloader/node_modules/pdfkit/js/pdfkit.js:4487:26)
    at Object.run (/var/www/html/Custom Manga Downloader/downloaders/holymanga.net/index.mjs:21:7)
    at __holymanga (/var/www/html/Custom Manga Downloader/server.js:36:13)
    at Object.<anonymous> (/var/www/html/Custom Manga Downloader/server.js:42:19)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)

拜托,我们将不胜感激。

谢谢你:)

文档页面说:

cover array provided - image is scaled proportionally to completely cover the rectangle defined by the passed width and height.

所以,它实际上需要一个 [width, height] 的数组而不是 boolean。为它提供一个数组,它会工作得很好。

这是我正在使用的片段:

doc.image(`${url}-screenshot.png`, {
        cover: [doc.page.width - 100, doc.page.height - 300]
    });

干杯!