Welcome Guest Search | Active Topics | Sign In | Register

Offline mode for HtmlToPdf.ConvertHtml? Options
George Harpur
Posted: Thursday, March 22, 2018 11:21:29 AM
Rank: Newbie
Groups: Member

Joined: 3/19/2018
Posts: 6
Is there any way to put ConvertHtml into an offline (local only) mode? I am processing archived HTML (typically email bodies) and do not want to follow links for two reasons:

1) potential security issues
2) in many cases the links will now be dead, so attempting to retrieve them could result in lengthy time-outs

I'd like to convert the HTML as quickly as possible, and with no attempt being made at network access.

Is this possible?

Thanks!
eo_support
Posted: Thursday, March 22, 2018 3:45:47 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,221
Hi,

There is no built-in option for you to disable network access. However it is possible for you to use a custom resource handler to intercept those requests and then immediately returns an error (for example, you can return 404 not found for all network requests) to prevent it from actually accessing the network. You will need to use this method to do so:

https://www.essentialobjects.com/doc/eo.pdf.htmltopdfsession.runwebviewcallback.aspx

Also you will need to go over this topic if you are not familiar with custom resource handler:

https://www.essentialobjects.com/doc/webbrowser/advanced/resource_handler.aspx

The code would be something like this:

Code: C#
//Here NoNetworkAccessHandler is a custom resource handler you
//would implement yourself that would return an error for all HTTP/HTTPS
//request
NoNetworkAccessHandler handler = new NoNetworkAccessHandler();

//Register your custom handler
session.RunWebViewCallback((WebView webView, object args) =>
    {
        webView.RegisterResourceHandler(handler);
    });

//Perform the conversion
session.RenderAsPDF(resultPDFFileName);

//Unregister the handler
session.RunWebViewCallback((WebView webView, object args) =>
    {
        webView.UnregisterResourceHandler(handler);
    });


Hope this helps. Please feel free to let us know if you still have any questions.

Thanks!
George Harpur
Posted: Friday, March 23, 2018 2:50:21 PM
Rank: Newbie
Groups: Member

Joined: 3/19/2018
Posts: 6
That worked like a charm (I just needed to modify your WebViewCallback delegate to return null).

Thanks for your prompt and helpful support!
eo_support
Posted: Friday, March 23, 2018 4:14:50 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,221
Ah yes. The callback needs to return null. Sorry about the overlook. Glad to hear that it works for you and thanks for the update!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.