【问题标题】:Convert html into PDF and put the converted PDFs into the zip file in javascript将html转换为PDF并将转换后的PDF放入javascript中的zip文件中
【发布时间】:2018-08-06 17:46:16
【问题描述】:

我必须使用 HTML 创建 pdf 文件,创建 PDF 后,需要将这些文件包含在 zip 中。因此,当用户单击它时,基本上会有一个下载按钮。 zip 文件将被下载,并且 zip 包含所有转换后的文件。

有没有办法在js中实现上述功能?我正在使用 react 和 meteor 来创建 Web 应用程序。

【问题讨论】:

    标签: javascript reactjs meteor


    【解决方案1】:

    第一步,将HTML转换为PDF文件,可以使用:

    dom-to-image 的示例。

    function generatePdf() {
      // get DOM element
      const node = document.getElementById('elementId');
      // generate the png from a DOM element
      domtoimage.toPng(node)
      .then((dataUrl) => {
        // generate the PDF
        const pdf = new jsPDF();
        // define max width and max height of the document
        const width = pdf.internal.pageSize.width;
        const height = pdf.internal.pageSize.height;
        // add the png in the PDF (fix the width and the height)
        pdf.addImage(dataUrl, 'PNG', 0, 0, width, height);
        // display the pdf in another tab
        window.open(pdf.output('bloburl'), '_blank');
      })
      .catch((error) => {
        console.error('oops, something went wrong!', error);
      });
    }
    

    对于第二步,我从不这样做。我帮不了你。

    【讨论】:

      猜你喜欢
      • 2018-06-03
      • 2013-07-10
      • 1970-01-01
      • 1970-01-01
      • 2012-02-11
      • 2011-09-02
      • 2010-12-31
      相关资源
      最近更新 更多