html2pdf js not prompting download


I am using html2pdf.js inside of my projet:

My issue, is that I do everything like inside of the tutorial and it does not prompt the download for my div :'(

Here is my code:

$(document).ready(() => {
    $("#download-btn").click(() => {

function generatePDF() {
    const element = document.getElementById("pdf-content");

    const opt = {
        filename: "methodo.pdf",
        image: { type: "jpeg", quality: 0.85 },
        html2canvas: {
            scale: 5,
            logging: true,
            letterRendering: true,
            useCORS: true,
        jsPDF: {
            unit: "in",
            format: "letter",
            orientation: "portrait",

    // Promise-based usage:
.row {
    display: flex;

.column {
    flex: 50%;

#header {
    display: flex;
    align-items: center;
    height: 150px;

#header img {
    height: 100%;
    width: auto;
    margin-left: 15px;

#download-btn {
    margin: 0 auto;
    display: block;

#pdf-content {
    margin: 5% 5% 15%;
    border-style: solid;
    border-color: lightgray;
    border-width: 2px;

#header h2 {
    flex: 75%;
    text-align: center;
<script src=""></script>
<script src=""></script>
<div class="row">
  <div class="column">
  <div class="column">
    <div id="pdf-content">
      <div id="header">
        <img src="" alt="logo">
        <h2>Fiche Méthodo</h2>
  <button id="download-btn">Download</button>

There are some console messages that are printed but the pdf does not start to download 🙁

The weird thing, is that if I do something like: html2pdf("Hello World"); It downloads me a pdf with written "hello world" on it. But in my case it does not prompt any download

I hope that someone can help me with that 🙂


My issue came from the fact that for some reason, the lib does not prompt download when you put a local image inside of the pdf generated.

I had img/image.png inside of my pdf-content that is why it was not working.

Answered By – Lockface

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published