C# VB PDF .NET : Using HTML To Create a PDF Using HTML To Create a PDF
using IronPdf;

// Disable local disk access or cross-origin requests
Installation.EnableWebSecurity = true;

// 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");

// Advanced Example with HTML Assets
// Load external html assets: Images, CSS and JavaScript.
// An optional BasePath 'C:\site\assets\' is set as the file location to load assets from
var myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"C:\site\assets\");
myAdvancedPdf.SaveAs("html-with-assets.pdf");
Imports IronPdf

' Disable local disk access or cross-origin requests
Installation.EnableWebSecurity = True

' Instantiate Renderer
Dim renderer = New ChromePdfRenderer()

' Create a PDF from a HTML string using C#
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>")

' Export to a file or Stream
pdf.SaveAs("output.pdf")

' Advanced Example with HTML Assets
' Load external html assets: Images, CSS and JavaScript.
' An optional BasePath 'C:\site\assets\' is set as the file location to load assets from
Dim myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", "C:\site\assets\")
myAdvancedPdf.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 from any HTML. This allows us to create PDFs that closely match the branding of existing websites.

You can choose simple HTML like the above, or incorporate CSS, images and JavaScript.

This process also allows PDF design to be delegated to web designers, rather than be tasked to back-end coders.

IronPDF uses a pixel perfect Chrome rendering engine to turn your HTML5 with CSS3 and JavaScript support into PDF documents. This can take the form of strings, external files or external URLs, all of which can be rendered to PDF easily using IronPDF.

C# VB PDF .NET : Converting a URL to a PDF Converting a URL to a PDF
using IronPdf;

// Instantiate Renderer
var renderer = new ChromePdfRenderer();

// Create a PDF from a URL or local file path
var pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/");

// Export to a file or Stream
pdf.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://ironpdf.com/")

' Export to a file or Stream
pdf.SaveAs("url.pdf")

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.


Steps to Convert URL to PDF in C#

  1. Download URL to PDF C# Library
  2. Install with NuGet to Test the Library
  3. Rendering PDFs from ASP.NET URLs which accept query string variables
  4. Creating PDF Document from URL
  5. View Your PDF Output document

C# VB PDF .NET : PDF Generation Settings PDF Generation Settings
using IronPdf;
using IronPdf.Engines.Chrome;

// Instantiate Renderer
var renderer = new ChromePdfRenderer();

// Many rendering options to use to customize!
renderer.RenderingOptions.SetCustomPaperSizeInInches(12.5, 20);
renderer.RenderingOptions.PrintHtmlBackgrounds = true;
renderer.RenderingOptions.PaperOrientation = IronPdf.Rendering.PdfPaperOrientation.Landscape;
renderer.RenderingOptions.Title = "My PDF Document Name";
renderer.RenderingOptions.EnableJavaScript = true;
renderer.RenderingOptions.WaitFor.RenderDelay(50); // in milliseconds
renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Screen;
renderer.RenderingOptions.FitToPaperMode = FitToPaperModes.Zoom;
renderer.RenderingOptions.Zoom = 100;
renderer.RenderingOptions.CreatePdfFormsFromHtml = true;

// Supports margin customization!
renderer.RenderingOptions.MarginTop = 40; //millimeters
renderer.RenderingOptions.MarginLeft = 20; //millimeters
renderer.RenderingOptions.MarginRight = 20; //millimeters
renderer.RenderingOptions.MarginBottom = 40; //millimeters

// Can set FirstPageNumber if you have a cover page
renderer.RenderingOptions.FirstPageNumber = 1; // use 2 if a cover page will be appended

