Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

130
Vistas
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');
      });

7 months ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

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")
  });
7 months ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos