Custom error handling when loading PDFs

Skip to first unread message

Mirko Lugano

Jan 14, 2021, 8:15:48 PM1/14/21
to PDFTron WebViewer
Hi I'm using (still) WebViewer 5.1.0. Is there a way to custom handle errors occurring when loading pdfs? For instance, I have a .png file which I renamed to .pdf, thus making it an "invalid pdf". When I try to load it with the webViewer I get an error in the console (which is correct): "Uncaught (in promise) PDF header not found. The file is not a valid PDF document."
I would like to be able to intercept such errors and execute my own callback if possible.
I have added 
$(document).on('error', function(e) { //some code })
$(window).on('error', function(e) { //some code })  
in my config.js file but none of that works. Is there a chance to set a custom callback?
Best regards

Sardor Isakov

Jan 18, 2021, 2:26:37 PM1/18/21
to PDFTron WebViewer

Would you be able to try this approach? Here:

window.addEventListener('loaderror', function(error) {
  var error = error.detail?.message || error.detail || error.message;
  console.log("Error occured: ", error);//or any message

Best Regards,
Sardor Isakov
Software Developer
PDFTron Systems, Inc.
Reply all
Reply to author
0 new messages