HiQPdf Documentation

Add HTTP Headers when Accessing Web Page

Quickly Create High Quality PDFs

The HiQPdf HTML Converters and the HTML Objects can be configured to transmit a set of custom HTTP headers to web server when requesting the web page to convert. For example, the HTTP headers to be transmitted to web server are added to the HttpHeaders collection of the HiQPdf.HtmlToPdf object using the HttpHeadersCollectionAddRequestHeader(String, String) method which takes as parameter the HTTP header name and the HTTP header value. Adding custom HTTP headers to a request can have interesting applications. Below we exemplify two usage scenarios of the custom HTTP headers.

Examples

The User-Agent HTTP header can be used to inform the web server about the identity of the agent requesting the page. The web server can return a different content based on the received user agent:

C#
// create the HTML to PDF converter
HtmlToPdf htmlToPdfConverter = new HtmlToPdf();

// set the User-Agent HTTP header
htmlToPdfConverter.HttpHeaders.AddRequestHeader("User-Agent", "Custom User Agent");

The Accept-Language HTTP header can be used to inform the web server about the culture of the agent requesting the page. The web server can return a different content based on the declared culture. In the example below the culture is set to Swedish and when you convert a web page like www.google.com the page content will be in Swedish:

C#
// create the HTML to PDF converter
HtmlToPdf htmlToPdfConverter = new HtmlToPdf();

// set the browser culture
htmlToPdfConverter.HttpHeaders.AddRequestHeader("Accept-Language", "sv-SE");
See Also

Other Resources