|
Rank: Newbie Groups: Member
Joined: 9/18/2018 Posts: 3
|
We have a problem where we are using EO.Pdf to auto-generate some documents. Occasionally, the URL that we are passing to ConvertUrl() will throw an error, and return Response Code 500 (Internal Server Error).
EO.Pdf does not handle these errors correctly and continues to simply generate a PDF of the error text returned by the server, which is not desired behaviour.
Is it possible to have ConvertUrl throw an exception or otherwise catch these HTTP errors so that our application can take the appropriate remedial action, rather than blindly creating a PDF from the error text?
Thanks
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,221
|
Hi, You will need to use HtmlToPdfSession object to have this level of control. See here for sample code on how to use this object: https://www.essentialobjects.com/doc/eo.pdf.htmltopdfsession.runwebviewcallback_overload_1.aspxYou will need to make the following modifications based on the sample code: 1. The sample code uses webView.LoadRequestAndWait to load a Request. You will need to modify that to something like this:
Code: C#
//Load the Url into the WebView
NavigationTask task = webView.LoadUrl(your_url);
//Wait for the load to finish
task.WaitOne();
2. Add code to check the NavigationTask object's HttpStatusCode value and act accordingly. This value is the http status code (such as 500) returned by your server. Note this is not the same as ErrorCode. ErrorCode indicates a real error (such as server not reachable), where as HttpStatusCode indicates the web server has responded properly, even though it may not be the result you wanted. If you want further controls, you may want to familiar yourself with the WebView class: https://www.essentialobjects.com/doc/eo.webbrowser.webview.aspxThis is the core class of our WebBrowser product and is what EO.Pdf uses internally to load and render web pages. Hope this helps. Please feel free to let us know if you still have any questions. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 9/18/2018 Posts: 3
|
Thank you for your response, I have got it working.
I do feel that this should be default behaviour though, I don't imagine that it is often that people would want to create a PDF of an unexpected error page.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,221
|
Thank you very much for your feedback. We will look into this and see what we can do.
|
|
Rank: Newbie Groups: Member
Joined: 9/18/2018 Posts: 3
|
As a followup to this, is there a way to add data to the request body? I can't seem to find an overload or method on WebView that will allow me to do this, other than LoadRequest() which takes a request, but only allows me to add form data (we need to post Json to the URL).
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,221
|
Hi, Have you tried something like this:
Code: C#
request.PostData.Add(new PostData(your_binary_post_data));
You will need to covert your JSON into a byte array first and also need to set the request's ContentType and ContentEncoding properly. Thanks!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,221
|
Hi, This is just to let you know that we have posted a new build that added this property: https://www.essentialobjects.com/doc/eo.pdf.htmltopdfoptions.throwonhttperror.aspxTo maintain backwards compatibility, this property is false by default. To achieve the behavior you wanted, you would need to set this property to true. You can download the new build from our download page. Please take a look and let us know how it goes. Thanks!
|
|