IronPDF How-Tos TLS Website & System Logins How to Convert HTML to PDF Behind Login Authentication Chaknith Bin Updated:August 14, 2025 The best way to deal with logins is to avoid them if possible and render HTML directly from a file or a string. Get started making PDFs with NuGet now: Install IronPDF with NuGet Package Manager PM > Install-Package IronPdf Copy and run this code snippet. new IronPdf.ChromePdfRenderer { RenderingOptions = new ChromePdfRenderOptions(), LoginCredentials = new IronPdf.ChromeHttpLoginCredentials("username", "password") } .RenderUrlAsPdf("https://example.com/protected-page") .SaveAs("secure.pdf"); Deploy to test on your live environment Start using IronPDF in your project today with a free trial Free 30 day Trial Get started with IronPDF Start using IronPDF in your project today with a free trial. First Step: Start for Free How to Convert HTML to PDF Behind Login Authentication Download the C# IronPDF Library Download the HTML to Avoid Logins Login using Network Authentication with LoginCredentials property Use HTML Form for Authentication Workaround for MVC Login Authentication Best Practices IronPDF supports TLS network authentication (username and password) and .NET web apps can easily support it: ChromeHttpLoginCredentials API The best practice is to use System.Net.WebClient or HttpClient to download the HTML and any assets. This fully supports headers, logins, and everything else you may require. Once downloaded to memory or the disk, IronPDF can turn your HTML into a PDF. Assets such as stylesheets and images can be discovered using the HtmlAgilityPack and then downloaded using the System.Net.WebClient as well. // Download HTML content from a URL string html; using (WebClient client = new WebClient()) { html = client.DownloadString("http://www.google.com"); } // Load the HTML into an HtmlDocument HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); // Iterate through all image nodes and print their src attributes foreach(HtmlNode img in doc.DocumentNode.SelectNodes("//img")) { Console.WriteLine(img.GetAttributeValue("src", null)); } // Download HTML content from a URL string html; using (WebClient client = new WebClient()) { html = client.DownloadString("http://www.google.com"); } // Load the HTML into an HtmlDocument HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); // Iterate through all image nodes and print their src attributes foreach(HtmlNode img in doc.DocumentNode.SelectNodes("//img")) { Console.WriteLine(img.GetAttributeValue("src", null)); } ' Download HTML content from a URL Dim html As String Using client As New WebClient() html = client.DownloadString("http://www.google.com") End Using ' Load the HTML into an HtmlDocument Dim doc As New HtmlDocument() doc.LoadHtml(html) ' Iterate through all image nodes and print their src attributes For Each img As HtmlNode In doc.DocumentNode.SelectNodes("//img") Console.WriteLine(img.GetAttributeValue("src", Nothing)) Next img $vbLabelText $csharpLabel Please noteAny relative Url can be rebased to an absolute url using an overloaded constructor for the System.Uri class. To rebase any relative paths in an entire HTML document, add a <base> tag to the header using HtmlAgilityPack. Example. Login using Network Authentication Most ASP.NET applications support network authentication, which is more reliable than HTML form posting. :path=/static-assets/pdf/content-code-examples/how-to/logins-username-password.cs using IronPdf; using System; ChromePdfRenderer renderer = new ChromePdfRenderer { // setting login credentials to bypass basic authentication LoginCredentials = new ChromeHttpLoginCredentials() { NetworkUsername = "testUser", NetworkPassword = "testPassword" } }; var uri = new Uri("http://localhost:51169/Invoice"); // Render web URL to PDF PdfDocument pdf = renderer.RenderUrlAsPdf(uri); // Export PDF pdf.SaveAs("UrlToPdfExample.Pdf"); Imports IronPdf Imports System Private renderer As New ChromePdfRenderer With { .LoginCredentials = New ChromeHttpLoginCredentials() With { .NetworkUsername = "testUser", .NetworkPassword = "testPassword" } } Private uri = New Uri("http://localhost:51169/Invoice") ' Render web URL to PDF Private pdf As PdfDocument = renderer.RenderUrlAsPdf(uri) ' Export PDF pdf.SaveAs("UrlToPdfExample.Pdf") $vbLabelText $csharpLabel Login using an HTML Form To log in by sending data to an HTML form may also be achieved using the ChromeHttpLoginCredentials class, as in the previous example. See IronPDF's ChromeHttpLoginCredentials API. Please Consider: The login data must be posted to the URL specified in the HTML form's ACTION attribute. This should be set as the *LoginFormUrl* attribute of the HttpLoginCredentials. This may vary from the URL you actually want to render as a PDF. The data to be sent should represent every input and textarea in the HTML form. The name attributes define the name of each variable (not the id, as is commonly misunderstood). Some websites may actively protect against this kind of machine login. MVC The following workaround allows a .NET MVC view to be rendered programmatically to a string, which is very useful in avoiding MVC logins yet rendering a view faithfully. // Converts an MVC partial view to a string public static string RenderPartialViewToString(this Controller controller, string viewPath, object model = null) { try { // Set the model var context = controller.ControllerContext; controller.ViewData.Model = model; using (var sw = new StringWriter()) { // Find the partial view var viewResult = ViewEngines.Engines.FindPartialView(context, viewPath); if (viewResult.View == null) { throw new Exception($"Partial view {viewPath} could not be found."); } // Create a view context var viewContext = new ViewContext(context, viewResult.View, context.Controller.ViewData, context.Controller.TempData, sw); // Render the view viewResult.View.Render(viewContext, sw); viewResult.ViewEngine.ReleaseView(context, viewResult.View); return sw.GetStringBuilder().ToString(); } } catch (Exception ex) { // Return error message if there is an exception return ex.Message; } } // Converts an MVC partial view to a string public static string RenderPartialViewToString(this Controller controller, string viewPath, object model = null) { try { // Set the model var context = controller.ControllerContext; controller.ViewData.Model = model; using (var sw = new StringWriter()) { // Find the partial view var viewResult = ViewEngines.Engines.FindPartialView(context, viewPath); if (viewResult.View == null) { throw new Exception($"Partial view {viewPath} could not be found."); } // Create a view context var viewContext = new ViewContext(context, viewResult.View, context.Controller.ViewData, context.Controller.TempData, sw); // Render the view viewResult.View.Render(viewContext, sw); viewResult.ViewEngine.ReleaseView(context, viewResult.View); return sw.GetStringBuilder().ToString(); } } catch (Exception ex) { // Return error message if there is an exception return ex.Message; } } ' Converts an MVC partial view to a string <System.Runtime.CompilerServices.Extension> _ Public Function RenderPartialViewToString(ByVal controller As Controller, ByVal viewPath As String, Optional ByVal model As Object = Nothing) As String Try ' Set the model Dim context = controller.ControllerContext controller.ViewData.Model = model Using sw = New StringWriter() ' Find the partial view Dim viewResult = ViewEngines.Engines.FindPartialView(context, viewPath) If viewResult.View Is Nothing Then Throw New Exception($"Partial view {viewPath} could not be found.") End If ' Create a view context Dim viewContext As New ViewContext(context, viewResult.View, context.Controller.ViewData, context.Controller.TempData, sw) ' Render the view viewResult.View.Render(viewContext, sw) viewResult.ViewEngine.ReleaseView(context, viewResult.View) Return sw.GetStringBuilder().ToString() End Using Catch ex As Exception ' Return error message if there is an exception Return ex.Message End Try End Function $vbLabelText $csharpLabel Ready to see what else you can do? Check out our tutorial page here: Convert PDFs Frequently Asked Questions How can I convert HTML to PDF without requiring login authentication? To convert HTML to PDF without login authentication, render the HTML directly from a file or a string using IronPDF. This method bypasses the need for authentication entirely. What are the initial steps to convert HTML to PDF in C#? Start by downloading the C# IronPDF Library from NuGet. Once installed, you can use its methods to render HTML documents to PDF directly, even handling scenarios with login authentication. Which tools are recommended for downloading HTML content securely for PDF conversion? Use System.Net.WebClient or HttpClient to download HTML content and assets like stylesheets and images. These tools support headers and logins. HtmlAgilityPack can be used to manage asset discovery and ensure all necessary resources are downloaded. How does IronPDF handle network authentication for converting HTML to PDF? IronPDF supports TLS network authentication with the LoginCredentials property, providing a secure method for handling authentication in ASP.NET applications. Is it possible to perform HTML form authentication using IronPDF? Yes, you can use IronPDF's ChromeHttpLoginCredentials class to handle HTML form authentication. Ensure that the login data is submitted to the correct URL as specified in the form's ACTION attribute. How can I bypass MVC login authentication when converting views to PDF? You can programmatically render an MVC view to a string, which allows you to bypass MVC logins while ensuring accurate rendering of the view. What precautions should be taken when using HTML form authentication for PDF conversion? Ensure that all form inputs and text areas are correctly represented in the posted data using their name attributes. Be aware that some websites may have protections in place to prevent machine logins. Chaknith Bin Chat with engineering team now Software Engineer Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience. Ready to Get Started? Nuget Downloads 15,607,683 | Version: 2025.10 just released Free NuGet Download Total downloads: 15,607,683 View Licenses