#How to properly load html2pdf.js lib?

24 messages · Page 1 of 1 (latest)

ivory juniper
#

I just imported this lib and using it, it works but in the console i get this error. I tried dynamic import but that caused other issues before

import html2pdf from "html2pdf.js";

  const downloadPdf = async () => {
    let content = document.getElementById("invoice");

    html2pdf(content, {
      filename: `${invoiceData.invoiceNo}.pdf`,
      image: { type: "jpeg", quality: 1 },
      html2canvas: { scale: 2 },
    }).save();
  };

whats the proper way to load this library

cloud lakeBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

mint pivot
#

You have internal server error, check your vscode terminal

gaunt hornet
#

The console is throwing an error for the /login route, but your code has no mention of that route.

ivory juniper
#

i fixed the issue by importing the modal which has html2pdf by next- dynamic

#
  • ssr false
cloud lakeBOT
mint pivot
#

I am 99% sure that it wasn't the root cause

mint pivot
#

show me the whole codebase of InvoiceModal

#

@ivory juniper

ivory juniper
mint pivot
#

I know, show me the full codebase

#

when do you call downloadPdf function?

ivory juniper
mint pivot
#

🤦‍♂️

#

the full codebase not the function

#

when do you call downloadPdf function?

ivory juniper
#

on btn click

mint pivot
#

although next/dynamic with ssr: false fixed your issue but it wasn't due to downloadPdf() if it's called on button click

ivory juniper