HTTP Request Header
This code demonstrates how to use HTTP request headers in IronPDF to render a PDF from an authenticated webpage. It begins by creating an instance of ChromePdfRenderer, which is responsible for converting web pages or HTML into PDFs. Next, it sets up HTTP request headers by assigning a dictionary to the HttpRequestHeaders property within RenderingOptions. In this case, an Authorization header is added with a Bearer token (test-token-123), which is commonly used for authentication in APIs.
Once the headers are set, the RenderUrlAsPdf
method is used to fetch and convert the webpage at https://httpbin.org/bearer into a PDF. This particular URL is a test API that requires Bearer authentication, making it a useful way to verify that the header is being correctly sent. Finally, the resulting PDF file is saved as "output.pdf" in the current directory. This approach is beneficial for generating PDFs from authenticated web pages, such as protected reports, dashboards, or API-generated content.