Convert HTML through a Proxy Server

EVO HTML to PDF Converter can load the HTML page and its resources through a HTTP or a SOCKS5 proxy server. The proxy is configured with the ProxyOptions object exposed by the HtmlToPdfConverterProxyOptions property. By default no proxy is set and the network settings of the system are used.

The same options are exposed by the HtmlToImageConverterProxyOptions property of the HTML to Image converter. The HTML headers, footers and stamps rendered during a conversion are loaded through the proxy of the converter.

Proxy Options

  • Type. The Type property selects a NetworkProxyTypeHttp or a NetworkProxyTypeSocks5 proxy. The default value NetworkProxyTypeNone means that no proxy is used.

  • Address. The HostName property is the host name or the IP address of the proxy server and PortNumber is its port. The proxy is used only when the type is not None and a host name is set.

  • Credentials. The Username and Password properties are sent when a HTTP proxy requires authentication.

  • Bypassed Hosts. The BypassedHosts array lists the hosts accessed directly, without the proxy. An entry can be a host name, an IP address, a domain with its subdomains ("*.example.com") or a CIDR range ("10.0.0.0/8"). The local machine is always accessed directly.

Code Sample - Convert HTML through a Proxy Server

C#
// Use EVO PDF Namespace
using EvoPdf.Next;

public byte[] ConvertHtmlThroughProxy(string url, string proxyHostName, int proxyPortNumber,
    string proxyUsername, string proxyPassword, string[] bypassedHosts)
{
    // Set the license key received after purchase to use the library in licensed mode; leave it commented for demo mode
    // Licensing.LicenseKey = "your-license-key";

    // Create a HTML to PDF converter object with default settings
    HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter();

    // The type of the proxy used to load the HTML page and its resources. With the None type
    // the network settings of the system are used, as when no proxy is configured
    htmlToPdfConverter.ProxyOptions.Type = NetworkProxyType.Http;

    // The address of the proxy server
    htmlToPdfConverter.ProxyOptions.HostName = proxyHostName;
    htmlToPdfConverter.ProxyOptions.PortNumber = proxyPortNumber;

    // The credentials for a proxy which requires authentication
    if (!string.IsNullOrEmpty(proxyUsername))
    {
        htmlToPdfConverter.ProxyOptions.Username = proxyUsername;
        htmlToPdfConverter.ProxyOptions.Password = proxyPassword;
    }

    // The hosts accessed directly, without the proxy: host names, IP addresses, domains with
    // their subdomains (*.example.com) or CIDR ranges (10.0.0.0/8). The local machine is
    // always accessed directly
    if (bypassedHosts != null)
        htmlToPdfConverter.ProxyOptions.BypassedHosts = bypassedHosts;

    // The same proxy options are available in the HTML to image converter

    // Convert the HTML page to a PDF document in a memory buffer
    byte[] outPdfBuffer = htmlToPdfConverter.ConvertUrl(url);

    return outPdfBuffer;
}

See Also