TLS Website & System Logins
Most ASP.NET applications support network authentication, a more reliable method than HTML form posting, and with IronPDF, you can be assured that TLS network authentication is fully supported. This means you can work within secure, .NET web app-supported environments.
Take this code, for example, we use IronPDF's powerful Chromium-based rendering engine to render the web page as if it were being viewed in a browser, wherein the headers and footers are dynamically generated and added to the pages. Then, margins and styles are applied accordingly before the result is saved as a professional-looking PDF.
Steps for Rendering PDFs with TLS Website and System Logins
// Define the web page URL to render
var uri = new Uri("http://localhost:51169/Invoice");
// Create a new instance of ChromePdfRenderer
var renderer = new ChromePdfRenderer();
// Set rendering options including margins and media type
renderer.RenderingOptions = new ChromePdfRenderOptions
{
CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print // Apply print-specific styles
};
// Create login credentials if the URL requires basic authentication
renderer.LoginCredentials = new IronPdf.ChromeHttpLoginCredentials
{
Username = "your-username",
Password = "your-password"
};
// Render the URL as a PDF
IronPdf.PdfDocument pdf = renderer.RenderUrlAsPdf(uri);
// Save the PDF to a file in the current directory
pdf.SaveAs(Path.Combine(Directory.GetCurrentDirectory(), "UrlToPdfExample2.Pdf"));
// Define the web page URL to render
var uri = new Uri("http://localhost:51169/Invoice");
// Create a new instance of ChromePdfRenderer
var renderer = new ChromePdfRenderer();
// Set rendering options including margins and media type
renderer.RenderingOptions = new ChromePdfRenderOptions
{
CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print // Apply print-specific styles
};
// Create login credentials if the URL requires basic authentication
renderer.LoginCredentials = new IronPdf.ChromeHttpLoginCredentials
{
Username = "your-username",
Password = "your-password"
};
// Render the URL as a PDF
IronPdf.PdfDocument pdf = renderer.RenderUrlAsPdf(uri);
// Save the PDF to a file in the current directory
pdf.SaveAs(Path.Combine(Directory.GetCurrentDirectory(), "UrlToPdfExample2.Pdf"));
' Define the web page URL to render
Dim uri As New Uri("http://localhost:51169/Invoice")
' Create a new instance of ChromePdfRenderer
Dim renderer = New ChromePdfRenderer()
' Set rendering options including margins and media type
renderer.RenderingOptions = New ChromePdfRenderOptions With {.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print}
' Create login credentials if the URL requires basic authentication
renderer.LoginCredentials = New IronPdf.ChromeHttpLoginCredentials With {
.Username = "your-username",
.Password = "your-password"
}
' Render the URL as a PDF
Dim pdf As IronPdf.PdfDocument = renderer.RenderUrlAsPdf(uri)
' Save the PDF to a file in the current directory
pdf.SaveAs(Path.Combine(Directory.GetCurrentDirectory(), "UrlToPdfExample2.Pdf"))
Explanation
Define the Web Page URL:
- The first step in this process is to define the web page URL. We create a new
uri
object representing the URL of the web page we want to render as a PDF. In this example, the page is hosted locally at"http://localhost:51169/Invoice"
.
- The first step in this process is to define the web page URL. We create a new
Create the PDF Renderer:
- Create a new instance of
ChromePdfRenderer
, which handles the conversion of web pages to PDF using its powerful conversion features.
- Create a new instance of
Set Rendering Options:
- Use the
RenderingOptions
property to configure the rendering options. Custom margins and media type for printing styles (IronPdf.Rendering.PdfCssMediaType.Print
) are demonstrated here.
- Use the
Set Login Credentials:
- Configure
LoginCredentials
if the URL requires basic authentication. Here, placeholders forUsername
andPassword
are provided.
- Configure
Render the URL as a PDF:
- Use the
RenderUrlAsPdf
method to open the givenuri
within a headless Chromium browser and convert the web page into a PDF using the specified rendering options.
- Use the
- Save the PDF:
- Finally, save the PDF using the
SaveAs
method to the current working directory with the filename"UrlToPdfExample2.Pdf"
.
- Finally, save the PDF using the
Click here to view the How-to Guide, including examples, sample code, and files