0

I use html2pdf.bundle.min.js in my Blazor project. I imported it in my main html of the project, before the main.js. In the network tab in the browser, I see that the html2pdf.bundle.min.js is sent with status code 200. But when I want to call the html2pdf function inside another javascript function, i get 'FAILED: ReferenceError: html2pdf is not defined' in my browsers console. Any idea why? The code already exists in an older version of the same project, and there it still works. Here the function where I call the html2pdf. This function gets called successfully, but then it throws an exception because it cannot find html2pdf:

function printDiv(divName) { let element = document.getElementById(divName); let clone = document.getElementById("clone"); try { let opt = { margin: 0, filename: 'myfile.pdf', image: { type: 'jpeg', quality: 0.98 }, html2canvas: { scale: 1, clone: clone, removeContainer: true }, jsPDF: { unit: 'mm', format: 'a4', clone: clone, orientation: 'landscape' } }; html2pdf().set(opt).from(element).toContainer().save(); } catch (e) { console.error("FAILED:", e); } } 

And the App.razor where I add my scripts and stylesheets:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <base href="/" /> <link rel="stylesheet" href="@Assets["app.css"]" /> <link rel="stylesheet" href="@Assets["/css/styles.css"]" /> <ImportMap @rendermode="InteractiveServer" /> <link rel="icon" type="image/png" href="/Assets/logo.png" /> <HeadOutlet @rendermode="InteractiveServer" /> </head> <body style="height:100dvh;width:100dvw"> <Routes @rendermode="InteractiveServer" /> <script src="_framework/blazor.web.js"></script> <script src="_content/MudBlazor/MudBlazor.min.js"></script> <script src="_content/MudBlazor.Markdown/MudBlazor.Markdown.min.js"></script> <script src="_content/Radzen.Blazor/Radzen.Blazor.js?v=@(typeof(Radzen.Colors).Assembly.GetName().Version)"></script> <script src="js/html2pdf.bundle.min.js"></script> <script src="js/main.js?v=1.0.0.9"></script> </body> </html> 
2
  • In the jsPDF options object (opt / jsPDF), there is a missing coma after clone: clone... I know this does not fit the error message you are getting... But sometimes, those messages are misleading. Commented May 27 at 13:23
  • @LouysPatriceBessette thx for your answer, unfortunately this was just a copy-paste error I am sorry.. Commented May 27 at 13:26

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.