// Settings have been set, we can render:
renderer.RenderHtmlFileAsPdf("assets/wikipedia.html").SaveAs("output/my-content.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com

IronPDF aims to be as flexible as possible for the developer.

In this example, we show the balance between providing an API that automates internal functionality and providing one that gives you control.

IronPDF supports many customizations for generated PDF files, including: page sizing, page margins, header/footer content, content scaling, CSS rulesets, and JavaScript execution.


We want developers to be able to control how Chrome turns a web page into a PDF. The ChromePdfRenderer class makes this possible.

Examples of settings available on the ChromePDFRenderOptions class include settings for margins, headers, footers, paper size, and form creation.

C# VB PDF .NET : Rendering ASPX Pages as PDFs Rendering ASPX Pages as PDFs
using IronPdf;

private void Form1_Load(object sender, EventArgs e)
{
    //Changes the ASPX output into a pdf instead of HTML
    IronPdf.AspxToPdf.RenderThisPageAsPdf();
}
Imports IronPdf

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
	'Changes the ASPX output into a pdf instead of HTML
	IronPdf.AspxToPdf.RenderThisPageAsPdf()
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 example shows how IronPDF can produce complex, data-driven PDFs that are designed and tested as HTML first for simplicity.

IronPDF's ASPX to PDF functionality allows you to call a single method within an ASPX page and have it return a PDF instead of HTML.

You can code the PDF to either display "in-browser," or to be behave as a file download.

C# VB PDF .NET : HTML or Image File to PDF HTML or Image File to PDF
using IronPdf;

// Instantiate Renderer
var renderer = new ChromePdfRenderer();

// 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");
Imports IronPdf

' Instantiate Renderer
Private renderer = New ChromePdfRenderer()

' Create a PDF from an existing HTML file using C#
Private pdf = renderer.RenderHtmlFileAsPdf("example.html")

' Export to a file or Stream
pdf.SaveAs("output.pdf")

One of the easiest ways to use IronPDF is to tell it to render an HTML file.

IronPDF can render any HTML file saved on a machine.

In this example, we show that all relative assets such as CSS, images and JavaScript 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. They can, in particular, test the fidelity in rendering. We recommend Chrome, as it is the web browser on which IronPDF's rendering engine is based.

If it looks right in Chrome, then it will be pixel-perfect in IronPDF as well.

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

var PdfOptions = new IronPdf.ChromePdfRenderOptions()
{
    CreatePdfFormsFromHtml = true,
    EnableJavaScript = false,
    Title = "My ASPX Page Rendered as a PDF"
    //.. many more options available
};

AspxToPdf.RenderThisPageAsPdf(AspxToPdf.FileBehavior.Attachment, "MyPdfFile.pdf", PdfOptions);
Imports IronPdf

Private PdfOptions = New IronPdf.ChromePdfRenderOptions() With {
	.CreatePdfFormsFromHtml = True,
	.EnableJavaScript = False,
	.Title = "My ASPX Page Rendered as a PDF"
}

AspxToPdf.RenderThisPageAsPdf(AspxToPdf.FileBehavior.Attachment, "MyPdfFile.pdf", PdfOptions)

This example demonstrates how the user can change PDF print options to turn form into HTML.

IronPDF's ASPX to PDF functionality has many options available for rendering HTML to PDF from a string or a file.

Two options of particular importance are:

  • Allowing developers to specify if HTML forms should be rendered as interactive PDF forms during conversion.
  • Allowing developers to specify if the PDF should be displayed "in browser," or as a file download.

C# VB PDF .NET : Image To PDF Image To PDF
using IronPdf;
using System.IO;
using System.Linq;

// One or more images as IEnumerable. This example selects all JPEG images in a specific 'assets' folder.
var imageFiles = Directory.EnumerateFiles("assets").Where(f => f.EndsWith(".jpg") || f.EndsWith(".jpeg"));

// Converts the images to a PDF and save it.
ImageToPdfConverter.ImageToPdf(imageFiles).SaveAs("composite.pdf");

// Also see PdfDocument.RasterizeToImageFiles() method to flatten a PDF to images or thumbnails
Imports IronPdf
Imports System.IO
Imports System.Linq

' One or more images as IEnumerable. This example selects all JPEG images in a specific 'assets' folder.
Private imageFiles = Directory.EnumerateFiles("assets").Where(Function(f) f.EndsWith(".jpg") OrElse f.EndsWith(".jpeg"))

' Converts the images to a PDF and save it.
ImageToPdfConverter.ImageToPdf(imageFiles).SaveAs("composite.pdf")

' Also see PdfDocument.RasterizeToImageFiles() method to flatten a PDF to images or thumbnails

Construct a PDF from one or more image files using the IronPdf.ImageToPdfConverter class.

How to Convert an Image to a PDF in C#

Given a single image located on a computer at C:\images\example.png, we can convert it quickly into a PDF document by calling the IronPdf.ImageToPdfConverter.ImageToPdf method with its file path:

IronPdf.ImageToPdfConverter.ImageToPdf(@"C:\images\example.png").SaveAs("example.pdf");
IronPdf.ImageToPdfConverter.ImageToPdf(@"C:\images\example.png").SaveAs("example.pdf");
IronPdf.ImageToPdfConverter.ImageToPdf("C:\images\example.png").SaveAs("example.pdf")
VB   C#

Combine Multiple Images Into a PDF File

We can also convert images to PDFs in batch into a single PDF document using System.IO.Directory.EnumerateFiles along with ImageToPdfConverter.ImageToPdf:

string sourceDirectory = "D:\web\assets";
string destinationFile = "JpgToPDF.pdf";
var imageFiles = Directory.EnumerateFiles(sourceDirectory, "*.jpg");
ImageToPdfConverter.ImageToPdf(imageFiles).SaveAs(destinationFile);
string sourceDirectory = "D:\web\assets";
string destinationFile = "JpgToPDF.pdf";
var imageFiles = Directory.EnumerateFiles(sourceDirectory, "*.jpg");
ImageToPdfConverter.ImageToPdf(imageFiles).SaveAs(destinationFile);
Dim sourceDirectory As String = "D:\web" & ChrW(7) & "ssets"
Dim destinationFile As String = "JpgToPDF.pdf"
Dim imageFiles = Directory.EnumerateFiles(sourceDirectory, "*.jpg")
ImageToPdfConverter.ImageToPdf(imageFiles).SaveAs(destinationFile)
VB   C#

C# VB PDF .NET : HTML Headers & Footers HTML Headers & Footers
using IronPdf;
using System;

// Instantiate Renderer
var renderer = new IronPdf.ChromePdfRenderer();


// Build a footer using html to style the text
// mergeable fields are:
// {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title}
renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter()
{
    MaxHeight = 15, //millimeters
    HtmlFragment = "<center><i>{page} of {total-pages}<i></center>",
    DrawDividerLine = true
};

// Use sufficient MarginBottom to ensure that the HtmlFooter does not overlap with the main PDF page content.
renderer.RenderingOptions.MarginBottom = 25; //mm


// Build a header using an image asset
// Note the use of BaseUrl to set a relative path to the assets
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
{
    MaxHeight = 20, //millimeters
    HtmlFragment = "<img src='logo.png'>",
    BaseUrl = new Uri(@"C:\assets\images\").AbsoluteUri
};

// Use sufficient MarginTop to ensure that the HtmlHeader does not overlap with the main PDF page content.
renderer.RenderingOptions.MarginTop = 25; //mm
Imports IronPdf
Imports System

' Instantiate Renderer
Private renderer = New IronPdf.ChromePdfRenderer()


' Build a footer using html to style the text
' mergeable fields are:
' {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title}
renderer.RenderingOptions.HtmlFooter = New HtmlHeaderFooter() With {
	.MaxHeight = 15,
	.HtmlFragment = "<center><i>{page} of {total-pages}<i></center>",
	.DrawDividerLine = True
}

' Use sufficient MarginBottom to ensure that the HtmlFooter does not overlap with the main PDF page content.
renderer.RenderingOptions.MarginBottom = 25 'mm


' Build a header using an image asset
' Note the use of BaseUrl to set a relative path to the assets
renderer.RenderingOptions.HtmlHeader = New HtmlHeaderFooter() With {
	.MaxHeight = 20,
	.HtmlFragment = "<img src='logo.png'>",
	.BaseUrl = (New Uri("C:\assets\images\")).AbsoluteUri
}

' Use sufficient MarginTop to ensure that the HtmlHeader does not overlap with the main PDF page content.
renderer.RenderingOptions.MarginTop = 25 'mm

The HTML headers and footers are rendered as independent HTML documents which may have their own assets and stylesheets. It gives developers total control over how their headers and footers look. The height of the rendered headers or footers can be controlled to match their content exactly.

In this example, we show how to add HTML headers and footers to your PDF documents in IronPDF.

HTML headers or footers will be printed onto every page of the PDF when you add them to your project. This can be used to override classic headers and footers.

When using HtmlHeaderFooter, it is important to set HtmlFragment, which will be used to render the headers or footers. It should be an HTML snippet rather than a complete document. It may also contain styles & images.

You can also merge meta-data into your HTML using any of these placeholder strings such as {page} {total-pages} {url} {date} {time} {html-title} {pdf-title}.

C# VB PDF .NET : Simple Headers & Footers Simple Headers & Footers
using IronPdf;

// Initiate PDF Renderer
var renderer = new ChromePdfRenderer();

// Add a header to every page easily
renderer.RenderingOptions.FirstPageNumber = 1; // use 2 if a cover page  will be appended
renderer.RenderingOptions.TextHeader.DrawDividerLine = true;
renderer.RenderingOptions.TextHeader.CenterText = "{url}";
renderer.RenderingOptions.TextHeader.Font = IronSoftware.Drawing.FontTypes.Helvetica;
renderer.RenderingOptions.TextHeader.FontSize = 12;
renderer.RenderingOptions.MarginTop = 25; //create 25mm space for header

// Add a footer too
renderer.RenderingOptions.TextFooter.DrawDividerLine = true;
renderer.RenderingOptions.TextFooter.Font = IronSoftware.Drawing.FontTypes.Arial;
renderer.RenderingOptions.TextFooter.FontSize = 10;
renderer.RenderingOptions.TextFooter.LeftText = "{date} {time}";
renderer.RenderingOptions.TextFooter.RightText = "{page} of {total-pages}";
renderer.RenderingOptions.MarginTop = 25; //create 25mm space for footer

// Mergeable fields are:
// {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title}
Imports IronPdf

' Initiate PDF Renderer
Private renderer = New ChromePdfRenderer()

' Add a header to every page easily
renderer.RenderingOptions.FirstPageNumber = 1 ' use 2 if a cover page  will be appended
renderer.RenderingOptions.TextHeader.DrawDividerLine = True
renderer.RenderingOptions.TextHeader.CenterText = "{url}"
renderer.RenderingOptions.TextHeader.Font = IronSoftware.Drawing.FontTypes.Helvetica
renderer.RenderingOptions.TextHeader.FontSize = 12
renderer.RenderingOptions.MarginTop = 25 'create 25mm space for header

' Add a footer too
renderer.RenderingOptions.TextFooter.DrawDividerLine = True
renderer.RenderingOptions.TextFooter.Font = IronSoftware.Drawing.FontTypes.Arial
renderer.RenderingOptions.TextFooter.FontSize = 10
renderer.RenderingOptions.TextFooter.LeftText = "{date} {time}"
renderer.RenderingOptions.TextFooter.RightText = "{page} of {total-pages}"
renderer.RenderingOptions.MarginTop = 25 'create 25mm space for footer

' Mergeable fields are:
' {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title}

Headers and Footers may be added to PDF documents in two distinct ways.

  • Classic text headers and footers, which allows text-based headers to be added, with the option to merge in dynamic data.
  • HTML headers and footers, which allows the developer to render HTML headers and footers to PDF files, also allowing the templating of dynamic data. This method is more flexible, although it is harder to use.

The class TextHeaderFooter in IronPDF defines PDF headers and footers display options. This uses a logical approach to rendering headers and footers for the most common use cases.

In this example, we show you how to add classic text headers and footers to your PDF documents in IronPDF.

When adding headers and footers to your document, you have the option to set the headers text to be centered on the PDF document. You can also merge metadata into your header using placeholder strings. You can find these strings here. You can also add a horizontal line divider between the headers or footers and the page content on every page of the PDF document, influence font and font sizes etc. It is a very useful feature that ticks all the boxes.

C# VB PDF .NET : Editing PDFs Editing PDFs
using IronPdf;
using System.Collections.Generic;

// Instantiate Renderer
var renderer = new ChromePdfRenderer();

// 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"));
var 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("excerpt.pdf");

foreach (var eachPdf in pdfs)
{
    eachPdf.Dispose();
}
Imports IronPdf
Imports System.Collections.Generic

' Instantiate Renderer
Private renderer = New ChromePdfRenderer()

' Join Multiple Existing PDFs into a single document
Private 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 = 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("excerpt.pdf")

For Each eachPdf In pdfs
	eachPdf.Dispose()
Next eachPdf

IronPDF offers 50+ features for reading and editing PDFs. The most popular are merging, cloning and extracting pages.

IronPDF also allows its users to add watermarks, rotate pages, add annotations, digitally sign PDF pages, create PDF new documents, attach cover pages, customize PDF sizes, and much more when generating and formatting PDF files. Moreover, it supports conversion of PDFs into all conventional image file types, including JPG, BMP, JPEG, GIF, PNG, TIFF, etc.

Read this article to learn how to make full use of IronPDF to modify PDF documents to best suit project requirements.


C# VB PDF .NET : Passwords, Security & Metadata Passwords, Security & Metadata
using IronPdf;

// Open an Encrypted File, alternatively create a new PDF from Html
var pdf = PdfDocument.FromFile("encrypted.pdf", "password");

// Get file metadata
System.Collections.Generic.List<string> metadatakeys = pdf.MetaData.Keys(); // returns {"Title", "Creator", ...}

// Remove file metadata
pdf.MetaData.RemoveMetaDataKey("Title");
metadatakeys = pdf.MetaData.Keys(); // return {"Creator", ...} // title was deleted

// Edit file metadata
pdf.MetaData.Author = "Satoshi Nakamoto";
pdf.MetaData.Keywords = "SEO, Friendly";
pdf.MetaData.ModifiedDate = System.DateTime.Now;

// The following code makes a PDF read only and will disallow copy & paste and printing
pdf.SecuritySettings.RemovePasswordsAndEncryption();
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key");
pdf.SecuritySettings.AllowUserAnnotations = false;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserFormData = false;
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;

// Change or set the document encryption password
pdf.SecuritySettings.OwnerPassword = "top-secret"; // password to edit the pdf
pdf.SecuritySettings.UserPassword = "sharable"; // password to open the pdf
pdf.SaveAs("secured.pdf");
Imports System
Imports IronPdf

' Open an Encrypted File, alternatively create a new PDF from Html
Private pdf = PdfDocument.FromFile("encrypted.pdf", "password")

' Get file metadata
Private metadatakeys As System.Collections.Generic.List(Of String) = pdf.MetaData.Keys() ' returns {"Title", "Creator", ...}

' Remove file metadata
pdf.MetaData.RemoveMetaDataKey("Title")
metadatakeys = pdf.MetaData.Keys() ' return {"Creator", ...} // title was deleted

' Edit file metadata
pdf.MetaData.Author = "Satoshi Nakamoto"
pdf.MetaData.Keywords = "SEO, Friendly"
pdf.MetaData.ModifiedDate = DateTime.Now

' The following code makes a PDF read only and will disallow copy & paste and printing
pdf.SecuritySettings.RemovePasswordsAndEncryption()
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key")
pdf.SecuritySettings.AllowUserAnnotations = False
pdf.SecuritySettings.AllowUserCopyPasteContent = False
pdf.SecuritySettings.AllowUserFormData = False
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights

' Change or set the document encryption password
pdf.SecuritySettings.OwnerPassword = "top-secret" ' password to edit the pdf
pdf.SecuritySettings.UserPassword = "sharable" ' password to open the pdf
pdf.SaveAs("secured.pdf")

Granular meta-data and security settings can be applied. This now includes the ability to limit PDF documents to be unprintable, read only and encrypted. 128 bit encryption, decryption and password protection of PDF documents is supported.

C# VB PDF .NET : PDF Watermarking PDF Watermarking
using IronPdf;

// Stamps a Watermark onto a new or existing PDF
var renderer = new ChromePdfRenderer();

var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
pdf.ApplyWatermark("<h2 style='color:red'>SAMPLE</h2>", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center);
pdf.SaveAs(@"C:\Path\To\Watermarked.pdf");
Imports IronPdf

' Stamps a Watermark onto a new or existing PDF
Private renderer = New ChromePdfRenderer()

Private pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf")
pdf.ApplyWatermark("<h2 style='color:red'>SAMPLE</h2>", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center)
pdf.SaveAs("C:\Path\To\Watermarked.pdf")

IronPDF provides methods to 'watermark' PDF documents with HTML.

Using the ApplyStamp method, developers can add an HTML-based watermark to a PDF file. As shown in the example above, the HTML code for the watermark goes as the first argument to the method. Additional arguments to ApplyStamp control the rotation, opacity, and position of the watermark.

Utilize the ApplyStamp method in lieu of the ApplyWatermark method for more granular control over watermark placement. For example, use ApplyStamp to:

  • Add Text, Image, or HTML watermarks to PDFs
  • Apply the same watermark to every page of the PDF
  • Apply different watermarks to specific PDF pages
  • Adjust the placement of watermarks in front or behind page copy
  • Adjust the opacity, rotation and alignment of watermarks with more precision

C# VB PDF .NET : Backgrounds & Foregrounds Backgrounds & Foregrounds
using IronPdf;

// With IronPDF, we can easily merge 2 PDF files using one as a background or foreground
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
pdf.AddBackgroundPdf(@"MyBackground.pdf");
pdf.AddForegroundOverlayPdfToPage(0, @"MyForeground.pdf", 0);
pdf.SaveAs(@"C:\Path\To\Complete.pdf");
Imports IronPdf

' With IronPDF, we can easily merge 2 PDF files using one as a background or foreground
Private renderer = New ChromePdfRenderer()
Private pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf")
pdf.AddBackgroundPdf("MyBackground.pdf")
pdf.AddForegroundOverlayPdfToPage(0, "MyForeground.pdf", 0)
pdf.SaveAs("C:\Path\To\Complete.pdf")

You may want to use a specific background and foreground as you create and render your PDF documents in IronPDF. In such a case, you can use an existing or rendered PDF as the background or foreground for another PDF document. This is particularly useful for design consistency and templating.

This example shows you how to use a PDF document as the background or foreground of another PDF document.

You can do this in C# by loading or creating a multi-page PDF as an IronPdf.PdfDocument object.

You can add backgrounds using PdfDocument.AddBackgroundPdf. There are several background insertion methods and overrides in the IronPdf.PdfDocument documentation. This adds a background to each page of your working PDF. The background is copied from a page in another PDF document.

You can add foregrounds, also known as "Overlays," using PdfDocument.AddForegroundOverlayPdfToPage. There are several foreground insertion methods and overrides in the IronPdf.PdfDocument documentation.

C# VB PDF .NET : Form Data Form Data
using IronPdf;
using System;

// Step 1.  Creating a PDF with editable forms from HTML using form and input tags
// Radio Button and Checkbox can also be implemented with input type 'radio' and 'checkbox'
const string formHtml = @"
    <html>
        <body>
            <h2>Editable PDF  Form</h2>
            <form>
              First name: <br> <input type='text' name='firstname' value=''> <br>
              Last name: <br> <input type='text' name='lastname' value=''> <br>
              <br>
              <p>Please specify your gender:</p>
              <input type='radio' id='female' name='gender' value= 'Female'>
                <label for='female'>Female</label> <br>
                <br>
              <input type='radio' id='male' name='gender' value='Male'>
                <label for='male'>Male</label> <br>
                <br>
              <input type='radio' id='non-binary/other' name='gender' value='Non-Binary / Other'>
                <label for='non-binary/other'>Non-Binary / Other</label>
              <br>

              <p>Please select all medical conditions that apply:</p>
              <input type='checkbox' id='condition1' name='Hypertension' value='Hypertension'>
              <label for='condition1'> Hypertension</label><br>
              <input type='checkbox' id='condition2' name='Heart Disease' value='Heart Disease'>
              <label for='condition2'> Heart Disease</label><br>
              <input type='checkbox' id='condition3' name='Stoke' value='Stoke'>
              <label for='condition3'> Stoke</label><br>
              <input type='checkbox' id='condition4' name='Diabetes' value='Diabetes'>
              <label for='condition4'> Diabetes</label><br>
              <input type='checkbox' id='condition5' name='Kidney Disease' value='Kidney Disease'>
              <label for='condition5'> Kidney Disease</label><br>
            </form>
        </body>
    </html>";

// Instantiate Renderer
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.CreatePdfFormsFromHtml = true;
renderer.RenderHtmlAsPdf(formHtml).SaveAs("BasicForm.pdf");

// Step 2. Reading and Writing PDF form values.
var FormDocument = PdfDocument.FromFile("BasicForm.pdf");

// Set and Read the value of the "firstname" field
var FirstNameField = FormDocument.Form.FindFormField("firstname");
FirstNameField.Value = "Minnie";
Console.WriteLine("FirstNameField value: {0}", FirstNameField.Value);

// Set and Read the value of the "lastname" field
var LastNameField = FormDocument.Form.FindFormField("lastname");
LastNameField.Value = "Mouse";
Console.WriteLine("LastNameField value: {0}", LastNameField.Value);

FormDocument.SaveAs("FilledForm.pdf");
Imports IronPdf
Imports System

' Step 1.  Creating a PDF with editable forms from HTML using form and input tags
' Radio Button and Checkbox can also be implemented with input type 'radio' and 'checkbox'
Private Const formHtml As String = "
    <html>
        <body>
            <h2>Editable PDF  Form</h2>
            <form>
              First name: <br> <input type='text' name='firstname' value=''> <br>
              Last name: <br> <input type='text' name='lastname' value=''> <br>
              <br>
              <p>Please specify your gender:</p>
              <input type='radio' id='female' name='gender' value= 'Female'>
                <label for='female'>Female</label> <br>
                <br>
              <input type='radio' id='male' name='gender' value='Male'>
                <label for='male'>Male</label> <br>
                <br>
              <input type='radio' id='non-binary/other' name='gender' value='Non-Binary / Other'>
                <label for='non-binary/other'>Non-Binary / Other</label>
              <br>

              <p>Please select all medical conditions that apply:</p>
              <input type='checkbox' id='condition1' name='Hypertension' value='Hypertension'>
              <label for='condition1'> Hypertension</label><br>
              <input type='checkbox' id='condition2' name='Heart Disease' value='Heart Disease'>
              <label for='condition2'> Heart Disease</label><br>
              <input type='checkbox' id='condition3' name='Stoke' value='Stoke'>
              <label for='condition3'> Stoke</label><br>
              <input type='checkbox' id='condition4' name='Diabetes' value='Diabetes'>
              <label for='condition4'> Diabetes</label><br>
              <input type='checkbox' id='condition5' name='Kidney Disease' value='Kidney Disease'>
              <label for='condition5'> Kidney Disease</label><br>
            </form>
        </body>
    </html>"

' Instantiate Renderer
Private renderer = New ChromePdfRenderer()
renderer.RenderingOptions.CreatePdfFormsFromHtml = True
renderer.RenderHtmlAsPdf(formHtml).SaveAs("BasicForm.pdf")

' Step 2. Reading and Writing PDF form values.
Dim FormDocument = PdfDocument.FromFile("BasicForm.pdf")

' Set and Read the value of the "firstname" field
Dim FirstNameField = FormDocument.Form.FindFormField("firstname")
FirstNameField.Value = "Minnie"
Console.WriteLine("FirstNameField value: {0}", FirstNameField.Value)

' Set and Read the value of the "lastname" field
Dim LastNameField = FormDocument.Form.FindFormField("lastname")
LastNameField.Value = "Mouse"
Console.WriteLine("LastNameField value: {0}", LastNameField.Value)

FormDocument.SaveAs("FilledForm.pdf")

You can create editable PDF documents with IronPDF as easily as a normal document. The PdfForm class is a collection of user-editable form fields within a PDF document. It can be implemented into your PDF render to make it a form or an editable document.

This example shows you how to create editable PDF forms in IronPDF.

PDFs with editable forms can be created from HTML simply by adding <form>, <input>, and <textarea> tags to the document parts.

The PdfDocument.Form.GetFieldByName can be used to read and write the value of any form field. The field's name will be the same as the 'name' attribute given to that field in your HTML.

The PdfDocument.Form object can be used in two ways.

  • The first is to populate the default value of form fields, which must be focused in Adobe Reader to display this value.
  • The second is to read data from user-filled PDF forms in any language.

C# VB PDF .NET : Rasterize a PDF to Images Rasterize a PDF to Images
using IronPdf;
using IronSoftware.Drawing;

var pdf = PdfDocument.FromFile("Example.pdf");

// Extract all pages to a folder as image files
pdf.RasterizeToImageFiles(@"C:\image\folder\*.png");

// Dimensions and page ranges may be specified
pdf.RasterizeToImageFiles(@"C:\image\folder\example_pdf_image_*.jpg", 100, 80);

// Extract all pages as AnyBitmap objects
AnyBitmap[] pdfBitmaps = pdf.ToBitmap();
Imports IronPdf
Imports IronSoftware.Drawing

Private pdf = PdfDocument.FromFile("Example.pdf")

' Extract all pages to a folder as image files
pdf.RasterizeToImageFiles("C:\image\folder\*.png")

' Dimensions and page ranges may be specified
pdf.RasterizeToImageFiles("C:\image\folder\example_pdf_image_*.jpg", 100, 80)

' Extract all pages as AnyBitmap objects
Dim pdfBitmaps() As AnyBitmap = pdf.ToBitmap()

Use IronPDF to convert a PDF to images in your preferred file type, image dimensions, and DPI quality.

To convert a PDF document to images, call IronPDF's RasterizeToImageFiles method on a PdfDocument object. A PDF document can be loaded using the PdfDocument.FromFile method or one of the available PDF generation methods.



RasterizeToImageFiles renders each page of the as a rasterized image. The first argument specifies the naming pattern to use for each image. Optional arguments can be used to customize the quality and dimensions for each image. Another one causes the method to convert selected pages from the PDF into images.

Line 24 of the featured code example demonstrates the ToBitMap method. Call this method on any PdfDocument object to quickly convert the PDF into AnyBitmap objects that can be saved to files or manipulated as needed.


C# VB PDF .NET : Digitally Sign a PDF Digitally Sign a PDF
using IronPdf;
using IronPdf.Signing;

// Cryptographically sign an existing PDF in 1 line of code!
new IronPdf.Signing.PdfSignature("Iron.p12", "123456").SignPdfFile("any.pdf");

/***** Advanced example for more control *****/

// Step 1. Create a PDF
var renderer = new ChromePdfRenderer();
var doc = renderer.RenderHtmlAsPdf("<h1>Testing 2048 bit digital security</h1>");

// Step 2. Create a Signature.
// You may create a .pfx or .p12 PDF signing certificate using Adobe Acrobat Reader.
// Read: https://helpx.adobe.com/acrobat/using/digital-ids.html

var signature = new IronPdf.Signing.PdfSignature("Iron.pfx", "123456")
{
    // Step 3. Optional signing options and a handwritten signature graphic
    SigningContact = "support@ironsoftware.com",
    SigningLocation = "Chicago, USA",
    SigningReason = "To show how to sign a PDF"
};

//Step 3. Sign the PDF with the PdfSignature. Multiple signing certificates may be used
doc.Sign(signature);

//Step 4. The PDF is not signed until saved to file, steam or byte array.
doc.SaveAs("signed.pdf");
Imports IronPdf
Imports IronPdf.Signing

' Cryptographically sign an existing PDF in 1 line of code!
Call (New IronPdf.Signing.PdfSignature("Iron.p12", "123456")).SignPdfFile("any.pdf")

'''*** Advanced example for more control ****

' Step 1. Create a PDF
Dim renderer = New ChromePdfRenderer()
Dim doc = renderer.RenderHtmlAsPdf("<h1>Testing 2048 bit digital security</h1>")

' Step 2. Create a Signature.
' You may create a .pfx or .p12 PDF signing certificate using Adobe Acrobat Reader.
' Read: https://helpx.adobe.com/acrobat/using/digital-ids.html

Dim signature = New IronPdf.Signing.PdfSignature("Iron.pfx", "123456") With {
	.SigningContact = "support@ironsoftware.com",
	.SigningLocation = "Chicago, USA",
	.SigningReason = "To show how to sign a PDF"
}

'Step 3. Sign the PDF with the PdfSignature. Multiple signing certificates may be used
doc.Sign(signature)

'Step 4. The PDF is not signed until saved to file, steam or byte array.
doc.SaveAs("signed.pdf")

IronPDF has options to digitally sign new or existing PDF files using .pfx and .p12 X509Certificate2 digital certificates.

Once a PDF is signed, it can not be modified without the certificate being invalidated. This ensures fidelity.

To generate a signing certificate for free using Adobe Reader, please read https://helpx.adobe.com/acrobat/using/digital-ids.html

In addition to cryptographic signing, a hand written signature image or company stamp image may also be used to sign using IronPDF.

You can download a file project from this link.

HTML to PDF in ASP .NET

What Is IronPDF for .NET?

Our .NET PDF Library solution is a dream for developers, especially software engineers who use C#. You can easily create a core pdf library for .NET.

IronPDF uses a .NET Chromium engine to render HTML pages to PDF files. There's no need to use complex APIs to position or design PDFs. IronPDF supports standard web documents HTML, ASPX, JS, CSS, and images.

It enables you to create a .NET PDF library using HTML5, CSS, JavaScript, and also images. You can edit, stamp, and add headers and footers to a PDF effortlessly. It also makes it easy to read PDF text and extract images!

Get Started
.NET PDF Library Features Using IronPDF

.NET PDF Library Features Using IronPDF

We’ve never seen a more accurate HTML to PDF converter! Our industry-leading PDF library has so many features and a rendering engine that enables heedlessness and embeddability in the Chrome / Webkit. No installation is required.

Create

  • Create PDF documents from HTML 4 and 5, CSS, and JavaScript
  • Generate PDF documents from URL
  • Load URL with custom network login credentials, UserAgents, Proxies, Cookies, HTTP headers, form variables allowing login behind HTML login forms
    • Supports mainstream icon fonts (Fontello, Bootstrap, FontAwesome)
    • Load external stylesheets and assets (HTTP, HTTPS, or filesystem) programmatically
  • Single and Multithreaded rendering
  • Custom ISO paper size with customizable orientations, margins, and color component

Edit Existing PDF Documents without Adobe Acrobat

  • Read and fill form fields data
  • Extract images and texts from PDF
  • Add, edit, update outlines and bookmarks, program annotations with sticky notes
  • Add foreground or background overlays from HTML or PDF assets
  • Stamp new HTML Content onto any existing PDF page
  • Add logical or HTML headers and footers

Manipulate Existing PDF Documents

  • Load and parse existing PDF documents
  • Merge and split content in pdf document
  • Add headers, footers, annotations, bookmarks, watermarks, text, and image assets
  • Add stamp and watermarks with text, images, and HTML backgrounds
  • Rotate pages

Convert from Multiple Formats

  • Images to a PDF file – convert from mainstream image document, with a single line code, JPG, PNG, GIF, BMP, TIFF, system drawing, and SVG to PDF
  • ASPX WebForms – convert, with 3 lines of code, ASP.NET webforms to downloadable PDFs viewable in the browser
  • HTML Document – convert HTML to PDF
  • Custom ‘base URL’ to allow accessible asset files across the web
  • Responsive layouts through Virtual Viewport (Width and Height)
  • Custom zoom with scalable:
    • HTML content to dimensions that preserves the quality
    • Output resolution in DPI
  • Embed System Drawing image assets into HTML strings with ImagetoDataURI
  • Enable JavaScript support including optional Render delays
  • Accept HTML encoded in any major file encoding (Default to UTF-8)

Export

  • MVC Views – export ASP.NET MVC views as PDF
  • Merge pages and images
  • Export files to any format with supported fonts

Save

  • Save and load from file, binary data, or MemoryStreams.

Secure

  • Improve security with options to update user passwords, metadata, security permissions, and verifiable digital signatures

Print

  • Screen or Print CSS media types
  • Turn PDF files into a PrintDocument object and print without Adobe (with minimal code)

See the Features
Edit PDFs in C# VB .NET

Everything you need in PDF documents

Creating, merging, splitting, editing, and manipulating PDF files whenever you want them, the way you want them is a breeze. Use your C# development skills to tap into IronPDF’s expanding features list.

To begin working on a project with IronPDF, download the free NuGet Package Installer or directly download the DLL. You can then proceed to create PDF document, edit and manipulate existing file formats, or export to any format without adobe acrobat.

Our support extends from a free and exhaustive range of tutorials to 24/7 live support.

Get Started with IronPDF
HTML, JavaScript, CSS and Image Conversion to PDF in .NET Applications.

Design with Familiar HTML Documents

IronPDF lets you work with mainstream HTML document formats and turn it into PDF in ASP.NET web applications. Apply multiple settings including setting file behavior and names, adding headers and footers, changing print options, adding page breaks, combining async and multithreading, and more.

Similarly you can convert C# MVC HTML to PDF for ASP .NET Applications, print MVC view to return PDF file format, supported with HTML, CSS, JavaScript and images.

In addition, create PDF documents and convert a present HTML page to PDF in ASP .NET C# applications and websites (C# html-to-pdf converter). The rich HTML is used as the PDF content with the ability to edit and manipulate with IronPDF's generate feature.

With IronPDF, worrying about resolutions is an issue from the past. The output PDF documents from IronPdf are pixel identical to the PDF functionality in the Google Chrome web browser.

Made for .NET, C#, VB, MVC, ASPX, ASP.NET, .NET Core

Get Started in Minutes
Simple Installation <br/>for Visual Studio

Try It With NuGet Now

The benefits are clear! With IronPDF, you can do so much more, so much easier. Our product is perfect for anyone who needs to make, manage and edit a library of PDFs, including businesses in real estate, publishing, finance, and enterprise. The prices of our solution are also very competitive.

Ready to see what IronPDF can do for your projects and business? Try it out now

Install with NuGet for .NET Download Now
Supports:
  • Supports C#, VB in .NET Framework 4.0 and above
  • NuGet Installer Support for Visual Studio
  • .NET Core 2 and above
  • .NET Development IDE - Microsoft Visual Studio.
  • Azure for .NET cloud hosting
  • JetBrains ReSharper C# compatible

IronPDF Licensing

Free for development purposes. Deployment licenses from $749.

Project C# + VB.NET Library Licensing

Project

Organization C# + VB.NET Library Licensing

Organization

SaaS C# + VB.NET Library Licensing

SaaS

OEM C# + VB.NET Library Licensing

OEM

Developer C# + VB.NET Library Licensing

Developer

Agency C# + VB.NET Library Licensing

Agency

Licensing IronPDF for Deployment  

PDF C# / VB Tutorials for .NET

C# HTML-to-PDF | C Sharp & VB.NET Tutorial

C# PDF HTML

Jean Ashberg .NET Software Engineer

Tutorial | CSharp and VB .NET HTML to PDF

Let's create PDFs in .NET, without the need for complex programtic design layout or APIs…

View Jean's HTML To PDF Tutorial
ASPX to PDF | ASP.NET Tutorial

C# PDF .NET ASPX

Jacob Müller Software Product Designer @ Team Iron

Tutorial | ASPX to PDF in ASP.NET

See how easy it is to convert ASPX pages into PDF documents using C# or VB .NET…

See Jacob's ASPX To PDF Tutorial
VB.NET | VB .NET PDF Tutorial

VB.NET PDF ASP.NET

Veronica Sillar .NET Software Engineer

Tutorial | Create PDFs with VB.NET

See how I use IronPDF to create PDF documents within my VB .NET projects…

See Veronica's VB .NET Tutorial
Thousands of developers use IronPDF for...

Accounting and Finance Systems

  • # Receipts
  • # 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
IronPDF Component software library customers

Developers working within Companies, Government departments and as freelancers use IronPDF.

IronPDF is constantly supported as a leading .NET PDF Library

IronPDF Customer Icon
IronPDF Customer Icon
IronPDF Customer Icon
IronPDF Customer Icon
IronPDF Customer Icon
IronPDF Customer Icon
IronPDF Customer Icon
IronPDF Customer Icon