# How to Convert HTML to PDF in C# .NET Core
Converting to PDFs from various formats can be challenging due to the stringent standards of the PDF format. The conversion may not yield a one-to-one match in many cases, especially when dealing with HTML and CSS styling. However, in today's digital landscape, the ability to convert URLs and forms - including those with HTML and CSS - is essential. This is where IronPDF excels, offering intuitive features that empower developers to convert a wide range of formats to PDF with high fidelity, often in just a few lines of code.
With IronPDF, you can effortlessly convert HTML, DOCX, RTF, Markdown, and even images to PDF, ensuring the integrity of your documents is maintained. It also supports the conversion of dynamic web pages from popular frameworks like Razor, CSHTML, ASPX, and XAML, eliminating compatibility concerns and making IronPDF your comprehensive solution for all PDF conversion needs.
In addition to straightforward conversion, IronPDF offers powerful customization options. You can tailor your PDF output with custom margins, headers, and footers to include page numbers and adjust greyscale settings to reduce file size. Enhance your documents by incorporating additional features like a table of contents, automatic page breaks, and content that scales perfectly to your desired document size.
In this tutorial, we will explore these capabilities and more, providing code examples and highlighting the key features of IronPDF. Get ready to transform your PDF conversion process, allowing you to convert, customize, and optimize your PDF documents effortlessly with IronPDF.
*as-heading:2(Quickstart: Convert HTML to PDF with IronPDF)*
Get started with IronPDF to convert HTML to PDF effortlessly in .NET Core. With just a single line of code, you can render pixel-perfect PDFs from HTML strings using IronPDF's powerful API. This guide will show you how to quickly integrate IronPDF into your project, enabling seamless PDF generation with minimal setup. Whether you're converting HTML, URLs, or Razor views, IronPDF simplifies the process, making it accessible for developers of all levels. Start converting today and explore advanced features when you're ready.
```cs
:title=Convert HTML to PDF Instantly
var pdf = new IronPdf.ChromePdfRenderer().RenderHtmlAsPdf("<h1>Hello, PDF!</h1>");
```
*as-heading:2(Table of Contents)*
- **Versatile PDF Conversion**
- [PDF from HTML String](#anchor-pdf-from-html-string)
- [PDF from HTML File](#anchor-pdf-from-html)
- [PDF from URL](#anchor-pdf-from-url)
- [Image to PDF](#anchor-image-to-pdf)
- [Image from PDF](#anchor-image-from-pdf)
- [Convert DOCX to PDF](#anchor-convert-docx-to-pdf)
- [Convert RTF to PDF](#anchor-convert-rtf-to-pdf)
- [Convert MD to PDF](#anchor-convert-md-to-pdf)
- [Convert XML to PDF](#anchor-convert-xml-to-pdf)
- [PDF to HTML](#anchor-pdf-to-html)
- **Dynamic Web Page to PDFs**
- [PDF from ASPX Pages](#anchor-pdf-from-aspx-pages)
- [XAML to PDF (MAUI)](#anchor-xaml-to-pdf-maui)
- [Generate PDF Reports](#anchor-generate-pdf-reports)
- [Create PDFs in Blazor Servers](#anchor-create-pdfs-in-blazor-servers)
- [Razor to PDF(Blazor Server)](#anchor-razor-to-pdf-blazor-servers)
- [CSHTML to PDF Overview](#anchor-cshtml-to-pdf)
- [CSHTML to PDF(Razor Pages)](#anchor-cshtml-to-pdf-razor-pages)
- [CSHTML to PDF(MVC Core)](#anchor-cshtml-to-pdf-mvc-core)
- [CSHTML to PDF(MVC Framework)](#anchor-cshtml-to-pdf-mvc-framework)
- [CSHTML to PDF(Headlessly)](#anchor-cshtml-to-pdf-headlessly)
- **Web Accessibility**
- [TLS Website & System Logins](#anchor-tls-website-system-logins)
- [Cookies](#anchor-cookies)
- [HTTP Request Header](#anchor-http-request-header)
- **Tailored PDF Conversion**
- [Rendering Options](#anchor-rendering-options)
- [Set Custom Margins](#anchor-set-custom-margin)
- [Grayscale](#anchor-grayscale)
- **Refine PDF Layout**
- [Add a Table of Contents](#anchor-add-a-table-of-contents)
- [Page Break](#anchor-page-break)
- [Fit to Paper & Zoom](#anchor-fit-to-page-zoom)
## Versatile PDF Conversion
### PDF from HTML String
To convert a PDF from an HTML string, we can use the `RenderHtmlAsPdf` method to transform the HTML string into a pixel-perfect PDF quickly.
```cs
:path=/static-assets/pdf/content-code-examples/how-to/html-string-to-pdf.cs
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/html-string-to-pdf/).
### PDF from HTML
Easily convert an HTML file to a PDF with our `RenderHtmlFileAsPdf` method and quickly save your pixel-perfect PDF.
```cs
:path=/static-assets/pdf/content-code-examples/how-to/html-file-to-pdf.cs
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/html-file-to-pdf/).
### PDF from URL
Convert the URL to PDF quickly with `RenderUrlAsPdf` in just a few lines. Input the URL as a parameter and save it with ease.
```cs
:path=/static-assets/pdf/content-code-examples/how-to/url-to-pdf.cs
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/url-to-pdf/).
### Image To PDF
Do you have an image you want to display as a PDF? Quickly convert it with our `ImageToPdfConverter` class and call the `ImageToPdf` method.
```cs
:path=/static-assets/pdf/content-code-examples/how-to/image-to-pdf-convert-one-image.cs
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/image-to-pdf/).
### Image From PDF
For the opposite of the example above, we can first convert the input into a PDF and then use the `RasterizeToImageFiles` method to convert the PDF into images.
```cs
:path=/static-assets/pdf/content-code-examples/how-to/rasterize-pdf-to-images-rasterize.cs
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/rasterize-pdf-to-images/).
### Convert DOCX to PDF
Have you ever needed to convert a DOCX file, such as a resume, to PDF easily? IronPDF has you covered. Simply call the `RenderDocxAsPDF` method to convert.
```cs
:path=/static-assets/pdf/content-code-examples/how-to/docx-to-pdf-from-file.cs
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/docx-to-pdf/).
### Convert RTF to PDF
To convert an RTF file to a PDF, we call the `RenderRtfFileAsPdf` method with the RTF file as input.
```cs
:path=/static-assets/pdf/content-code-examples/how-to/rtf-to-pdf-from-file.cs
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/rtf-to-pdf/).
### Convert MD to PDF
To convert an MD to a PDF, we can call the `RenderMarkdownFileAsPdf` method with the MD file as input.
```cs
:path=/static-assets/pdf/content-code-examples/how-to/md-to-pdf-from-file.cs
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/md-to-pdf/).
### Convert XML to PDF
Although converting XML to PDF can be pretty challenging, IronPDF still rises to the challenge and helps convert XML to PDF in a few steps. We start with an XLST template and then convert the XML to PDF via HTML through XLST transformations. Here's a shortened version of the code snippet to help you get started.
```cs
// XSLT template that defines the transformation from XML to HTML
string xslt = @"<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match='/'>
<html>
<style>
td{
text-align: center;
padding: 20px;
border: 1px solid #CDE7F0;
}
th{
color: white;
padding: 20px;
}
</style>
<body style='font-family: Arial, Helvetica Neue, Helvetica, sans-serif;'>
<table style='border-collapse: collapse;'>
<thead>
<tr>
<th colspan='3'>
<img style='margin: auto;' src='https://ironsoftware.com/img/svgs/ironsoftware-logo-black.svg'/>
</th>
</tr>
</thead>
<tbody>
<tr bgcolor='#9acd32'>
<th bgcolor='#32ab90'>Title</th>
<th bgcolor='#f49400'>Feature</th>
<th bgcolor='#2a95d5'>Compatible</th>
</tr>
<xsl:for-each select='catalog/cd'>
<tr>
<td style='font-weight: bold;'><xsl:value-of select='title'/></td>
<td style='background-color: #eff8fb; color: #2a95d5; font-weight: bold;'><xsl:value-of select='feature'/></td>
<td><xsl:value-of select='compatible'/></td>
</tr>
</xsl:for-each>
</tbody>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
";
[...]
// Create an instance of XslCompiledTransform
XslCompiledTransform transform = new XslCompiledTransform();
// Load the XSLT from a string
using (XmlReader reader = XmlReader.Create(new StringReader(xslt)))
{
transform.Load(reader);
}
// Transform the XML to HTML
StringWriter results = new StringWriter();
using (XmlReader reader = XmlReader.Create(new StringReader(xml)))
{
transform.Transform(reader, null, results);
}
// Create a renderer for converting HTML to PDF
IronPdf.ChromePdfRenderer renderer = new IronPdf.ChromePdfRenderer();
// Options, headers, and footers may be set here if needed
// Render our XML as a PDF via XSLT transformation
renderer.RenderHtmlAsPdf(results.ToString()).SaveAs("Final.pdf");
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/xml-to-pdf/).
### PDF to HTML
In addition to converting various formats to PDFs, IronPDF also supports the opposite operation of converting PDFs into HTML. Here's a quick code snippet to demonstrate the functionality.
```cs
:path=/static-assets/pdf/content-code-examples/how-to/pdf-to-html.cs
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/pdf-to-html/).
## Dynamic Web Page to PDFs
Do you need your dynamic web page preserved and converted to PDFs while preserving the exact layout and formatting? Look no further than IronPDF, which quickly converts a variety of popular dynamic web page frameworks to PDFs.
### PDF from ASPX Pages
Here's a brief code snippet on converting ASPX Pages as PDF in Active Server Pages.
```cs
:path=/static-assets/pdf/content-code-examples/how-to/aspx-to-pdf-2.cs
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/aspx-to-pdf/).
### XAML to PDF (MAUI)
For developers looking to build cross-platform applications, .NET MAUI is a popular choice among the frameworks. IronPDF fully supports converting XAML to PDF with a few steps.
```cs
:path=/static-assets/pdf/content-code-examples/how-to/xaml-to-pdf-maui-mainpage-xaml-cs.cs
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/xaml-to-pdf-maui/).
### Generate PDF Reports
When it comes to generating PDF Reports, the exact dimensions and format are crucial. As such, IronPDF allows you to generate PDFs seamlessly with only a couple of steps.
```cs
:path=/static-assets/pdf/content-code-examples/how-to/csharp-pdf-reports-render-html-file.cs
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/csharp-pdf-reports/).
### Create PDFs in Blazor Servers
IronPDF supports .NET 6, and as it includes project types like Blazor, this code snippet provides a brief example of how to create PDFs in Blazor Server.
```csharp
@code {
// Model to bind user input
private InputHTMLModel _InputMsgModel = new InputHTMLModel();
private async Task SubmitHTML()
{
// Set your IronPDF license key
IronPdf.License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01";
// Create a renderer to convert HTML to PDF
var render = new IronPdf.ChromePdfRenderer();
// Render the HTML input into a PDF document
var doc = render.RenderHtmlAsPdf(_InputMsgModel.HTML);
var fileName = "iron.pdf";
// Create a stream reference for the PDF content
using var streamRef = new DotNetStreamReference(stream: doc.Stream);
// Invoke JavaScript function to download the PDF in the browser
await JS.InvokeVoidAsync("SubmitHTML", fileName, streamRef);
}
public class InputHTMLModel
{
public string HTML { get; set; } = "My new message";
}
}
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/blazor-tutorial/).
### Razor to PDF (Blazor Servers)
Aside from creating PDFs in Blazor Servers, IronPDF also supports generating PDF documents from Razor components within a Blazor page. Making the creation of PDF files and pages much more streamlined.
```csharp
[Parameter]
public IEnumerable<PersonInfo> persons { get; set; }
public Dictionary<string, object> Parameters { get; set; } = new Dictionary<string, object>();
protected override async Task OnInitializedAsync()
{
persons = new List<PersonInfo>
{
new PersonInfo { Name = "Alice", Title = "Mrs.", Description = "Software Engineer" },
new PersonInfo { Name = "Bob", Title = "Mr.", Description = "Software Engineer" },
new PersonInfo { Name = "Charlie", Title = "Mr.", Description = "Software Engineer" }
};
}
private async void PrintToPdf()
{
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Apply text footer
renderer.RenderingOptions.TextFooter = new TextHeaderFooter()
{
LeftText = "{date} - {time}",
DrawDividerLine = true,
RightText = "Page {page} of {total-pages}",
Font = IronSoftware.Drawing.FontTypes.Arial,
FontSize = 11
};
Parameters.Add("persons", persons);
// Render razor component to PDF
PdfDocument pdf = renderer.RenderRazorComponentToPdf<Person>(Parameters);
File.WriteAllBytes("razorComponentToPdf.pdf", pdf.BinaryData);
}
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/razor-to-pdf-blazor-server/).
### CSHTML to PDF
Converting CSHTML (Razor) to PDF allows you to generate professional, print-ready documents directly from your web applications. This is useful for invoices, reports, contracts, or any dynamic content. IronPDF supports Razor Pages, MVC Core, and MVC Framework, as well as headless rendering, making it seamless to integrate PDF generation into your .NET applications with just a few lines of code.
#### CSHTML to PDF (Razor Pages)
```csharp
using IronPdf.Razor.Pages;
public IActionResult OnPostAsync()
{
persons = new List<Person>
{
new Person { Name = "Alice", Title = "Mrs.", Description = "Software Engineer" },
new Person { Name = "Bob", Title = "Mr.", Description = "Software Engineer" },
new Person { Name = "Charlie", Title = "Mr.", Description = "Software Engineer" }
};
ViewData["personList"] = persons;
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Render Razor Page to PDF document
PdfDocument pdf = renderer.RenderRazorToPdf(this);
Response.Headers.Add("Content-Disposition", "inline");
return File(pdf.BinaryData, "application/pdf", "razorPageToPdf.pdf");
}
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/cshtml-to-pdf-razor/).
#### CSHTML to PDF (MVC Core)
```csharp
public async Task<IActionResult> Persons()
{
var persons = new List<Person>
{
new Person { Name = "Alice", Title = "Mrs.", Description = "Software Engineer" },
new Person { Name = "Bob", Title = "Mr.", Description = "Software Engineer" },
new Person { Name = "Charlie", Title = "Mr.", Description = "Software Engineer" }
};
if (_httpContextAccessor.HttpContext.Request.Method == HttpMethod.Post.Method)
{
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Render View to PDF document
PdfDocument pdf = renderer.RenderRazorViewToPdf(_viewRenderService, "Views/Home/Persons.cshtml", persons);
Response.Headers.Add("Content-Disposition", "inline");
// Output PDF document
return File(pdf.BinaryData, "application/pdf", "viewToPdfMVCCore.pdf");
}
return View(persons);
}
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/cshtml-to-pdf-mvc-core/).
#### CSHTML to PDF (MVC Framework)
```csharp
public ActionResult Persons()
{
var persons = new List<Person>
{
new Person { Name = "Alice", Title = "Mrs.", Description = "Software Engineer" },
new Person { Name = "Bob", Title = "Mr.", Description = "Software Engineer" },
new Person { Name = "Charlie", Title = "Mr.", Description = "Software Engineer" }
};
if (HttpContext.Request.HttpMethod == "POST")
{
// Provide the path to your view file
var viewPath = "~/Views/Home/Persons.cshtml";
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Render Razor view to PDF document
PdfDocument pdf = renderer.RenderView(this.HttpContext, viewPath, persons);
Response.Headers.Add("Content-Disposition", "inline");
// View the PDF
return File(pdf.BinaryData, "application/pdf");
}
return View(persons);
}
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/cshtml-to-pdf-mvc-framework/).
#### CSHTML to PDF (Headlessly)
```csharp
:path=/static-assets/pdf/content-code-examples/tutorials/convert-pdf-20.cs
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/cshtml-to-pdf-razor-headlessly/).
## Web Accessibility
### TLS Website & System Logins
IronPDF offers an easy solution for converting web pages that require authentication. With its rendering options, users can bypass HTTP authentication by setting the renderer's `LoginCredentials` property to a `ChromeHttpLoginCredentials` object.
```cs
:path=/static-assets/pdf/content-code-examples/how-to/logins-username-password.cs
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/logins/).
### Cookies
Apply cookies to the additional login request to ensure your session is saved! This will make it easier to render additional resources within the locked domain, all within IronPDF.
```cs
:path=/static-assets/pdf/content-code-examples/how-to/cookies-apply-cookies.cs
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/cookies/).
### HTTP Request Header
Aside from cookies, IronPDF also allows users to customize their HTTP request header with authorization tokens and other common-related fields.
```cs
:path=/static-assets/pdf/content-code-examples/how-to/http-request-header.cs
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/http-request-header/).
## Tailored Your PDF Conversion
### Rendering Options
IronPDF allows users to customize the appearance and format of their generated PDFs. The `ChromePdfRenderer` class that is used to convert various inputs into PDFs also includes the `RenderingOptions` property, letting users control how the output looks.
```cs
:path=/static-assets/pdf/content-code-examples/how-to/rendering-options-render.cs
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/rendering-options/).
### Set Custom Margin
You can further tailor the appearance of your output PDF by adjusting the margins, allowing you to control the layout and spacing precisely.
```cs
:path=/static-assets/pdf/content-code-examples/how-to/custom-margins-set-margins.cs
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/custom-margins/).
### Grayscale
To generate a grayscale PDF, we set the `GrayScale` property within `RenderingOptions` to true.
```cs
:path=/static-assets/pdf/content-code-examples/how-to/color-grayscale-grayscale.cs
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/color-grayscale/).
## Refine Your PDF Layout
### Add a Table of Contents
Create a dynamic table of contents with IronPDF to help readers easily navigate your document. IronPDF automatically handles the table of contents with hyperlinks to headers such as `h1` and `h2`. Along with that, you can also customize the styling of the table of contents with HTML and CSS styling.
```cs
:path=/static-assets/pdf/content-code-examples/how-to/table-of-contents.cs
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/table-of-contents/).
### Page Break
Add page breaks between sections to clearly separate content and improve the readability of your document. With IronPDF, simply use the HTML `div style= page-break-after` to achieve that effect.
```cs
:path=/static-assets/pdf/content-code-examples/how-to/html-to-pdf-page-breaks-page-break.cs
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/html-to-pdf-page-breaks/).
### Fit to Page & Zoom
Need help deciding the dimensions of the content to fit a specified paper size? IronPDF has you covered with the `UseChromeDefault`, which mimics how Google Chrome's print preview scales content to fit the page.
```cs
:path=/static-assets/pdf/content-code-examples/how-to/viewport-zoom-default-chrome.cs
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/viewport-zoom/).
## Conclusion
The examples above showcase the impressive capabilities and standout features you can unlock while converting various formats to PDFs using IronPDF.
If you would like to request a feature or have general questions about IronPDF or licensing, please [contact our support team](/troubleshooting/engineering-request-pdf/). We will be more than happy to assist you.
Converting to PDFs from various formats can be challenging due to the stringent standards of the PDF format. The conversion may not yield a one-to-one match in many cases, especially when dealing with HTML and CSS styling. However, in today's digital landscape, the ability to convert URLs and forms - including those with HTML and CSS - is essential. This is where IronPDF excels, offering intuitive features that empower developers to convert a wide range of formats to PDF with high fidelity, often in just a few lines of code.
With IronPDF, you can effortlessly convert HTML, DOCX, RTF, Markdown, and even images to PDF, ensuring the integrity of your documents is maintained. It also supports the conversion of dynamic web pages from popular frameworks like Razor, CSHTML, ASPX, and XAML, eliminating compatibility concerns and making IronPDF your comprehensive solution for all PDF conversion needs.
In addition to straightforward conversion, IronPDF offers powerful customization options. You can tailor your PDF output with custom margins, headers, and footers to include page numbers and adjust greyscale settings to reduce file size. Enhance your documents by incorporating additional features like a table of contents, automatic page breaks, and content that scales perfectly to your desired document size.
In this tutorial, we will explore these capabilities and more, providing code examples and highlighting the key features of IronPDF. Get ready to transform your PDF conversion process, allowing you to convert, customize, and optimize your PDF documents effortlessly with IronPDF.
Quickstart: Convert HTML to PDF with IronPDF
Get started with IronPDF to convert HTML to PDF effortlessly in .NET Core. With just a single line of code, you can render pixel-perfect PDFs from HTML strings using IronPDF's powerful API. This guide will show you how to quickly integrate IronPDF into your project, enabling seamless PDF generation with minimal setup. Whether you're converting HTML, URLs, or Razor views, IronPDF simplifies the process, making it accessible for developers of all levels. Start converting today and explore advanced features when you're ready.
1Install IronPDF with NuGet Package Manager
PM > Install-Package IronPdf
Install-Package IronPdf
2Copy and run this code snippet.
var pdf = new IronPdf.ChromePdfRenderer().RenderHtmlAsPdf("<h1>Hello, PDF!</h1>");
var pdf = new IronPdf.ChromePdfRenderer().RenderHtmlAsPdf("<h1>Hello, PDF!</h1>");
C#
3Deploy to test on your live environment
Start using IronPDF in your project today with a free trial
To convert a PDF from an HTML string, we can use the RenderHtmlAsPdf method to transform the HTML string into a pixel-perfect PDF quickly.
using IronPdf;// Instantiate Renderervar 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 Streampdf.SaveAs("output.pdf");
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");
ImportsIronPdf' Instantiate RendererPrivate 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 Streampdf.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")
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
PDF from HTML
Easily convert an HTML file to a PDF with our RenderHtmlFileAsPdf method and quickly save your pixel-perfect PDF.
using IronPdf;using IronPdf.Engines.Chrome;using IronPdf.Rendering;var renderer = new ChromePdfRenderer{RenderingOptions = new ChromePdfRenderOptions {CssMediaType = PdfCssMediaType.Print,MarginBottom = 0,MarginLeft = 0,MarginRight = 0,MarginTop = 0,Timeout = 120, },};renderer.RenderingOptions.WaitFor.RenderDelay(50);// Create a PDF from an existing HTML file using C#var pdf = renderer.RenderHtmlFileAsPdf("example.html");// Export to a file or Streampdf.SaveAs("output.pdf");
using IronPdf;
using IronPdf.Engines.Chrome;
using IronPdf.Rendering;
var renderer = new ChromePdfRenderer
{
RenderingOptions = new ChromePdfRenderOptions
{
CssMediaType = PdfCssMediaType.Print,
MarginBottom = 0,
MarginLeft = 0,
MarginRight = 0,
MarginTop = 0,
Timeout = 120,
},
};
renderer.RenderingOptions.WaitFor.RenderDelay(50);
// Create a PDF from an existing HTML file using C#
var pdf = renderer.RenderHtmlFileAsPdf("example.html");
// Export to a file or Stream
pdf.SaveAs("output.pdf");
ImportsIronPdfImportsIronPdf.Engines.ChromeImportsIronPdf.RenderingPrivate renderer = New ChromePdfRendererWith { .RenderingOptions = New ChromePdfRenderOptionsWith { .CssMediaType = PdfCssMediaType.Print, .MarginBottom = 0, .MarginLeft = 0, .MarginRight = 0, .MarginTop = 0, .Timeout = 120 }}renderer.RenderingOptions.WaitFor.RenderDelay(50)' Create a PDF from an existing HTML file using C#Dim pdf = renderer.RenderHtmlFileAsPdf("example.html")' Export to a file or Streampdf.SaveAs("output.pdf")
Imports IronPdf
Imports IronPdf.Engines.Chrome
Imports IronPdf.Rendering
Private renderer = New ChromePdfRenderer With {
.RenderingOptions = New ChromePdfRenderOptions With {
.CssMediaType = PdfCssMediaType.Print,
.MarginBottom = 0,
.MarginLeft = 0,
.MarginRight = 0,
.MarginTop = 0,
.Timeout = 120
}
}
renderer.RenderingOptions.WaitFor.RenderDelay(50)
' Create a PDF from an existing HTML file using C#
Dim pdf = renderer.RenderHtmlFileAsPdf("example.html")
' Export to a file or Stream
pdf.SaveAs("output.pdf")
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
PDF from URL
Convert the URL to PDF quickly with RenderUrlAsPdf in just a few lines. Input the URL as a parameter and save it with ease.
using IronPdf;// Instantiate Renderervar renderer = new ChromePdfRenderer();// Create a PDF from a URL or local file pathvar pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page");// Export to a file or Streampdf.SaveAs("url.pdf");
using IronPdf;
// Instantiate Renderer
var renderer = new ChromePdfRenderer();
// Create a PDF from a URL or local file path
var pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page");
// Export to a file or Stream
pdf.SaveAs("url.pdf");
ImportsIronPdf' Instantiate RendererPrivate renderer = New ChromePdfRenderer()' Create a PDF from a URL or local file pathPrivate pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page")' Export to a file or Streampdf.SaveAs("url.pdf")
Imports IronPdf
' Instantiate Renderer
Private renderer = New ChromePdfRenderer()
' Create a PDF from a URL or local file path
Private pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page")
' Export to a file or Stream
pdf.SaveAs("url.pdf")
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
Image To PDF
Do you have an image you want to display as a PDF? Quickly convert it with our ImageToPdfConverter class and call the ImageToPdf method.
using IronPdf;string imagePath = "meetOurTeam.jpg";// Convert an image to a PDFPdfDocument pdf = ImageToPdfConverter.ImageToPdf(imagePath);// Export the PDFpdf.SaveAs("imageToPdf.pdf");
using IronPdf;
string imagePath = "meetOurTeam.jpg";
// Convert an image to a PDF
PdfDocument pdf = ImageToPdfConverter.ImageToPdf(imagePath);
// Export the PDF
pdf.SaveAs("imageToPdf.pdf");
ImportsIronPdfPrivate imagePath AsString = "meetOurTeam.jpg"' Convert an image to a PDFPrivate pdf AsPdfDocument = ImageToPdfConverter.ImageToPdf(imagePath)' Export the PDFpdf.SaveAs("imageToPdf.pdf")
Imports IronPdf
Private imagePath As String = "meetOurTeam.jpg"
' Convert an image to a PDF
Private pdf As PdfDocument = ImageToPdfConverter.ImageToPdf(imagePath)
' Export the PDF
pdf.SaveAs("imageToPdf.pdf")
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
Image From PDF
For the opposite of the example above, we can first convert the input into a PDF and then use the RasterizeToImageFiles method to convert the PDF into images.
using IronPdf;// Instantiate RendererChromePdfRenderer renderer = new ChromePdfRenderer();// Render PDF from web URLPdfDocument pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page");// Export images from PDFpdf.RasterizeToImageFiles("wikipage_*.png");
using IronPdf;
// Instantiate Renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Render PDF from web URL
PdfDocument pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page");
// Export images from PDF
pdf.RasterizeToImageFiles("wikipage_*.png");
ImportsIronPdf' Instantiate RendererDim renderer As New ChromePdfRenderer()' Render PDF from web URLDim pdf AsPdfDocument = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page")' Export images from PDFpdf.RasterizeToImageFiles("wikipage_*.png")
Imports IronPdf
' Instantiate Renderer
Dim renderer As New ChromePdfRenderer()
' Render PDF from web URL
Dim pdf As PdfDocument = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page")
' Export images from PDF
pdf.RasterizeToImageFiles("wikipage_*.png")
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
Convert DOCX to PDF
Have you ever needed to convert a DOCX file, such as a resume, to PDF easily? IronPDF has you covered. Simply call the RenderDocxAsPDF method to convert.
using IronPdf;// Instantiate RendererDocxToPdfRenderer renderer = new DocxToPdfRenderer();// Render from DOCX filePdfDocument pdf = renderer.RenderDocxAsPdf("Modern-chronological-resume.docx");// Save the PDFpdf.SaveAs("pdfFromDocx.pdf");
using IronPdf;
// Instantiate Renderer
DocxToPdfRenderer renderer = new DocxToPdfRenderer();
// Render from DOCX file
PdfDocument pdf = renderer.RenderDocxAsPdf("Modern-chronological-resume.docx");
// Save the PDF
pdf.SaveAs("pdfFromDocx.pdf");
ImportsIronPdf' Instantiate RendererDim renderer As New DocxToPdfRenderer()' Render from DOCX fileDim pdf AsPdfDocument = renderer.RenderDocxAsPdf("Modern-chronological-resume.docx")' Save the PDFpdf.SaveAs("pdfFromDocx.pdf")
Imports IronPdf
' Instantiate Renderer
Dim renderer As New DocxToPdfRenderer()
' Render from DOCX file
Dim pdf As PdfDocument = renderer.RenderDocxAsPdf("Modern-chronological-resume.docx")
' Save the PDF
pdf.SaveAs("pdfFromDocx.pdf")
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
Convert RTF to PDF
To convert an RTF file to a PDF, we call the RenderRtfFileAsPdf method with the RTF file as input.
using IronPdf;// Instantiate RendererChromePdfRenderer renderer = new ChromePdfRenderer();// Render from RTF filePdfDocument pdf = renderer.RenderRtfFileAsPdf("sample.rtf");// Save the PDFpdf.SaveAs("pdfFromRtfFile.pdf");
using IronPdf;
// Instantiate Renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Render from RTF file
PdfDocument pdf = renderer.RenderRtfFileAsPdf("sample.rtf");
// Save the PDF
pdf.SaveAs("pdfFromRtfFile.pdf");
ImportsIronPdf' Instantiate RendererPrivate renderer As New ChromePdfRenderer()' Render from RTF filePrivate pdf AsPdfDocument = renderer.RenderRtfFileAsPdf("sample.rtf")' Save the PDFpdf.SaveAs("pdfFromRtfFile.pdf")
Imports IronPdf
' Instantiate Renderer
Private renderer As New ChromePdfRenderer()
' Render from RTF file
Private pdf As PdfDocument = renderer.RenderRtfFileAsPdf("sample.rtf")
' Save the PDF
pdf.SaveAs("pdfFromRtfFile.pdf")
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
Convert MD to PDF
To convert an MD to a PDF, we can call the RenderMarkdownFileAsPdf method with the MD file as input.
using IronPdf;// Instantiate RendererChromePdfRenderer renderer = new ChromePdfRenderer();// Render from markdown filePdfDocument pdf = renderer.RenderMarkdownFileAsPdf("sample.md");// Save the PDFpdf.SaveAs("pdfFromMarkdownFile.pdf");
using IronPdf;
// Instantiate Renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Render from markdown file
PdfDocument pdf = renderer.RenderMarkdownFileAsPdf("sample.md");
// Save the PDF
pdf.SaveAs("pdfFromMarkdownFile.pdf");
ImportsIronPdf' Instantiate RendererPrivate renderer As New ChromePdfRenderer()' Render from markdown filePrivate pdf AsPdfDocument = renderer.RenderMarkdownFileAsPdf("sample.md")' Save the PDFpdf.SaveAs("pdfFromMarkdownFile.pdf")
Imports IronPdf
' Instantiate Renderer
Private renderer As New ChromePdfRenderer()
' Render from markdown file
Private pdf As PdfDocument = renderer.RenderMarkdownFileAsPdf("sample.md")
' Save the PDF
pdf.SaveAs("pdfFromMarkdownFile.pdf")
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
Convert XML to PDF
Although converting XML to PDF can be pretty challenging, IronPDF still rises to the challenge and helps convert XML to PDF in a few steps. We start with an XLST template and then convert the XML to PDF via HTML through XLST transformations. Here's a shortened version of the code snippet to help you get started.
// XSLT template that defines the transformation from XML to HTMLstring xslt = @"<?xml version='1.0' encoding='UTF-8'?><xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:template match='/'><html><style>td{ text-align: center; padding: 20px; border: 1px solid #CDE7F0;}th{ color: white; padding: 20px;}</style><body style='font-family: Arial, Helvetica Neue, Helvetica, sans-serif;'> <table style='border-collapse: collapse;'> <thead> <tr> <th colspan='3'> <img style='margin: auto;' src='https://ironsoftware.com/img/svgs/ironsoftware-logo-black.svg'/> </th> </tr> </thead> <tbody> <tr bgcolor='#9acd32'> <th bgcolor='#32ab90'>Title</th> <th bgcolor='#f49400'>Feature</th> <th bgcolor='#2a95d5'>Compatible</th> </tr> <xsl:for-each select='catalog/cd'> <tr> <td style='font-weight: bold;'><xsl:value-of select='title'/></td> <td style='background-color: #eff8fb; color: #2a95d5; font-weight: bold;'><xsl:value-of select='feature'/></td> <td><xsl:value-of select='compatible'/></td> </tr> </xsl:for-each> </tbody> </table></body></html></xsl:template></xsl:stylesheet>";[...]// Create an instance of XslCompiledTransformXslCompiledTransform transform = new XslCompiledTransform();// Load the XSLT from a stringusing (XmlReader reader = XmlReader.Create(new StringReader(xslt))){ transform.Load(reader);}// Transform the XML to HTMLStringWriter results = new StringWriter();using (XmlReader reader = XmlReader.Create(new StringReader(xml))){ transform.Transform(reader, null, results);}// Create a renderer for converting HTML to PDFIronPdf.ChromePdfRenderer renderer = new IronPdf.ChromePdfRenderer();// Options, headers, and footers may be set here if needed// Render our XML as a PDF via XSLT transformationrenderer.RenderHtmlAsPdf(results.ToString()).SaveAs("Final.pdf");
// XSLT template that defines the transformation from XML to HTML
string xslt = @"<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match='/'>
<html>
<style>
td{
text-align: center;
padding: 20px;
border: 1px solid #CDE7F0;
}
th{
color: white;
padding: 20px;
}
</style>
<body style='font-family: Arial, Helvetica Neue, Helvetica, sans-serif;'>
<table style='border-collapse: collapse;'>
<thead>
<tr>
<th colspan='3'>
<img style='margin: auto;' src='https://ironsoftware.com/img/svgs/ironsoftware-logo-black.svg'/>
</th>
</tr>
</thead>
<tbody>
<tr bgcolor='#9acd32'>
<th bgcolor='#32ab90'>Title</th>
<th bgcolor='#f49400'>Feature</th>
<th bgcolor='#2a95d5'>Compatible</th>
</tr>
<xsl:for-each select='catalog/cd'>
<tr>
<td style='font-weight: bold;'><xsl:value-of select='title'/></td>
<td style='background-color: #eff8fb; color: #2a95d5; font-weight: bold;'><xsl:value-of select='feature'/></td>
<td><xsl:value-of select='compatible'/></td>
</tr>
</xsl:for-each>
</tbody>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
";
[...]
// Create an instance of XslCompiledTransform
XslCompiledTransform transform = new XslCompiledTransform();
// Load the XSLT from a string
using (XmlReader reader = XmlReader.Create(new StringReader(xslt)))
{
transform.Load(reader);
}
// Transform the XML to HTML
StringWriter results = new StringWriter();
using (XmlReader reader = XmlReader.Create(new StringReader(xml)))
{
transform.Transform(reader, null, results);
}
// Create a renderer for converting HTML to PDF
IronPdf.ChromePdfRenderer renderer = new IronPdf.ChromePdfRenderer();
// Options, headers, and footers may be set here if needed
// Render our XML as a PDF via XSLT transformation
renderer.RenderHtmlAsPdf(results.ToString()).SaveAs("Final.pdf");
ImportsSystem.XmlImportsSystem.IOImportsSystem.Xml.XslImportsIronPdf' XSLT template that defines the transformation from XML to HTMLDim xslt AsString = "<?xml version='1.0' encoding='UTF-8'?>" & _"<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>" & _"<xsl:template match='/'>" & _"<html>" & _"<style>" & _"td{" & _" text-align: center;" & _" padding: 20px;" & _" border: 1px solid #CDE7F0;" & _"}" & _"th{" & _" color: white;" & _" padding: 20px;" & _"}" & _"</style>" & _"<body style='font-family: Arial, Helvetica Neue, Helvetica, sans-serif;'>" & _" <table style='border-collapse: collapse;'>" & _" <thead>" & _" <tr>" & _" <th colspan='3'>" & _" <img style='margin: auto;' src='https://ironsoftware.com/img/svgs/ironsoftware-logo-black.svg'/>" & _" </th>" & _" </tr>" & _" </thead>" & _" <tbody>" & _" <tr bgcolor='#9acd32'>" & _" <th bgcolor='#32ab90'>Title</th>" & _" <th bgcolor='#f49400'>Feature</th>" & _" <th bgcolor='#2a95d5'>Compatible</th>" & _" </tr>" & _" <xsl:for-each select='catalog/cd'>" & _" <tr>" & _" <td style='font-weight: bold;'><xsl:value-of select='title'/></td>" & _" <td style='background-color: #eff8fb; color: #2a95d5; font-weight: bold;'><xsl:value-of select='feature'/></td>" & _" <td><xsl:value-of select='compatible'/></td>" & _" </tr>" & _" </xsl:for-each>" & _" </tbody>" & _" </table>" & _"</body>" & _"</html>" & _"</xsl:template>" & _"</xsl:stylesheet>"[...]' Create an instance of XslCompiledTransformDim transform As New XslCompiledTransform()' Load the XSLT from a stringUsing reader AsXmlReader = XmlReader.Create(New StringReader(xslt)) transform.Load(reader)EndUsing' Transform the XML to HTMLDim results As New StringWriter()Using reader AsXmlReader = XmlReader.Create(New StringReader(xml)) transform.Transform(reader, Nothing, results)EndUsing' Create a renderer for converting HTML to PDFDim renderer As New ChromePdfRenderer()' Options, headers, and footers may be set here if needed' Render our XML as a PDF via XSLT transformationrenderer.RenderHtmlAsPdf(results.ToString()).SaveAs("Final.pdf")
Imports System.Xml
Imports System.IO
Imports System.Xml.Xsl
Imports IronPdf
' XSLT template that defines the transformation from XML to HTML
Dim xslt As String = "<?xml version='1.0' encoding='UTF-8'?>" & _
"<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>" & _
"<xsl:template match='/'>" & _
"<html>" & _
"<style>" & _
"td{" & _
" text-align: center;" & _
" padding: 20px;" & _
" border: 1px solid #CDE7F0;" & _
"}" & _
"th{" & _
" color: white;" & _
" padding: 20px;" & _
"}" & _
"</style>" & _
"<body style='font-family: Arial, Helvetica Neue, Helvetica, sans-serif;'>" & _
" <table style='border-collapse: collapse;'>" & _
" <thead>" & _
" <tr>" & _
" <th colspan='3'>" & _
" <img style='margin: auto;' src='https://ironsoftware.com/img/svgs/ironsoftware-logo-black.svg'/>" & _
" </th>" & _
" </tr>" & _
" </thead>" & _
" <tbody>" & _
" <tr bgcolor='#9acd32'>" & _
" <th bgcolor='#32ab90'>Title</th>" & _
" <th bgcolor='#f49400'>Feature</th>" & _
" <th bgcolor='#2a95d5'>Compatible</th>" & _
" </tr>" & _
" <xsl:for-each select='catalog/cd'>" & _
" <tr>" & _
" <td style='font-weight: bold;'><xsl:value-of select='title'/></td>" & _
" <td style='background-color: #eff8fb; color: #2a95d5; font-weight: bold;'><xsl:value-of select='feature'/></td>" & _
" <td><xsl:value-of select='compatible'/></td>" & _
" </tr>" & _
" </xsl:for-each>" & _
" </tbody>" & _
" </table>" & _
"</body>" & _
"</html>" & _
"</xsl:template>" & _
"</xsl:stylesheet>"
[...]
' Create an instance of XslCompiledTransform
Dim transform As New XslCompiledTransform()
' Load the XSLT from a string
Using reader As XmlReader = XmlReader.Create(New StringReader(xslt))
transform.Load(reader)
End Using
' Transform the XML to HTML
Dim results As New StringWriter()
Using reader As XmlReader = XmlReader.Create(New StringReader(xml))
transform.Transform(reader, Nothing, results)
End Using
' Create a renderer for converting HTML to PDF
Dim renderer As New ChromePdfRenderer()
' Options, headers, and footers may be set here if needed
' Render our XML as a PDF via XSLT transformation
renderer.RenderHtmlAsPdf(results.ToString()).SaveAs("Final.pdf")
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
PDF to HTML
In addition to converting various formats to PDFs, IronPDF also supports the opposite operation of converting PDFs into HTML. Here's a quick code snippet to demonstrate the functionality.
using IronPdf;using System;PdfDocument pdf = PdfDocument.FromFile("sample.pdf");// Convert PDF to HTML stringstring html = pdf.ToHtmlString();Console.WriteLine(html);// Convert PDF to HTML filepdf.SaveAsHtml("myHtml.html");
using IronPdf;
using System;
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");
// Convert PDF to HTML string
string html = pdf.ToHtmlString();
Console.WriteLine(html);
// Convert PDF to HTML file
pdf.SaveAsHtml("myHtml.html");
ImportsIronPdfImportsSystemDim pdf AsPdfDocument = PdfDocument.FromFile("sample.pdf")' Convert PDF to HTML stringDim html AsString = pdf.ToHtmlString()Console.WriteLine(html)' Convert PDF to HTML filepdf.SaveAsHtml("myHtml.html")
Imports IronPdf
Imports System
Dim pdf As PdfDocument = PdfDocument.FromFile("sample.pdf")
' Convert PDF to HTML string
Dim html As String = pdf.ToHtmlString()
Console.WriteLine(html)
' Convert PDF to HTML file
pdf.SaveAsHtml("myHtml.html")
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
Dynamic Web Page to PDFs
Do you need your dynamic web page preserved and converted to PDFs while preserving the exact layout and formatting? Look no further than IronPDF, which quickly converts a variety of popular dynamic web page frameworks to PDFs.
PDF from ASPX Pages
Here's a brief code snippet on converting ASPX Pages as PDF in Active Server Pages.
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using IronPdf;namespace AspxToPdfTutorial{ public partial class Invoice : System.Web.UI.Page { protected voidPage_Load(object sender, EventArgs e) {IronPdf.AspxToPdf.RenderThisPageAsPdf(IronPdf.AspxToPdf.FileBehavior.InBrowser); } }}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IronPdf;
namespace AspxToPdfTutorial
{
public partial class Invoice : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
IronPdf.AspxToPdf.RenderThisPageAsPdf(IronPdf.AspxToPdf.FileBehavior.InBrowser);
}
}
}
ImportsSystemImportsSystem.Collections.GenericImportsSystem.LinqImportsSystem.WebImportsSystem.Web.UIImportsSystem.Web.UI.WebControlsImportsIronPdfNamespaceAspxToPdfTutorialPartialPublic Class InvoiceInheritsSystem.Web.UI.PageProtected Sub Page_Load(ByVal sender AsObject, ByVal e AsEventArgs)IronPdf.AspxToPdf.RenderThisPageAsPdf(IronPdf.AspxToPdf.FileBehavior.InBrowser) End Sub End ClassEndNamespace
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports IronPdf
Namespace AspxToPdfTutorial
Partial Public Class Invoice
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
IronPdf.AspxToPdf.RenderThisPageAsPdf(IronPdf.AspxToPdf.FileBehavior.InBrowser)
End Sub
End Class
End Namespace
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
XAML to PDF (MAUI)
For developers looking to build cross-platform applications, .NET MAUI is a popular choice among the frameworks. IronPDF fully supports converting XAML to PDF with a few steps.
using IronPdf.Extensions.Maui;namespace mauiSample;public partial class MainPage : ContentPage{ publicMainPage() {InitializeComponent(); } private voidPrintToPdf(object sender, EventArgs e) { ChromePdfRenderer renderer = new ChromePdfRenderer(); // Apply HTML header renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter() {HtmlFragment = "<h1>Header</h1>", }; // Render PDF from Maui Page PdfDocument pdf = renderer.RenderContentPageToPdf<MainPage, App>().Result; pdf.SaveAs(@"C:\Users\lyty1\Downloads\contentPageToPdf.pdf"); }}
using IronPdf.Extensions.Maui;
namespace mauiSample;
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private void PrintToPdf(object sender, EventArgs e)
{
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Apply HTML header
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
{
HtmlFragment = "<h1>Header</h1>",
};
// Render PDF from Maui Page
PdfDocument pdf = renderer.RenderContentPageToPdf<MainPage, App>().Result;
pdf.SaveAs(@"C:\Users\lyty1\Downloads\contentPageToPdf.pdf");
}
}
ImportsIronPdf.Extensions.MauiNamespace mauiSamplePartialPublic Class MainPageInheritsContentPage Public Sub New()InitializeComponent() End Sub Private Sub PrintToPdf(ByVal sender AsObject, ByVal e AsEventArgs) Dim renderer As New ChromePdfRenderer() ' Apply HTML header renderer.RenderingOptions.HtmlHeader = New HtmlHeaderFooter() With {.HtmlFragment = "<h1>Header</h1>"} ' Render PDF from Maui Page Dim pdf AsPdfDocument = renderer.RenderContentPageToPdf(OfMainPage, App)().Result pdf.SaveAs("C:\Users\lyty1\Downloads\contentPageToPdf.pdf") End Sub End ClassEndNamespace
Imports IronPdf.Extensions.Maui
Namespace mauiSample
Partial Public Class MainPage
Inherits ContentPage
Public Sub New()
InitializeComponent()
End Sub
Private Sub PrintToPdf(ByVal sender As Object, ByVal e As EventArgs)
Dim renderer As New ChromePdfRenderer()
' Apply HTML header
renderer.RenderingOptions.HtmlHeader = New HtmlHeaderFooter() With {.HtmlFragment = "<h1>Header</h1>"}
' Render PDF from Maui Page
Dim pdf As PdfDocument = renderer.RenderContentPageToPdf(Of MainPage, App)().Result
pdf.SaveAs("C:\Users\lyty1\Downloads\contentPageToPdf.pdf")
End Sub
End Class
End Namespace
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
Generate PDF Reports
When it comes to generating PDF Reports, the exact dimensions and format are crucial. As such, IronPDF allows you to generate PDFs seamlessly with only a couple of steps.
using IronPdf;ChromePdfRenderer renderer = new ChromePdfRenderer();renderer.RenderHtmlFileAsPdf("report.html").SaveAs("report.pdf");
using IronPdf;
ChromePdfRenderer renderer = new ChromePdfRenderer();
renderer.RenderHtmlFileAsPdf("report.html").SaveAs("report.pdf");
ImportsIronPdfPrivate renderer As New ChromePdfRenderer()renderer.RenderHtmlFileAsPdf("report.html").SaveAs("report.pdf")
Imports IronPdf
Private renderer As New ChromePdfRenderer()
renderer.RenderHtmlFileAsPdf("report.html").SaveAs("report.pdf")
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
Create PDFs in Blazor Servers
IronPDF supports .NET 6, and as it includes project types like Blazor, this code snippet provides a brief example of how to create PDFs in Blazor Server.
@code { // Model to bind user input private InputHTMLModel _InputMsgModel = new InputHTMLModel(); private async TaskSubmitHTML() { // Set your IronPDF license keyIronPdf.License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01"; // Create a renderer to convert HTML to PDF var render = new IronPdf.ChromePdfRenderer(); // Render the HTML input into a PDF document var doc = render.RenderHtmlAsPdf(_InputMsgModel.HTML); var fileName = "iron.pdf"; // Create a stream reference for the PDF content using var streamRef = new DotNetStreamReference(stream: doc.Stream); // Invoke JavaScript function to download the PDF in the browser awaitJS.InvokeVoidAsync("SubmitHTML", fileName, streamRef); } public class InputHTMLModel { public stringHTML { get; set; } = "My new message"; }}
@code {
// Model to bind user input
private InputHTMLModel _InputMsgModel = new InputHTMLModel();
private async Task SubmitHTML()
{
// Set your IronPDF license key
IronPdf.License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01";
// Create a renderer to convert HTML to PDF
var render = new IronPdf.ChromePdfRenderer();
// Render the HTML input into a PDF document
var doc = render.RenderHtmlAsPdf(_InputMsgModel.HTML);
var fileName = "iron.pdf";
// Create a stream reference for the PDF content
using var streamRef = new DotNetStreamReference(stream: doc.Stream);
// Invoke JavaScript function to download the PDF in the browser
await JS.InvokeVoidAsync("SubmitHTML", fileName, streamRef);
}
public class InputHTMLModel
{
public string HTML { get; set; } = "My new message";
}
}
codeIf True Then ' Model to bind user input privateInputHTMLModel _InputMsgModel = New InputHTMLModel()'INSTANT VB TODO TASK: Local functions are not converted by Instant VB:' private async Task SubmitHTML()' {' ' Set your IronPDF license key' IronPdf.License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01";'' ' Create a renderer to convert HTML to PDF' var render = New IronPdf.ChromePdfRenderer();'' ' Render the HTML input into a PDF document' var doc = render.RenderHtmlAsPdf(_InputMsgModel.HTML);'' var fileName = "iron.pdf";'' ' Create a stream reference for the PDF content' var streamRef = New DotNetStreamReference(stream: doc.Stream);'' ' Invoke JavaScript function to download the PDF in the browser' await JS.InvokeVoidAsync("SubmitHTML", fileName, streamRef);' }'INSTANT VB TODO TASK: Local functions are not converted by Instant VB:' public class InputHTMLModel' {' public string HTML' {' get;' set;' } = "My new message";' }End If
code
If True Then
' Model to bind user input
private InputHTMLModel _InputMsgModel = New InputHTMLModel()
'INSTANT VB TODO TASK: Local functions are not converted by Instant VB:
' private async Task SubmitHTML()
' {
' ' Set your IronPDF license key
' IronPdf.License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01";
'
' ' Create a renderer to convert HTML to PDF
' var render = New IronPdf.ChromePdfRenderer();
'
' ' Render the HTML input into a PDF document
' var doc = render.RenderHtmlAsPdf(_InputMsgModel.HTML);
'
' var fileName = "iron.pdf";
'
' ' Create a stream reference for the PDF content
' var streamRef = New DotNetStreamReference(stream: doc.Stream);
'
' ' Invoke JavaScript function to download the PDF in the browser
' await JS.InvokeVoidAsync("SubmitHTML", fileName, streamRef);
' }
'INSTANT VB TODO TASK: Local functions are not converted by Instant VB:
' public class InputHTMLModel
' {
' public string HTML
' {
' get;
' set;
' } = "My new message";
' }
End If
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
Razor to PDF (Blazor Servers)
Aside from creating PDFs in Blazor Servers, IronPDF also supports generating PDF documents from Razor components within a Blazor page. Making the creation of PDF files and pages much more streamlined.
[Parameter]publicIEnumerable<PersonInfo> persons { get; set; }publicDictionary<string, object> Parameters { get; set; } = new Dictionary<string, object>();protected override async TaskOnInitializedAsync(){ persons = new List<PersonInfo> { new PersonInfo { Name = "Alice", Title = "Mrs.", Description = "Software Engineer" }, new PersonInfo { Name = "Bob", Title = "Mr.", Description = "Software Engineer" }, new PersonInfo { Name = "Charlie", Title = "Mr.", Description = "Software Engineer" } };}private async voidPrintToPdf(){ ChromePdfRenderer renderer = new ChromePdfRenderer(); // Apply text footer renderer.RenderingOptions.TextFooter = new TextHeaderFooter() {LeftText = "{date} - {time}",DrawDividerLine = true,RightText = "Page {page} of {total-pages}",Font = IronSoftware.Drawing.FontTypes.Arial,FontSize = 11 };Parameters.Add("persons", persons); // Render razor component to PDF PdfDocument pdf = renderer.RenderRazorComponentToPdf<Person>(Parameters);File.WriteAllBytes("razorComponentToPdf.pdf", pdf.BinaryData);}
[Parameter]
public IEnumerable<PersonInfo> persons { get; set; }
public Dictionary<string, object> Parameters { get; set; } = new Dictionary<string, object>();
protected override async Task OnInitializedAsync()
{
persons = new List<PersonInfo>
{
new PersonInfo { Name = "Alice", Title = "Mrs.", Description = "Software Engineer" },
new PersonInfo { Name = "Bob", Title = "Mr.", Description = "Software Engineer" },
new PersonInfo { Name = "Charlie", Title = "Mr.", Description = "Software Engineer" }
};
}
private async void PrintToPdf()
{
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Apply text footer
renderer.RenderingOptions.TextFooter = new TextHeaderFooter()
{
LeftText = "{date} - {time}",
DrawDividerLine = true,
RightText = "Page {page} of {total-pages}",
Font = IronSoftware.Drawing.FontTypes.Arial,
FontSize = 11
};
Parameters.Add("persons", persons);
// Render razor component to PDF
PdfDocument pdf = renderer.RenderRazorComponentToPdf<Person>(Parameters);
File.WriteAllBytes("razorComponentToPdf.pdf", pdf.BinaryData);
}
<Parameter>Public Property persons AsIEnumerable(OfPersonInfo)Public Property ParametersAsDictionary(OfString, Object) = New Dictionary(OfString, Object)()ProtectedOverridesAsync Function OnInitializedAsync() AsTask persons = New List(OfPersonInfo) From { New PersonInfoWith {.Name = "Alice", .Title = "Mrs.", .Description = "Software Engineer"}, New PersonInfoWith {.Name = "Bob", .Title = "Mr.", .Description = "Software Engineer"}, New PersonInfoWith {.Name = "Charlie", .Title = "Mr.", .Description = "Software Engineer"} }End FunctionPrivateAsync Sub PrintToPdf() Dim renderer As New ChromePdfRenderer() ' Apply text footer renderer.RenderingOptions.TextFooter = New TextHeaderFooter() With { .LeftText = "{date} - {time}", .DrawDividerLine = True, .RightText = "Page {page} of {total-pages}", .Font = IronSoftware.Drawing.FontTypes.Arial, .FontSize = 11 }Parameters.Add("persons", persons) ' Render razor component to PDF Dim pdf AsPdfDocument = renderer.RenderRazorComponentToPdf(OfPerson)(Parameters)File.WriteAllBytes("razorComponentToPdf.pdf", pdf.BinaryData)End Sub
<Parameter>
Public Property persons As IEnumerable(Of PersonInfo)
Public Property Parameters As Dictionary(Of String, Object) = New Dictionary(Of String, Object)()
Protected Overrides Async Function OnInitializedAsync() As Task
persons = New List(Of PersonInfo) From {
New PersonInfo With {.Name = "Alice", .Title = "Mrs.", .Description = "Software Engineer"},
New PersonInfo With {.Name = "Bob", .Title = "Mr.", .Description = "Software Engineer"},
New PersonInfo With {.Name = "Charlie", .Title = "Mr.", .Description = "Software Engineer"}
}
End Function
Private Async Sub PrintToPdf()
Dim renderer As New ChromePdfRenderer()
' Apply text footer
renderer.RenderingOptions.TextFooter = New TextHeaderFooter() With {
.LeftText = "{date} - {time}",
.DrawDividerLine = True,
.RightText = "Page {page} of {total-pages}",
.Font = IronSoftware.Drawing.FontTypes.Arial,
.FontSize = 11
}
Parameters.Add("persons", persons)
' Render razor component to PDF
Dim pdf As PdfDocument = renderer.RenderRazorComponentToPdf(Of Person)(Parameters)
File.WriteAllBytes("razorComponentToPdf.pdf", pdf.BinaryData)
End Sub
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
CSHTML to PDF
Converting CSHTML (Razor) to PDF allows you to generate professional, print-ready documents directly from your web applications. This is useful for invoices, reports, contracts, or any dynamic content. IronPDF supports Razor Pages, MVC Core, and MVC Framework, as well as headless rendering, making it seamless to integrate PDF generation into your .NET applications with just a few lines of code.
CSHTML to PDF (Razor Pages)
using IronPdf.Razor.Pages;public IActionResultOnPostAsync(){ persons = new List<Person> { new Person { Name = "Alice", Title = "Mrs.", Description = "Software Engineer" }, new Person { Name = "Bob", Title = "Mr.", Description = "Software Engineer" }, new Person { Name = "Charlie", Title = "Mr.", Description = "Software Engineer" } };ViewData["personList"] = persons; ChromePdfRenderer renderer = new ChromePdfRenderer(); // Render Razor Page to PDF document PdfDocument pdf = renderer.RenderRazorToPdf(this);Response.Headers.Add("Content-Disposition", "inline"); returnFile(pdf.BinaryData, "application/pdf", "razorPageToPdf.pdf");}
using IronPdf.Razor.Pages;
public IActionResult OnPostAsync()
{
persons = new List<Person>
{
new Person { Name = "Alice", Title = "Mrs.", Description = "Software Engineer" },
new Person { Name = "Bob", Title = "Mr.", Description = "Software Engineer" },
new Person { Name = "Charlie", Title = "Mr.", Description = "Software Engineer" }
};
ViewData["personList"] = persons;
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Render Razor Page to PDF document
PdfDocument pdf = renderer.RenderRazorToPdf(this);
Response.Headers.Add("Content-Disposition", "inline");
return File(pdf.BinaryData, "application/pdf", "razorPageToPdf.pdf");
}
ImportsIronPdf.Razor.PagesPublic Function OnPostAsync() AsIActionResult persons = New List(OfPerson) From { New PersonWith {.Name = "Alice", .Title = "Mrs.", .Description = "Software Engineer"}, New PersonWith {.Name = "Bob", .Title = "Mr.", .Description = "Software Engineer"}, New PersonWith {.Name = "Charlie", .Title = "Mr.", .Description = "Software Engineer"} }ViewData("personList") = persons Dim renderer As New ChromePdfRenderer() ' Render Razor Page to PDF document Dim pdf AsPdfDocument = renderer.RenderRazorToPdf(Me) Response.Headers.Add("Content-Disposition", "inline") ReturnFile(pdf.BinaryData, "application/pdf", "razorPageToPdf.pdf")End Function
Imports IronPdf.Razor.Pages
Public Function OnPostAsync() As IActionResult
persons = New List(Of Person) From {
New Person With {.Name = "Alice", .Title = "Mrs.", .Description = "Software Engineer"},
New Person With {.Name = "Bob", .Title = "Mr.", .Description = "Software Engineer"},
New Person With {.Name = "Charlie", .Title = "Mr.", .Description = "Software Engineer"}
}
ViewData("personList") = persons
Dim renderer As New ChromePdfRenderer()
' Render Razor Page to PDF document
Dim pdf As PdfDocument = renderer.RenderRazorToPdf(Me)
Response.Headers.Add("Content-Disposition", "inline")
Return File(pdf.BinaryData, "application/pdf", "razorPageToPdf.pdf")
End Function
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
CSHTML to PDF (MVC Core)
public async Task<IActionResult> Persons(){ var persons = new List<Person> { new Person { Name = "Alice", Title = "Mrs.", Description = "Software Engineer" }, new Person { Name = "Bob", Title = "Mr.", Description = "Software Engineer" }, new Person { Name = "Charlie", Title = "Mr.", Description = "Software Engineer" } }; if (_httpContextAccessor.HttpContext.Request.Method == HttpMethod.Post.Method) { ChromePdfRenderer renderer = new ChromePdfRenderer(); // Render View to PDF document PdfDocument pdf = renderer.RenderRazorViewToPdf(_viewRenderService, "Views/Home/Persons.cshtml", persons);Response.Headers.Add("Content-Disposition", "inline"); // Output PDF document returnFile(pdf.BinaryData, "application/pdf", "viewToPdfMVCCore.pdf"); } returnView(persons);}
public async Task<IActionResult> Persons()
{
var persons = new List<Person>
{
new Person { Name = "Alice", Title = "Mrs.", Description = "Software Engineer" },
new Person { Name = "Bob", Title = "Mr.", Description = "Software Engineer" },
new Person { Name = "Charlie", Title = "Mr.", Description = "Software Engineer" }
};
if (_httpContextAccessor.HttpContext.Request.Method == HttpMethod.Post.Method)
{
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Render View to PDF document
PdfDocument pdf = renderer.RenderRazorViewToPdf(_viewRenderService, "Views/Home/Persons.cshtml", persons);
Response.Headers.Add("Content-Disposition", "inline");
// Output PDF document
return File(pdf.BinaryData, "application/pdf", "viewToPdfMVCCore.pdf");
}
return View(persons);
}
PublicAsync Function Persons() AsTask(OfIActionResult) Dim persons = New List(OfPerson) From { New PersonWith {.Name = "Alice", .Title = "Mrs.", .Description = "Software Engineer"}, New PersonWith {.Name = "Bob", .Title = "Mr.", .Description = "Software Engineer"}, New PersonWith {.Name = "Charlie", .Title = "Mr.", .Description = "Software Engineer"} } If _httpContextAccessor.HttpContext.Request.Method = HttpMethod.Post.MethodThen Dim renderer As New ChromePdfRenderer() ' Render View to PDF document Dim pdf AsPdfDocument = renderer.RenderRazorViewToPdf(_viewRenderService, "Views/Home/Persons.cshtml", persons) Response.Headers.Add("Content-Disposition", "inline") ' Output PDF document ReturnFile(pdf.BinaryData, "application/pdf", "viewToPdfMVCCore.pdf") End If ReturnView(persons)End Function
Public Async Function Persons() As Task(Of IActionResult)
Dim persons = New List(Of Person) From {
New Person With {.Name = "Alice", .Title = "Mrs.", .Description = "Software Engineer"},
New Person With {.Name = "Bob", .Title = "Mr.", .Description = "Software Engineer"},
New Person With {.Name = "Charlie", .Title = "Mr.", .Description = "Software Engineer"}
}
If _httpContextAccessor.HttpContext.Request.Method = HttpMethod.Post.Method Then
Dim renderer As New ChromePdfRenderer()
' Render View to PDF document
Dim pdf As PdfDocument = renderer.RenderRazorViewToPdf(_viewRenderService, "Views/Home/Persons.cshtml", persons)
Response.Headers.Add("Content-Disposition", "inline")
' Output PDF document
Return File(pdf.BinaryData, "application/pdf", "viewToPdfMVCCore.pdf")
End If
Return View(persons)
End Function
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
CSHTML to PDF (MVC Framework)
public ActionResultPersons(){ var persons = new List<Person> { new Person { Name = "Alice", Title = "Mrs.", Description = "Software Engineer" }, new Person { Name = "Bob", Title = "Mr.", Description = "Software Engineer" }, new Person { Name = "Charlie", Title = "Mr.", Description = "Software Engineer" } }; if (HttpContext.Request.HttpMethod == "POST") { // Provide the path to your view file var viewPath = "~/Views/Home/Persons.cshtml"; ChromePdfRenderer renderer = new ChromePdfRenderer(); // Render Razor view to PDF document PdfDocument pdf = renderer.RenderView(this.HttpContext, viewPath, persons);Response.Headers.Add("Content-Disposition", "inline"); // View the PDF returnFile(pdf.BinaryData, "application/pdf"); } returnView(persons);}
public ActionResult Persons()
{
var persons = new List<Person>
{
new Person { Name = "Alice", Title = "Mrs.", Description = "Software Engineer" },
new Person { Name = "Bob", Title = "Mr.", Description = "Software Engineer" },
new Person { Name = "Charlie", Title = "Mr.", Description = "Software Engineer" }
};
if (HttpContext.Request.HttpMethod == "POST")
{
// Provide the path to your view file
var viewPath = "~/Views/Home/Persons.cshtml";
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Render Razor view to PDF document
PdfDocument pdf = renderer.RenderView(this.HttpContext, viewPath, persons);
Response.Headers.Add("Content-Disposition", "inline");
// View the PDF
return File(pdf.BinaryData, "application/pdf");
}
return View(persons);
}
Public Function Persons() AsActionResult Dim persons = New List(OfPerson) From { New PersonWith {.Name = "Alice", .Title = "Mrs.", .Description = "Software Engineer"}, New PersonWith {.Name = "Bob", .Title = "Mr.", .Description = "Software Engineer"}, New PersonWith {.Name = "Charlie", .Title = "Mr.", .Description = "Software Engineer"} } IfHttpContext.Request.HttpMethod = "POST" Then ' Provide the path to your view file Dim viewPath = "~/Views/Home/Persons.cshtml" Dim renderer As New ChromePdfRenderer() ' Render Razor view to PDF document Dim pdf AsPdfDocument = renderer.RenderView(Me.HttpContext, viewPath, persons) Response.Headers.Add("Content-Disposition", "inline") ' View the PDF ReturnFile(pdf.BinaryData, "application/pdf") End If ReturnView(persons)End Function
Public Function Persons() As ActionResult
Dim persons = New List(Of Person) From {
New Person With {.Name = "Alice", .Title = "Mrs.", .Description = "Software Engineer"},
New Person With {.Name = "Bob", .Title = "Mr.", .Description = "Software Engineer"},
New Person With {.Name = "Charlie", .Title = "Mr.", .Description = "Software Engineer"}
}
If HttpContext.Request.HttpMethod = "POST" Then
' Provide the path to your view file
Dim viewPath = "~/Views/Home/Persons.cshtml"
Dim renderer As New ChromePdfRenderer()
' Render Razor view to PDF document
Dim pdf As PdfDocument = renderer.RenderView(Me.HttpContext, viewPath, persons)
Response.Headers.Add("Content-Disposition", "inline")
' View the PDF
Return File(pdf.BinaryData, "application/pdf")
End If
Return View(persons)
End Function
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
CSHTML to PDF (Headlessly)
app.MapGet("/PrintPdf", async () =>{ // Set your IronPDF license keyIronPdf.License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01"; // Enable detailed logging for troubleshootingIronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All; // Render the Razor view to an HTML string string html = awaitRazorTemplateEngine.RenderAsync("Views/Home/Data.cshtml"); // Create a new instance of ChromePdfRenderer ChromePdfRenderer renderer = new ChromePdfRenderer(); // Render the HTML string as a PDF document PdfDocument pdf = renderer.RenderHtmlAsPdf(html, "./wwwroot"); // Return the PDF file as a response returnResults.File(pdf.BinaryData, "application/pdf", "razorViewToPdf.pdf");});
app.MapGet("/PrintPdf", async () =>
{
// Set your IronPDF license key
IronPdf.License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01";
// Enable detailed logging for troubleshooting
IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All;
// Render the Razor view to an HTML string
string html = await RazorTemplateEngine.RenderAsync("Views/Home/Data.cshtml");
// Create a new instance of ChromePdfRenderer
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Render the HTML string as a PDF document
PdfDocument pdf = renderer.RenderHtmlAsPdf(html, "./wwwroot");
// Return the PDF file as a response
return Results.File(pdf.BinaryData, "application/pdf", "razorViewToPdf.pdf");
});
ImportsIronPdfImportsMicrosoft.AspNetCore.Httpapp.MapGet("/PrintPdf", Async Function() AsTask(OfIResult) ' Set your IronPDF license keyIronPdf.License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01" ' Enable detailed logging for troubleshootingIronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All ' Render the Razor view to an HTML string Dim html AsString = AwaitRazorTemplateEngine.RenderAsync("Views/Home/Data.cshtml") ' Create a new instance of ChromePdfRenderer Dim renderer As New ChromePdfRenderer() ' Render the HTML string as a PDF document Dim pdf AsPdfDocument = renderer.RenderHtmlAsPdf(html, "./wwwroot") ' Return the PDF file as a response ReturnResults.File(pdf.BinaryData, "application/pdf", "razorViewToPdf.pdf")End Function)
Imports IronPdf
Imports Microsoft.AspNetCore.Http
app.MapGet("/PrintPdf", Async Function() As Task(Of IResult)
' Set your IronPDF license key
IronPdf.License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01"
' Enable detailed logging for troubleshooting
IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All
' Render the Razor view to an HTML string
Dim html As String = Await RazorTemplateEngine.RenderAsync("Views/Home/Data.cshtml")
' Create a new instance of ChromePdfRenderer
Dim renderer As New ChromePdfRenderer()
' Render the HTML string as a PDF document
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf(html, "./wwwroot")
' Return the PDF file as a response
Return Results.File(pdf.BinaryData, "application/pdf", "razorViewToPdf.pdf")
End Function)
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
My favorite library of this kind is IronPDF. It allows for fast and efficient manipulation of PDF files. It also has many valuable features, like exporting to PDF/A format and digitally signing PDF documents.
IronOCR means we can save $40,000 annually from manual processing, while enhancing productivity and freeing up resources for high-impact tasks. I would highly recommend it.
The IronSuite play a crucial role in our operations. These are tools that increase efficiencies across the business including creating floor plans and improving inventory management.
IronPDF offers an easy solution for converting web pages that require authentication. With its rendering options, users can bypass HTTP authentication by setting the renderer's LoginCredentials property to a ChromeHttpLoginCredentials object.
using IronPdf;using System;ChromePdfRenderer renderer = new ChromePdfRenderer{ // setting login credentials to bypass basic authenticationLoginCredentials = new ChromeHttpLoginCredentials() {NetworkUsername = "testUser",NetworkPassword = "testPassword" }};var uri = new Uri("http://localhost:51169/Invoice");// Render web URL to PDFPdfDocument pdf = renderer.RenderUrlAsPdf(uri);// Export PDFpdf.SaveAs("UrlToPdfExample.Pdf");
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");
ImportsIronPdfImportsSystemPrivate renderer As New ChromePdfRendererWith { .LoginCredentials = New ChromeHttpLoginCredentials() With { .NetworkUsername = "testUser", .NetworkPassword = "testPassword" }}Private uri = New Uri("http://localhost:51169/Invoice")' Render web URL to PDFPrivate pdf AsPdfDocument = renderer.RenderUrlAsPdf(uri)' Export PDFpdf.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")
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
Cookies
Apply cookies to the additional login request to ensure your session is saved! This will make it easier to render additional resources within the locked domain, all within IronPDF.
using IronPdf;// Instantiate ChromePdfRendererChromePdfRenderer renderer = new ChromePdfRenderer();renderer.RenderingOptions.RequestContext = IronPdf.Rendering.RequestContexts.Global;ChromeHttpLoginCredentials credentials = new ChromeHttpLoginCredentials() {NetworkUsername = "testUser",NetworkPassword = "testPassword"};string uri = "http://localhost:51169/Invoice";// Apply cookiesrenderer.ApplyCookies(uri, credentials);
using IronPdf;
// Instantiate ChromePdfRenderer
ChromePdfRenderer renderer = new ChromePdfRenderer();
renderer.RenderingOptions.RequestContext = IronPdf.Rendering.RequestContexts.Global;
ChromeHttpLoginCredentials credentials = new ChromeHttpLoginCredentials() {
NetworkUsername = "testUser",
NetworkPassword = "testPassword"
};
string uri = "http://localhost:51169/Invoice";
// Apply cookies
renderer.ApplyCookies(uri, credentials);
ImportsIronPdf' Instantiate ChromePdfRendererPrivate renderer As New ChromePdfRenderer()renderer.RenderingOptions.RequestContext = IronPdf.Rendering.RequestContexts.GlobalDim credentials As New ChromeHttpLoginCredentials() With { .NetworkUsername = "testUser", .NetworkPassword = "testPassword"}Dim uri AsString = "http://localhost:51169/Invoice"' Apply cookiesrenderer.ApplyCookies(uri, credentials)
Imports IronPdf
' Instantiate ChromePdfRenderer
Private renderer As New ChromePdfRenderer()
renderer.RenderingOptions.RequestContext = IronPdf.Rendering.RequestContexts.Global
Dim credentials As New ChromeHttpLoginCredentials() With {
.NetworkUsername = "testUser",
.NetworkPassword = "testPassword"
}
Dim uri As String = "http://localhost:51169/Invoice"
' Apply cookies
renderer.ApplyCookies(uri, credentials)
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
HTTP Request Header
Aside from cookies, IronPDF also allows users to customize their HTTP request header with authorization tokens and other common-related fields.
using IronPdf;using System.Collections.Generic;var renderer = new ChromePdfRenderer();renderer.RenderingOptions.HttpRequestHeaders = new Dictionary<string, string>{ { "Authorization", "Bearer test-token-123" }};// Render PDF from authenticated pagevar pdf = renderer.RenderUrlAsPdf("https://httpbin.org/bearer");pdf.SaveAs("output.pdf");
using IronPdf;
using System.Collections.Generic;
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.HttpRequestHeaders = new Dictionary<string, string>
{
{ "Authorization", "Bearer test-token-123" }
};
// Render PDF from authenticated page
var pdf = renderer.RenderUrlAsPdf("https://httpbin.org/bearer");
pdf.SaveAs("output.pdf");
ImportsIronPdfImportsSystem.Collections.GenericDim renderer = New ChromePdfRenderer()renderer.RenderingOptions.HttpRequestHeaders = New Dictionary(OfString, String) From { {"Authorization", "Bearer test-token-123"}}' Render PDF from authenticated pageDim pdf = renderer.RenderUrlAsPdf("https://httpbin.org/bearer")pdf.SaveAs("output.pdf")
Imports IronPdf
Imports System.Collections.Generic
Dim renderer = New ChromePdfRenderer()
renderer.RenderingOptions.HttpRequestHeaders = New Dictionary(Of String, String) From {
{"Authorization", "Bearer test-token-123"}
}
' Render PDF from authenticated page
Dim pdf = renderer.RenderUrlAsPdf("https://httpbin.org/bearer")
pdf.SaveAs("output.pdf")
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
Tailored Your PDF Conversion
Rendering Options
IronPDF allows users to customize the appearance and format of their generated PDFs. The ChromePdfRenderer class that is used to convert various inputs into PDFs also includes the RenderingOptions property, letting users control how the output looks.
using IronPdf;// Instantiate a ChromePdfRenderer object, which uses a headless version of the Chrome browser// to render HTML/CSS as a PDF document.ChromePdfRenderer renderer = new ChromePdfRenderer();// Configure rendering options// Enable printing of HTML backgrounds to ensure all styles are visible.renderer.RenderingOptions.PrintHtmlBackgrounds = true;// Set HTML header content using HtmlHeaderFooter.renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter{ // HTML fragment to add a header at the top of every page in the PDF.HtmlFragment = "<h1>Header Content</h1>"};// Set a custom paper size for the PDF in millimeters (width and height).renderer.RenderingOptions.SetCustomPaperSizeinMilimeters(150, 150);// Set the top margin to zero to start the content from the very top of the page.renderer.RenderingOptions.MarginTop = 0;// Define a Markdown string that will be rendered as a PDF.// Markdown text allows basic formatting like bold and italic styles.string md = "This is some **bold** and *italic* text.";// Render the Markdown string to a PDF document.// The library will convert Markdown syntax into equivalent HTML before rendering it as a PDF.PdfDocument pdf = renderer.RenderMarkdownStringAsPdf(md);// Save the generated PDF to a file named "renderingOptions.pdf."pdf.SaveAs("renderingOptions.pdf");
using IronPdf;
// Instantiate a ChromePdfRenderer object, which uses a headless version of the Chrome browser
// to render HTML/CSS as a PDF document.
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Configure rendering options
// Enable printing of HTML backgrounds to ensure all styles are visible.
renderer.RenderingOptions.PrintHtmlBackgrounds = true;
// Set HTML header content using HtmlHeaderFooter.
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter
{
// HTML fragment to add a header at the top of every page in the PDF.
HtmlFragment = "<h1>Header Content</h1>"
};
// Set a custom paper size for the PDF in millimeters (width and height).
renderer.RenderingOptions.SetCustomPaperSizeinMilimeters(150, 150);
// Set the top margin to zero to start the content from the very top of the page.
renderer.RenderingOptions.MarginTop = 0;
// Define a Markdown string that will be rendered as a PDF.
// Markdown text allows basic formatting like bold and italic styles.
string md = "This is some **bold** and *italic* text.";
// Render the Markdown string to a PDF document.
// The library will convert Markdown syntax into equivalent HTML before rendering it as a PDF.
PdfDocument pdf = renderer.RenderMarkdownStringAsPdf(md);
// Save the generated PDF to a file named "renderingOptions.pdf."
pdf.SaveAs("renderingOptions.pdf");
ImportsIronPdf' Instantiate a ChromePdfRenderer object, which uses a headless version of the Chrome browser' to render HTML/CSS as a PDF document.Private renderer As New ChromePdfRenderer()' Configure rendering options' Enable printing of HTML backgrounds to ensure all styles are visible.renderer.RenderingOptions.PrintHtmlBackgrounds = True' Set HTML header content using HtmlHeaderFooter.renderer.RenderingOptions.HtmlHeader = New HtmlHeaderFooterWith {.HtmlFragment = "<h1>Header Content</h1>"}' Set a custom paper size for the PDF in millimeters (width and height).renderer.RenderingOptions.SetCustomPaperSizeinMilimeters(150, 150)' Set the top margin to zero to start the content from the very top of the page.renderer.RenderingOptions.MarginTop = 0' Define a Markdown string that will be rendered as a PDF.' Markdown text allows basic formatting like bold and italic styles.Dim md AsString = "This is some **bold** and *italic* text."' Render the Markdown string to a PDF document.' The library will convert Markdown syntax into equivalent HTML before rendering it as a PDF.Dim pdf AsPdfDocument = renderer.RenderMarkdownStringAsPdf(md)' Save the generated PDF to a file named "renderingOptions.pdf."pdf.SaveAs("renderingOptions.pdf")
Imports IronPdf
' Instantiate a ChromePdfRenderer object, which uses a headless version of the Chrome browser
' to render HTML/CSS as a PDF document.
Private renderer As New ChromePdfRenderer()
' Configure rendering options
' Enable printing of HTML backgrounds to ensure all styles are visible.
renderer.RenderingOptions.PrintHtmlBackgrounds = True
' Set HTML header content using HtmlHeaderFooter.
renderer.RenderingOptions.HtmlHeader = New HtmlHeaderFooter With {.HtmlFragment = "<h1>Header Content</h1>"}
' Set a custom paper size for the PDF in millimeters (width and height).
renderer.RenderingOptions.SetCustomPaperSizeinMilimeters(150, 150)
' Set the top margin to zero to start the content from the very top of the page.
renderer.RenderingOptions.MarginTop = 0
' Define a Markdown string that will be rendered as a PDF.
' Markdown text allows basic formatting like bold and italic styles.
Dim md As String = "This is some **bold** and *italic* text."
' Render the Markdown string to a PDF document.
' The library will convert Markdown syntax into equivalent HTML before rendering it as a PDF.
Dim pdf As PdfDocument = renderer.RenderMarkdownStringAsPdf(md)
' Save the generated PDF to a file named "renderingOptions.pdf."
pdf.SaveAs("renderingOptions.pdf")
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
Set Custom Margin
You can further tailor the appearance of your output PDF by adjusting the margins, allowing you to control the layout and spacing precisely.
Dim renderer As New ChromePdfRenderer()renderer.RenderingOptions.MarginTop = 40renderer.RenderingOptions.MarginLeft = 20renderer.RenderingOptions.MarginRight = 20renderer.RenderingOptions.MarginBottom = 40
Dim renderer As New ChromePdfRenderer()
renderer.RenderingOptions.MarginTop = 40
renderer.RenderingOptions.MarginLeft = 20
renderer.RenderingOptions.MarginRight = 20
renderer.RenderingOptions.MarginBottom = 40
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
Grayscale
To generate a grayscale PDF, we set the GrayScale property within RenderingOptions to true.
using IronPdf;ChromePdfRenderer renderer = new ChromePdfRenderer();// Set GrayScale to truerenderer.RenderingOptions.GrayScale = true;PdfDocument pdf = renderer.RenderUrlAsPdf("https://ironsoftware.com/");pdf.CopyPage(0).SaveAs("test.pdf");
using IronPdf;
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Set GrayScale to true
renderer.RenderingOptions.GrayScale = true;
PdfDocument pdf = renderer.RenderUrlAsPdf("https://ironsoftware.com/");
pdf.CopyPage(0).SaveAs("test.pdf");
ImportsIronPdfDim renderer As New ChromePdfRenderer()' Set GrayScale to truerenderer.RenderingOptions.GrayScale = TrueDim pdf AsPdfDocument = renderer.RenderUrlAsPdf("https://ironsoftware.com/")pdf.CopyPage(0).SaveAs("test.pdf")
Imports IronPdf
Dim renderer As New ChromePdfRenderer()
' Set GrayScale to true
renderer.RenderingOptions.GrayScale = True
Dim pdf As PdfDocument = renderer.RenderUrlAsPdf("https://ironsoftware.com/")
pdf.CopyPage(0).SaveAs("test.pdf")
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
Refine Your PDF Layout
Add a Table of Contents
Create a dynamic table of contents with IronPDF to help readers easily navigate your document. IronPDF automatically handles the table of contents with hyperlinks to headers such as h1 and h2. Along with that, you can also customize the styling of the table of contents with HTML and CSS styling.
using IronPdf;// Instantiate RendererChromePdfRenderer renderer = new ChromePdfRenderer();// Configure render optionsrenderer.RenderingOptions = new ChromePdfRenderOptions{ // Enable table of content featureTableOfContents = TableOfContentsTypes.WithPageNumbers,};PdfDocument pdf = renderer.RenderHtmlFileAsPdf("tableOfContent.html");pdf.SaveAs("tableOfContents.pdf");
using IronPdf;
// Instantiate Renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Configure render options
renderer.RenderingOptions = new ChromePdfRenderOptions
{
// Enable table of content feature
TableOfContents = TableOfContentsTypes.WithPageNumbers,
};
PdfDocument pdf = renderer.RenderHtmlFileAsPdf("tableOfContent.html");
pdf.SaveAs("tableOfContents.pdf");
ImportsIronPdf' Instantiate RendererPrivate renderer As New ChromePdfRenderer()' Configure render optionsrenderer.RenderingOptions = New ChromePdfRenderOptionsWith {.TableOfContents = TableOfContentsTypes.WithPageNumbers}Dim pdf AsPdfDocument = renderer.RenderHtmlFileAsPdf("tableOfContent.html")pdf.SaveAs("tableOfContents.pdf")
Imports IronPdf
' Instantiate Renderer
Private renderer As New ChromePdfRenderer()
' Configure render options
renderer.RenderingOptions = New ChromePdfRenderOptions With {.TableOfContents = TableOfContentsTypes.WithPageNumbers}
Dim pdf As PdfDocument = renderer.RenderHtmlFileAsPdf("tableOfContent.html")
pdf.SaveAs("tableOfContents.pdf")
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
Page Break
Add page breaks between sections to clearly separate content and improve the readability of your document. With IronPDF, simply use the HTML div style= page-break-after to achieve that effect.
using IronPdf;const string html = @" <table style='border: 1px solid #000000'> <tr> <th>Company</th> <th>Product</th> </tr> <tr> <td>Iron Software</td> <td>IronPDF</td> </tr> <tr> <td>Iron Software</td> <td>IronOCR</td> </tr> </table> <div style='page-break-after: always;'> </div> <img src='https://ironpdf.com/img/products/ironpdf-logo-text-dotnet.svg'>";var renderer = new ChromePdfRenderer();var pdf = renderer.RenderHtmlAsPdf(html);pdf.SaveAs("Page_Break.pdf");
using IronPdf;
const string html = @"
<table style='border: 1px solid #000000'>
<tr>
<th>Company</th>
<th>Product</th>
</tr>
<tr>
<td>Iron Software</td>
<td>IronPDF</td>
</tr>
<tr>
<td>Iron Software</td>
<td>IronOCR</td>
</tr>
</table>
<div style='page-break-after: always;'> </div>
<img src='https://ironpdf.com/img/products/ironpdf-logo-text-dotnet.svg'>";
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("Page_Break.pdf");
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
Fit to Page & Zoom
Need help deciding the dimensions of the content to fit a specified paper size? IronPDF has you covered with the UseChromeDefault, which mimics how Google Chrome's print preview scales content to fit the page.
using IronPdf;ChromePdfRenderer renderer = new ChromePdfRenderer();// Chrome default renderingrenderer.RenderingOptions.PaperFit.UseChromeDefaultRendering();// Render web URL to PDFPdfDocument pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page");pdf.SaveAs("chromeDefault.pdf");
using IronPdf;
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Chrome default rendering
renderer.RenderingOptions.PaperFit.UseChromeDefaultRendering();
// Render web URL to PDF
PdfDocument pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page");
pdf.SaveAs("chromeDefault.pdf");
ImportsIronPdfPrivate renderer As New ChromePdfRenderer()' Chrome default renderingrenderer.RenderingOptions.PaperFit.UseChromeDefaultRendering()' Render web URL to PDFDim pdf AsPdfDocument = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page")pdf.SaveAs("chromeDefault.pdf")
Imports IronPdf
Private renderer As New ChromePdfRenderer()
' Chrome default rendering
renderer.RenderingOptions.PaperFit.UseChromeDefaultRendering()
' Render web URL to PDF
Dim pdf As PdfDocument = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page")
pdf.SaveAs("chromeDefault.pdf")
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.
Conclusion
The examples above showcase the impressive capabilities and standout features you can unlock while converting various formats to PDFs using IronPDF.
If you would like to request a feature or have general questions about IronPDF or licensing, please contact our support team. We will be more than happy to assist you.
Frequently Asked Questions
How can I convert HTML to PDF using IronPDF in C# .NET?
You can use the IronPdf.ChromePdfRenderer class and its RenderHtmlAsPdf method to render HTML as a PDF document in C# .NET. For example, you can use `var pdf = new IronPdf.ChromePdfRenderer().RenderHtmlAsPdf("
Hello, PDF!
");` to convert HTML content directly to a PDF.
Does IronPDF support converting dynamic web pages to PDFs?
Yes, IronPDF supports converting dynamic web pages built with frameworks like Razor, CSHTML, ASPX, and XAML to PDF while maintaining layout and formatting integrity.
What customization options does IronPDF offer for PDF conversion?
IronPDF provides various customization options, including setting margins, headers, footers, page numbers, and greyscale settings. You can also add features like a table of contents and automatic page breaks.
Is it possible to apply security features like AES-256 during PDF conversion with IronPDF?
Yes, IronPDF allows the application of security features such as AES-256 encryption to secure your PDF documents during the conversion process.
How can I convert a URL to a PDF using IronPDF?
You can convert a URL to a PDF using IronPDF by using the RenderUrlAsPdf method of the ChromePdfRenderer class. Simply pass the URL as a parameter to the method.
Can IronPDF handle the conversion of images to PDFs?
Yes, IronPDF can convert images to PDFs using the ImageToPdfConverter class and the ImageToPdf method, facilitating easy conversion of visual content into PDF format.
Does IronPDF allow conversion from PDF back to HTML?
Yes, IronPDF supports converting PDFs back to HTML with a straightforward process, allowing you to manipulate PDF content within an HTML format.
How do I convert DOCX files to PDF using IronPDF?
Using IronPDF, you can convert DOCX files to PDF with the RenderDocxAsPDF method from the DocxToPdfRenderer class, which allows you to save the converted document as a PDF easily.
What file formats can IronPDF convert to PDF besides HTML?
IronPDF can convert a variety of file formats to PDF, including DOCX, RTF, Markdown (MD), XML, and more, making it versatile for different document types.
How does IronPDF improve performance for PDF generation in Docker environments?
IronPDF is optimized for performance in Docker environments by allowing developers to set custom rendering options and use virtual display for headless operations, enhancing efficiency and speed.
Jacob Mellor is Chief Technology Officer at Iron Software and a visionary engineer pioneering C# PDF technology. As the original developer behind Iron Software's core codebase, he has shaped the company's product architecture since its inception, transforming it alongside CEO Cameron Rimington into a 50+ person company serving NASA, Tesla, and global government agencies.