【问题标题】:How to compress a pdf with node?如何用节点压缩pdf?
【发布时间】:2017-09-29 09:39:18
【问题描述】:

我找到了:

他们都依赖PDFTk,费用约为 1,000 美元。

我在哪里可以了解更多关于使用 node 压缩 pdf 的信息,或者找到已经制作的库?

【问题讨论】:

    标签: node.js pdf compression


    【解决方案1】:

    尝试使用shrinkpdf 压缩您的pdf文件

    还有这个帖子:How to run shell script file using nodejs?

    【讨论】:

    • 是的,这完美地解决了问题,我宁愿我们的节点开发人员使用 shell 脚本来完成诸如基本 CLI 命令之类的任务。虽然当你有测试用例时会更好,但省去了重复输入命令的麻烦。
    【解决方案2】:

    使用ghostscript4js

    gs.executeSync('gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=out.pdf in.pdf')

    请参阅this answer 了解各种选项。

    需要在主机系统上安装 ghostscript。

    【讨论】:

      【解决方案3】:

      这可以通过ConvertAPI NodeJS library 轻松实现:

      var convertapi = require('convertapi')('<YOUR SECRET HERE>');
      convertapi.convert('compress', {
      File: '/path/to/my_file.pdf'
      }, 'pdf').then(function(result) {
           result.saveFiles('/path/to/dir');
      });
      

      可以通过指定image compression algorithms 和质量来调整压缩级别。您还可以从 PDF 中remove redundant objects 包括字体、书签、注释、表单、页面标签、文章线程、标记信息、页面缩略图、图层、副本、Adobe Illustrator 或 Photoshop 私人数据等片段信息字典等。

      您可以在此处找到完整的压缩参数列表:https://www.convertapi.com/pdf-to-compressbottom of the page 上的自动生成代码 sn-p。

      免责声明:我为图书馆的供应商工作。

      【讨论】:

        猜你喜欢
        • 2012-03-14
        • 1970-01-01
        • 2022-10-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-07-05
        • 2011-07-06
        相关资源
        最近更新 更多