Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

FAILED: ReferenceError: html2pdf is not defined with Blazor

$
0
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>

Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>