简体   繁体   English

如何防止 HTML2PDF 自动下载 pdf?

[英]How do I prevent HTML2PDF from auto-downloading the pdf?

I have a HTML2PDF method in my JavaScript code.我的 JavaScript 代码中有一个 HTML2PDF 方法。 The code is working great on one hand as I can open the rendered pdf in a new blob tab and open the print window.一方面代码运行良好,因为我可以在新的 blob 选项卡中打开呈现的 pdf 并打开打印窗口。 However, as I do that, the pdf automatically downloads as well.但是,当我这样做时,pdf也会自动下载。 I wish to prevent the method from downloading the .pdf file and only open the print window in the new tab.我希望阻止该方法下载 .pdf 文件,只在新选项卡中打开打印窗口。 The following code is what I have.以下代码是我所拥有的。 Any help would be greatly appreciated!任何帮助将不胜感激!

    html2pdf(body, {
      filename: 'test.pdf',
      jsPDF: {
          orientation: 'portrait',
        }
    })
      .from('element-to-print')
      .get('pdf')
      .then(function (pdfObj) {
        pdfObj.autoPrint();
        window.open(pdfObj.output('bloburl'), 'F');
      });

Try this code :试试这个代码:

html2pdf() // move your config in the .set({...}) function below
  .set({
    filename: 'test.pdf',
    jsPDF: {
      orientation: 'portrait',
    }
  })
  .from('element-to-print')
  .outputPdf()  // add this to replace implicite .save() method, which triggers file download
  .get('pdf')
  .then(function (pdfObj) {
    pdfObj.autoPrint();
    window.open(pdfObj.output("bloburl"), "F")
  });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM