C# + VB.Net: HTML to PDF HTML to PDF
using IronPdf;

IronPdf.HtmlToPdf Renderer = new IronPdf.HtmlToPdf();

// Render an HTML document or snippet as a string
Renderer.RenderHtmlAsPdf("<h1>Hello World</h1>").SaveAs("html-string.pdf");


// Advanced: 
// Set a "base url" or file path so that images, javascript and CSS can be loaded  
var PDF = Renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>",@"C:\site\assets\");
PDF.SaveAs("html-with-assets.pdf");
Imports IronPdf



Dim Renderer As New IronPdf.HtmlToPdf()

' Render an HTML document or snippet as a string
Renderer.RenderHtmlAsPdf("<h1>Hello World</h1>").SaveAs("html-string.pdf")


' Advanced: 
' Set a "base url" or file path so that images, javascript and CSS can be loaded  
Dim PDF = Renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>","C:\site\assets\")
PDF.SaveAs("html-with-assets.pdf")

IronPDF allows developers to create PDF documents easily in C#, F#, and VB.Net for .NET Core and .NET Framework. In this example we show that a PDF document can be rendered using HTML. You can choose simple HTML like the above, or incorporate CSS, images and Javascript. IronPDF rendering closely follows Google Chrome.

C# + VB.Net: Url to a PDF Url to a PDF
using IronPdf;

IronPdf.HtmlToPdf Renderer = new IronPdf.HtmlToPdf();
Renderer.RenderUrlAsPdf("http//ironpdf.com/").SaveAs("url.pdf");



// or System.IO.MemoryStream PdfStream = PDF.GetStream;
// or byte[] PdfBinary = PDF.GetBinary;
Imports IronPdf



Dim Renderer As New IronPdf.HtmlToPdf()
Renderer.RenderUrlAsPdf("http//ironpdf.com/").SaveAs("url.pdf")



' or System.IO.MemoryStream PdfStream = PDF.GetStream;
' or byte[] PdfBinary = PDF.GetBinary;

IronPDF makes it very straightforward to render HTML from existing URLS as PDF documents. There is a very high level of support for Javascript, Images, Forms and CSS.

Rendering PDFs from ASP.NET URLS which accept query string variables can make PDF development an easy collaboration between designers and coders.

C# + VB.Net: ASPX Pages to PDF ASPX Pages to PDF
private void Form1_Load(object sender, EventArgs e)
{
IronPdf.AspxToPdf.RenderThisPageAsPDF();
//Changes the ASPX output into a pdf instead of html
}
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
IronPdf.AspxToPdf.RenderThisPageAsPDF()
'Changes the ASPX output into a pdf instead of html
End Sub

Using the IronPDF library, ASP.NET web pages can be rendered to PDF instead of HTML by adding a single line of code to the Form_Load event. This allows complex PDFS to be data driven, and designed and tested as HTML first for simplicity.

C# + VB.Net: HTML Files to PDF HTML Files to PDF
using IronPdf;

// Create a PDF from an existing HTML using C#
 var Renderer = new IronPdf.HtmlToPdf();
 var PDF = Renderer.RenderHTMLFileAsPdf("Assets/TestInvoice1.html");
 var OutputPath = "Invoice.pdf";
 PDF.SaveAs(OutputPath);
Imports IronPdf

' Create a PDF from an existing HTML using C#


 Dim Renderer = New IronPdf.HtmlToPdf()
 Dim PDF = Renderer.RenderHTMLFileAsPdf("Assets/TestInvoice1.html")
 Dim OutputPath = "Invoice.pdf"
 PDF.SaveAs(OutputPath)

We can also render any HTML file on our hard disk.

All relative assets such as CSS, images and js will be rendered as if the file had been opened using the file:// protocol.

This method has the advantage of allowing the developer the opportunity to test the HTML content in a browser during development. We recommend Chrome as being the web browser on which IronPDF's rendering engine is based.

C# + VB.Net: PDF Generation Settings PDF Generation Settings
using IronPdf;

IronPdf.HtmlToPdf Renderer = new IronPdf.HtmlToPdf();

Renderer.PrintOptions.SetCustomPaperSizeInInches(12.5, 20);
Renderer.PrintOptions.PrintHtmlBackgrounds = true;
Renderer.PrintOptions.PaperOrientation = PdfPrintOptions.PdfPaperOrientation.Portrait;
Renderer.PrintOptions.Title = "My PDF Document Name";
Renderer.PrintOptions.EnableJavaScript = true;
Renderer.PrintOptions.RenderDelay = 50; //ms
Renderer.PrintOptions.CssMediaType = PdfPrintOptions.PdfCssMediaType.Screen;
Renderer.PrintOptions.DPI = 300;
Renderer.PrintOptions.FitToPaperWidth = true;
Renderer.PrintOptions.JpegQuality = 80;
Renderer.PrintOptions.GrayScale = false;
Renderer.PrintOptions.FitToPaperWidth = true;
Renderer.PrintOptions.InputEncoding = Encoding.UTF8;
Renderer.PrintOptions.Zoom = 100;
Renderer.PrintOptions.CreatePdfFormsFromHtml = true;

Renderer.PrintOptions.MarginTop = 40;  //millimeters
Renderer.PrintOptions.MarginLeft = 20;  //millimeters
Renderer.PrintOptions.MarginRight = 20;  //millimeters
Renderer.PrintOptions.MarginBottom = 40;  //millimeters

Renderer.PrintOptions.FirstPageNumber = 1; //use 2 if a coverpage  will be appended

Renderer.RenderHTMLFileAsPdf("my-content.html").SaveAs("my-content.pdf");
Imports IronPdf



Dim Renderer As New IronPdf.HtmlToPdf()

Renderer.PrintOptions.SetCustomPaperSizeInInches(12.5, 20)
Renderer.PrintOptions.PrintHtmlBackgrounds = True
Renderer.PrintOptions.PaperOrientation = PdfPrintOptions.PdfPaperOrientation.Portrait
Renderer.PrintOptions.Title = "My PDF Document Name"
Renderer.PrintOptions.EnableJavaScript = True
Renderer.PrintOptions.RenderDelay = 50 'ms
Renderer.PrintOptions.CssMediaType = PdfPrintOptions.PdfCssMediaType.Screen
Renderer.PrintOptions.DPI = 300
Renderer.PrintOptions.FitToPaperWidth = True
Renderer.PrintOptions.JpegQuality = 80
Renderer.PrintOptions.GrayScale = False
Renderer.PrintOptions.FitToPaperWidth = True
Renderer.PrintOptions.InputEncoding = Encoding.UTF8
Renderer.PrintOptions.Zoom = 100
Renderer.PrintOptions.CreatePdfFormsFromHtml = True

Renderer.PrintOptions.MarginTop = 40 'millimeters
Renderer.PrintOptions.MarginLeft = 20 'millimeters
Renderer.PrintOptions.MarginRight = 20 'millimeters
Renderer.PrintOptions.MarginBottom = 40 'millimeters

Renderer.PrintOptions.FirstPageNumber = 1 'use 2 if a coverpage  will be appended

Renderer.RenderHTMLFileAsPdf("my-content.html").SaveAs("my-content.pdf")

IronPDF supports many customizations for generated PDF file formats including: Paper Sizes, Document output quality, Content Scaling, CSS 'media types' and JavaScript Support.

C# + VB.Net: ASPX To PDF Settings ASPX To PDF Settings
using IronPdf;

private void Form1_Load(object sender, EventArgs e)
{
    PdfPrintOptions PdfOptions = new PdfPrintOptions()
    {
        DPI = 300,
        EnableJavaScript = false,
        //.. many more options available
    };

AspxToPdf.RenderThisPageAsPDF(AspxToPdf.FileBehaviour.Attachment,"MyPdfFile.pdf", PdfOptions);
}
Imports IronPdf

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
	Dim PdfOptions As New PdfPrintOptions() With {
		.DPI = 300,
		.EnableJavaScript = False
	}

AspxToPdf.RenderThisPageAsPDF(AspxToPdf.FileBehaviour.Attachment,"MyPdfFile.pdf", PdfOptions)
End Sub

ASP.NET ASPX to PDF functionality allows the full set of options available when rendering HTML from a string or file, but allows adds 2 new options:
- Changing the PDF file Name
- Your PDF may be displayed directly in the web browser, or as a file download.

C# + VB.Net: Images To PDF Images To PDF
using IronPdf;
using System.IO;
using System.Linq;

// Select one or more images.  This example selects all JPEG images in a specific folder.
var ImageFiles = Directory.EnumerateFiles(@"C:\project\assets").Where(f => f.EndsWith(".jpg") || f.EndsWith(".jpeg"));

// Convert the images to a PDF and save it.
ImageToPdfConverter.ImageToPdf(ImageFiles).SaveAs(@"C:\project\composite.pdf");
            
//Also see PdfDocument.RasterizeToImageFiles() method to flatten a PDF to images or thumbnails
Imports IronPdf
Imports System.IO
Imports System.Linq
Dim ImageFiles As var = Directory.EnumerateFiles("C:\project\assets").Where(() => {  }, (f.EndsWith(".jpg") OrElse f.EndsWith(".jpeg")))
' Convert the images to a PDF and save it.
ImageToPdfConverter.ImageToPdf(ImageFiles).SaveAs("C:\project\composite.pdf")
'Also see PdfDocument.RasterizeToImageFiles() method to flatten a PDF to images or thumbnails

PDF documents can be easily constructed from one or more image files using the IronPdf.ImageToPdfConverter Class.

C# + VB.Net: Headers & Footers Headers & Footers
using IronPdf;

IronPdf.HtmlToPdf Renderer = new IronPdf.HtmlToPdf();

// add a header to every page easily
Renderer.PrintOptions.FirstPageNumber = 1; // use 2 if a coverpage  will be appended
Renderer.PrintOptions.Header.DrawDividerLine = true;
Renderer.PrintOptions.Header.CenterText = "{url}" ;
Renderer.PrintOptions.Header.FontFamily = "Helvetica,Arial";
Renderer.PrintOptions.Header.FontSize = 12;

// add a footer too
Renderer.PrintOptions.Footer.DrawDividerLine = true;
Renderer.PrintOptions.Footer.FontFamily = "Arial";
Renderer.PrintOptions.Footer.FontSize = 10;
Renderer.PrintOptions.Footer.LeftText = "{date} {time}";
Renderer.PrintOptions.Footer.RightText = "{page} of {total-pages}";

// mergable fields are:
// {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title}
Imports IronPdf
Dim Renderer As IronPdf.HtmlToPdf = New IronPdf.HtmlToPdf
' add a header to every page easily
Renderer.PrintOptions.FirstPageNumber = 1
' use 2 if a coverpage  will be appended
Renderer.PrintOptions.Header.DrawDividerLine = true
Renderer.PrintOptions.Header.CenterText = "{url}"
Renderer.PrintOptions.Header.FontFamily = "Helvetica,Arial"
Renderer.PrintOptions.Header.FontSize = 12
' add a footer too
Renderer.PrintOptions.Footer.DrawDividerLine = true
Renderer.PrintOptions.Footer.FontFamily = "Arial"
Renderer.PrintOptions.Footer.FontSize = 10
Renderer.PrintOptions.Footer.LeftText = "{date} {time}"
Renderer.PrintOptions.Footer.RightText = "{page} of {total-pages}"
' mergable fields are:
' {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title}

Headers and Footers may be added to PDF documents in 2 distinct ways.
- SimpleHeaderFooter allows text based headers to be added, with the option to merge in dynamic data.
- HtmlHeaderFooter allows the developer to render HTML headers and footers to PDF files, also allowing the templating of dynamic data.

C# + VB.Net: HTML Headers & Footers HTML Headers & Footers
using IronPdf;

IronPdf.HtmlToPdf Renderer = new IronPdf.HtmlToPdf();


// Build a footer using html to style the text
// mergable fields are:
// {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title}
Renderer.PrintOptions.Footer = new HtmlHeaderFooter()
{
  Height = 15,
  HtmlFragment = "<center><i>{page} of {total-pages}<i></center>",
  DrawDividerLine = true
 };

