'How do I prevent HTML2PDF from auto-downloading the pdf?

I have a HTML2PDF method in my JavaScript code. 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. However, as I do that, the pdf automatically downloads as well. I wish to prevent the method from downloading the .pdf file and only open the print window in the new tab. 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');
      });



Solution 1:[1]

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")
  });

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 cooow