document error handling and custom messages

399 views
Skip to first unread message

Perry Manole

unread,
Mar 6, 2014, 7:03:38 AM3/6/14
to pdfnet-w...@googlegroups.com
If my PDF to XOD conversion fails for some reason (e.g. corrupt PDF or whatever else) the viewer spits out a java script error when trying to load it. Is there no way to gracefully handle a document load failure? Same for loading the annotation file.

Similarly how do I customize the annotation load/save popup with messages of my own. (e.g. missing XFDF file during GET, save errors during POST, etc.)?

Perry Manole

unread,
Mar 11, 2014, 7:20:56 PM3/11/14
to pdfnet-w...@googlegroups.com
What I want to do is if there is an error retrieving the file (XOD or XDFD annot). from my data store, I want to return an XML document containing the error details instead of the actual requested XOD or annotation file which should be parsed on the client and shown to the user. In other words I am concerned about capturing the error that occurred on the server side not on the client side for presentation. So on the client side this would not be an error but the returned content type should be checked and if "text/xml", don't attempt to load the document but instead show the parsed error. Where do I intercept this? And is there a way to modify the java script code in a way that is apart from the library folder so that future updates could be done with a "lib" folder replacement without affecting my changes?
On Thursday, March 6, 2014 12:49:54 PM UTC-8, Matt Parizeau wrote:
To be able to handle errors from document load failures you can set a callback on the part retriever object in ReaderControl.js.  Look for the loadDocument function and near the bottom, just before the line this.docViewer.LoadAsync(...) add the following:
partRetriever.SetErrorCallback(function(err) {
   
// show some error message
});

This will be called if there is an error while initially loading the document or if there is an error while trying to download a part of the file.  One thing to note is that for documents without any bookmarks this callback will be triggered for the DocStruct.struct file but this can be safely ignored.

To customize the behavior with annotations you can look at the $.ajax call in onDocumentLoaded for loading annotations and the saveAnnotations function for saving annotations.  There are success and error callbacks for the $.ajax calls and you can modify these as you like.

Matt Parizeau
Software Developer
PDFTron Systems Inc.

Matt Parizeau

unread,
Mar 11, 2014, 9:14:04 PM3/11/14
to pdfnet-w...@googlegroups.com
To make changes separate from the library folder you would want to use config files with your customizations.  You can see how this is done by looking at the WebViewer samples.  Unfortunately at the current time there isn't a way to set the error callback easily from a config file.  We plan to improve this for the next version so that an event will be emitted when there is an error and you can handle this in your config file or from the JavaScript code that creates the WebViewer object.

It is possible to hook into the document loading to check the content type yourself.  You could have code like the following in a config file:
$(document).on('viewerLoaded', function() {
   
var originalLoadDocument = readerControl.loadDocument;

    readerControl
.loadDocument = function(doc) {
       
if (myXMLTestingFunction(doc)) {
            console
.log("show error");
       
} else {
            originalLoadDocument
.apply(this, arguments);
       
}
   
};
});

Matt Parizeau
Software Developer
PDFTron Systems Inc.

Matt Parizeau

unread,
May 11, 2018, 2:55:56 PM5/11/18
to pdfnet-w...@googlegroups.com
To be able to handle errors from document load failures you can set a callback on the part retriever object in ReaderControl.js.  Look for the loadDocument function and near the bottom, just before the line this.docViewer.LoadAsync(...) add the following:
partRetriever.setErrorCallback(function(err) {

   
// show some error message
});

This will be called if there is an error while initially loading the document or if there is an error while trying to download a part of the file.  One thing to note is that for documents without any bookmarks this callback will be triggered for the DocStruct.struct file but this can be safely ignored.

To customize the behavior with annotations you can look at the $.ajax call in onDocumentLoaded for loading annotations and the saveAnnotations function for saving annotations.  There are success and error callbacks for the $.ajax calls and you can modify these as you like.

Matt Parizeau
Software Developer
PDFTron Systems Inc.

On Thursday, March 6, 2014 4:03:38 AM UTC-8, Perry Manole wrote:
Reply all
Reply to author
Forward
0 new messages