// Build a header using an image asset
// Note the use of BaseUrl to set a relative path to the assets
Renderer.PrintOptions.Header = new HtmlHeaderFooter()
{
  Height = 20,
  HtmlFragment = "<img src='logo.png'>",
  BaseUrl = new Uri(@"C:\assets\images\").AbsoluteUri
};
Imports IronPdf
Dim Renderer As IronPdf.HtmlToPdf = New IronPdf.HtmlToPdf
' Build a footer using html to style the text
' mergable fields are:
' {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title}
Renderer.PrintOptions.Footer = New HtmlHeaderFooter
' Build a header using an image asset
' Note the use of BaseUrl to set a relative path to the assets
Renderer.PrintOptions.Header = New HtmlHeaderFooter

HTML Headers and Footers are rendered as independent HTML documents which may have their own assets and stylesheets. Developers may control the Height of the rendered Header or Footer to match their content exactly.

C# + VB.Net: Editing PDFs Editing PDFs
using IronPdf;
using System.Collections.Generic;

var Renderer = new IronPdf.HtmlToPdf();

// Join Multiple Existing PDFs into a single document
var PDFs     = new List<PdfDocument>();
PDFs.Add(PdfDocument.FromFile("A.pdf"));
PDFs.Add(PdfDocument.FromFile("B.pdf"));
PDFs.Add(PdfDocument.FromFile("C.pdf"));
PdfDocument PDF =  PdfDocument.Merge(PDFs);
PDF.SaveAs("merged.pdf");

// Add a cover page
PDF.PrependPdf(Renderer.RenderHtmlAsPdf("<h1>Cover Page</h1><hr>"));

// Remove the last page from the PDF and save again
PDF.RemovePage(PDF.PageCount - 1);
PDF.SaveAs("merged.pdf");

// Copy pages 5-7 and save them as a new document.
PDF.CopyPages(4,6).SaveAs("exerpt.pdf");
Imports IronPdf
Imports System.Collections.Generic



Dim Renderer = New IronPdf.HtmlToPdf()

' Join Multiple Existing PDFs into a single document
Dim PDFs = New List(Of PdfDocument)()
PDFs.Add(PdfDocument.FromFile("A.pdf"))
PDFs.Add(PdfDocument.FromFile("B.pdf"))
PDFs.Add(PdfDocument.FromFile("C.pdf"))
Dim PDF As PdfDocument = PdfDocument.Merge(PDFs)
PDF.SaveAs("merged.pdf")

' Add a cover page
PDF.PrependPdf(Renderer.RenderHtmlAsPdf("<h1>Cover Page</h1><hr>"))

' Remove the last page from the PDF and save again
PDF.RemovePage(PDF.PageCount - 1)
PDF.SaveAs("merged.pdf")

' Copy pages 5-7 and save them as a new document.
PDF.CopyPages(4,6).SaveAs("exerpt.pdf")

IronPDF allows many PDF file editing manipulations. The most popular are merging, cloning and extracting pages.

PDF may also be watermarked, stamped and have backgrounds and foregrounds applied.

Human Support Directly From Our .Net Development Team

Whether its product, integration or licensing queries, the Iron product development team are on hand to support all of your questions. Get in touch and start a dialog with Iron to make the most of our C# PDF library in your project.

Ask a Question
C# .Net HTML-to-PDF

Convert HTML to PDF directly in C# and VB.Net

Avoid wasting time learning new APIs, proprietary software or time consuming programming patterns. IronPDF contains a fully licensed Google Chrome rendering engine for C# which can convert HTML pages or string to PDF documents with full support for Javascript, AJAX, images, SVG, Web Fonts and CSS.

Read Tutorial - 'How To Create PDF in C#'
C# .NET PDF OCR Library

Extract and Re-use PDF Text and Images

IronPDF allows you to automatically read pdf text using C# for injection into your C# & VB .NET Core or framework applications and date storage solutions. Import, migrate and index content from legacy PDF document storage into your document management and business process applications.

Read The Object Reference
How To Edit PDF Documents in C#

Elegant Tools to Edit PDF Documents in .NET Core
or Framework

From merging, to splitting, to editing PDFs, use your development skills to output exactly the right PDF at the right time. IronPDF puts a growing array of feature sets directly into your hands, inside your C# / VB ASP Dot Net Core or Framework PDF Project.

Clear Documentation
Convert HTML5, JS, CSS and Image files to PDF documents using  .Net Code.

Works With Documents You Already have

Point IronPDF at your existing HTML, ASPX forms, MVC views and image files to convert directly to PDF. This utilizes your existing assets and web pages to render your data in PDF format.

Get to Hello-World in 5 minutes
Visual Studio - C# Create PDF .Net Library - for PDF Creation and Content Editing.

Rapid Installation With Microsoft Visual Studio

IronPDF puts PDF generation and manipulation tools in your own hands quickly with fully intellisense support and a Visual Studio installer. Whether installing directly from NuGet with Visual Studio or downloading the DLL, you'll be set up in no time. Just one DLL and no dependencies.

PM > Install-Package IronPdf Download DLL
Supports:
  • .Net Core 2 and above
  • .Net Framework 4.0 and above support C#, VB, F#
  • Microsoft Visual Studio. .Net Development IDE Icon
  • Nuget Installer Support for Visual Studio
  • JetBrains ReSharper C# language assistant compatible
  • Microsoft Azure C# .NET  hosting platform compatible

Licensing & Pricing

Free community development licenses. Commercial licenses from $399.

Project PDF .NET C# Library Licensing

Project

Developer C# + VB.NET Library Licensing

Developer

Organization C# + VB.NET Library Licensing

Organization

Agency C# + VB.NET Library Licensing

Agency

SaaS C# + VB.NET Library Licensing

SaaS

OEM C# + VB.NET Library Licensing

OEM

View Full License Options  

C# PDF .Net Tutorials From Our Community

Tutorial + Code Examples ASPX to PDF in .Net | ASP.NET C# PDF Tutorial

C# PDF ASP.NET ASPX

Jacob Müller Software Product Designer @ Team Iron

ASPX to PDF | ASP.NET C# PDF Generator

Learn how to turn any ASP.Net ASPX page into a PDF document into a PDF instead of HTML using a single line of code in C# or VB.Net…

View Jacob's ASPX-To-PDF Example
Tutorial + Code Examples C# HTML to PDF | CSharp & VB.Net Tutorial

C# PDF HTML

Jean Ashberg .Net Software Engineer

C# HTML to PDF | CSharp & VB.Net

For many this is the most efficient way to use C# ASP .Net to generate PDF files, because there is no additional C# PDF API to learn, or complex design system to navigate…

See Jean's HTML-To-PDF Examples
Tutorial + Code Examples VB.Net PDF Creation and Editing | VB.Net & ASP.Net PDF

VB PDF ASP.NET

Veronica Sillar .Net Software Engineer

VB.Net PDF Creation and Editing | VB.Net & ASP.Net PDF Tutorial

Learn how to use VB or C# to create PDF documents in VB.Net applications and websites. A frich tutorial with code examples.…

View Veronica's Vb.Net PDF Tutorial
Thousands of developers use IronPDF for...

Accounting and Finance Systems

  • # Recepits
  • # Reporting
  • # Invoice Printing
Add PDF Support to ASP.Net Accounting and Finance Systems

Business Digitization

  • # Documentation
  • # Ordering & Labelling
  • # Paper Replacement
C# Business Digitization Use Cases

Enterprise Content Management

  • # Content Production
  • # Document Management
  • # Content Distribution
.Net CMS PDF Support

Data and Reporting Applications

  • # Performance Tracking
  • # Trend Mapping
  • # Reports
C# PDF Reports
Join Them Today
Iron Software Enterprise .Net Component Developers

Thousands of corporations, governments, SME's and developers alike trust Iron software products.

Iron's team have over 10 years experience in the .Net software component market.

3M
Rakuten
South Australia Government
GSK
Tennessee State Government
Europcar
Smith & Nephew
Turkish Airlines