IronPDF How-Tos How to Render HTML String into PDF How to Convert HTML String to PDF in C# Regan Pun Updated:July 28, 2025 IronPDF allows developers to create PDF documents easily in C#, F#, and VB.NET for .NET Core and .NET Framework. IronPdf supports rendering any HTML string into a PDF, and the rendering process is undertaken by a fully functional version of the Google Chromium engine. Get started making PDFs with NuGet now: Install IronPDF with NuGet PM > Install-Package IronPdf Copy the code IronPdf.ChromePdfRender .StaticRenderHtmlAsPdf("<p>Hello Word</p>") .SaveAs("string-to-pdf.pdf"); Deploy to test on your live environment Start using IronPDF in your project today with a free trial Free 30 day Trial How to Render HTML String to PDF Download IronPDF C# Library from NuGet Instantiate the PDF Renderer and Pass the HTML String Configure BasePath for External Assets in PDF Configure the RenderingOptions to fine-tune the output PDF Save and Download the Generated PDF HTML String to PDF Example Here we have an example of IronPDF rendering an HTML string into a PDF by using the RenderHtmlAsPdf method. The parameter is an HTML string to be rendered as a PDF. :path=/static-assets/pdf/content-code-examples/how-to/html-string-to-pdf.cs using IronPdf; // Instantiate Renderer var renderer = new ChromePdfRenderer(); // Create a PDF from a HTML string using C# var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>"); // Export to a file or Stream pdf.SaveAs("output.pdf"); Imports IronPdf ' Instantiate Renderer Private renderer = New ChromePdfRenderer() ' Create a PDF from a HTML string using C# Private pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>") ' Export to a file or Stream pdf.SaveAs("output.pdf") $vbLabelText $csharpLabel The RenderHtmlAsPdf method returns a PdfDocument object, which is a class used to hold PDF information. In cases where an HTML string is obtained from an external source, and disabling local disk access or cross-origin requests is desired, the ChromePdfRenderer.EnableWebSecurity property can be set to true to achieve that. Result This is the file that the code produced: Advanced HTML to PDF Example Here we have an example of IronPDF loading an external image asset from an optional BasePath. Setting the BaseUrlOrPath property gives the relative file path or URL context for hyperlinks, images, CSS, and JavaScript files. :path=/static-assets/pdf/content-code-examples/how-to/html-string-to-pdf-2.cs using IronPdf; // Instantiate Renderer var renderer = new ChromePdfRenderer(); // Advanced Example with HTML Assets // Load external html assets: Images, CSS and JavaScript. // An optional BasePath 'C:\site\assets\' is set as the file location to load assets from var myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"C:\site\assets\"); myAdvancedPdf.SaveAs("html-with-assets.pdf"); Imports IronPdf ' Instantiate Renderer Private renderer = New ChromePdfRenderer() ' Advanced Example with HTML Assets ' Load external html assets: Images, CSS and JavaScript. ' An optional BasePath 'C:\site\assets\' is set as the file location to load assets from Private myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", "C:\site\assets\") myAdvancedPdf.SaveAs("html-with-assets.pdf") $vbLabelText $csharpLabel This is the file that the code produced: Frequently Asked Questions How do I convert an HTML string to a PDF document in C#? To convert an HTML string to a PDF in C#, you can use IronPDF's StaticRenderHtmlAsPdf method from the IronPdf.ChromePdfRender class. This method takes an HTML string, renders it as a PDF, and allows you to save it as a file. What steps are involved in rendering an HTML string to PDF? The steps to render an HTML string to PDF using IronPDF include downloading the IronPDF library from NuGet, instantiating the PDF renderer, passing the HTML string, configuring rendering options like BasePath for external assets, and saving the generated PDF. Can I include external images and CSS in the PDF? Yes, IronPDF allows you to include external images and CSS in your PDF by setting the BaseUrlOrPath property. This property provides a context for loading resources such as images, CSS, and JavaScript files when rendering HTML to PDF. How can I improve the security when rendering HTML from external sources? To enhance security when rendering HTML from external sources, you can set the ChromePdfRenderer.EnableWebSecurity property to true in IronPDF. This disables local disk access and cross-origin requests. What is the purpose of setting the BaseUrlOrPath property in IronPDF? The BaseUrlOrPath property in IronPDF is used to define the base path or URL context for loading external resources like images, CSS, and JavaScript files. It ensures these resources are correctly referenced when rendering HTML to PDF. What is the method used to save a rendered PDF in IronPDF? After rendering an HTML string to PDF using IronPDF, you can save the PDF by calling the SaveAs method on the PdfDocument object, specifying the desired file path. Where can I download the IronPDF library? You can download the IronPDF C# library from NuGet. To do this, visit the NuGet website and search for IronPDF to find the package. How can I render an HTML string with external resources into a PDF? IronPDF allows rendering HTML with external resources by setting the BaseUrlOrPath property. You can load images, CSS, and JavaScript from specified URLs or paths and render them into the PDF. Regan Pun Chat with engineering team now Software Engineer Regan graduated from the University of Reading, with a BA in Electronic Engineering. Before joining Iron Software, his previous job roles had him laser-focused on single tasks; and what he most enjoys at Iron Software is the spectrum of work he gets to undertake, whether it’s adding value to ...Read More Ready to Get Started? Free NuGet Download Total downloads: 15,080,714 View Licenses