C# + VB.Net: Using Html To Create a PDF Using Html To Create a PDF
// PM> Install-Package IronPdf
using IronPdf;

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

// Create a PDF from a HTML string using C#
using 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 
using var myAdvancedPdf = Renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"C:\site\assets\");
pdf.SaveAs("html-with-assets.pdf");
' PM> Install-Package IronPdf
Imports IronPdf

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

' Create a PDF from a HTML string using C#
Private var As using

' 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 
Using myAdvancedPdf = Renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", "C:\site\assets\")
	pdf.SaveAs("html-with-assets.pdf")
End Using

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's rendering is "pixel perfect" to desktop versions of Google Chrome.

C# + VB.Net: Converting a URL to a PDF Converting a URL to a PDF
// PM> Install-Package IronPdf
using IronPdf;

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

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

// Export to a file or Stream
pdf.SaveAs("url.pdf");
' PM> Install-Package IronPdf
Imports IronPdf

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

' Create a PDF from a URL or local file path
Private var As using

' 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.

You can download a file project from this link.

C# + VB.Net: PDF Generation Settings PDF Generation Settings
// PM> Install-Package IronPdf
using IronPdf;

// Instantiate Renderer
var Renderer = new IronPdf.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.RenderDelay = 50; // in milliseconds
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Screen;
Renderer.RenderingOptions.FitToPaperWidth = false;
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 coverpage
Renderer.RenderingOptions.FirstPageNumber = 1; // use 2 if a coverpage will be appended

// Settings have been set, we can render:
Renderer.RenderHTMLFileAsPdf("assets/wikipedia.html").SaveAs("output/my-content.pdf");
' PM> Install-Package IronPdf
Imports IronPdf

' Instantiate Renderer
Private Renderer = New IronPdf.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.RenderDelay = 50 ' in milliseconds
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Screen
Renderer.RenderingOptions.FitToPaperWidth = False
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 coverpage
Renderer.RenderingOptions.FirstPageNumber = 1 ' use 2 if a coverpage will be appended

' Settings have been set, we can render:
Renderer.RenderHTMLFileAsPdf("assets/wikipedia.html").SaveAs("output/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: HTML or Image File to PDF HTML or Image File to PDF
 // PM> Install-Package IronPdf
using IronPdf;

// Instantiate Renderer

var Renderer = new IronPdf.ChromePdfRenderer();

// Create a PDF from an existing HTML file using C#
using var pdf = Renderer.RenderHTMLFileAsPdf("example.html");

// Export to a file or Stream
pdf.SaveAs("output.pdf");
' PM> Install-Package IronPdf
Imports IronPdf

' Instantiate Renderer

Private Renderer = New IronPdf.ChromePdfRenderer()

' Create a PDF from an existing HTML file using C#
Private var As using

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

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: ASPX To PDF Settings ASPX To PDF Settings
// PM> Install-Package IronPdf
using IronPdf;


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

AspxToPdf.RenderThisPageAsPdf(AspxToPdf.FileBehavior.Attachment, "MyPdfFile.pdf", PdfOptions);
' PM> Install-Package IronPdf
Imports IronPdf


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

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

ASP.NET ASPX to PDF functionality allows the full set of options available when rendering HTML from a string or file, but 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: Image To PDF Image To PDF
// PM> Install-Package IronPdf
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 = System.IO.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
' PM> Install-Package IronPdf
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 = System.IO.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

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

You can download a file project from this link.

C# + VB.Net: Headers & Footers Headers & Footers
// PM> Install-Package IronPdf
using IronPdf;

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

// Add a header to every page easily
Renderer.RenderingOptions.FirstPageNumber = 1; // use 2 if a coverpage  will be appended
Renderer.RenderingOptions.TextHeader.DrawDividerLine = true;
Renderer.RenderingOptions.TextHeader.CenterText = "{url}";
Renderer.RenderingOptions.TextHeader.Font = IronPdf.Font.FontTypes.Helvetica;
Renderer.RenderingOptions.TextHeader.FontSize = 12;

// Add a footer too
Renderer.RenderingOptions.TextFooter.DrawDividerLine = true;
Renderer.RenderingOptions.TextFooter.Font = IronPdf.Font.FontTypes.Arial;
Renderer.RenderingOptions.TextFooter.FontSize = 10;
Renderer.RenderingOptions.TextFooter.LeftText = "{date} {time}";
Renderer.RenderingOptions.TextFooter.RightText = "{page} of {total-pages}";

// Mergable fields are:
// {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title}
' PM> Install-Package IronPdf
Imports IronPdf

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

' Add a header to every page easily
Renderer.RenderingOptions.FirstPageNumber = 1 ' use 2 if a coverpage  will be appended
Renderer.RenderingOptions.TextHeader.DrawDividerLine = True
Renderer.RenderingOptions.TextHeader.CenterText = "{url}"
Renderer.RenderingOptions.TextHeader.Font = IronPdf.Font.FontTypes.Helvetica
Renderer.RenderingOptions.TextHeader.FontSize = 12

' Add a footer too
Renderer.RenderingOptions.TextFooter.DrawDividerLine = True
Renderer.RenderingOptions.TextFooter.Font = IronPdf.Font.FontTypes.Arial
Renderer.RenderingOptions.TextFooter.FontSize = 10
Renderer.RenderingOptions.TextFooter.LeftText = "{date} {time}"
Renderer.RenderingOptions.TextFooter.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.
- TextHeaderFooter 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. More felxible but harder to use.

C# + VB.Net: HTML Headers & Footers HTML Headers & Footers
// PM> Install-Package IronPdf
using IronPdf;

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


// Build a footer using html to style the text
// mergable 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
};

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

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


' Build a footer using html to style the text
' mergable 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
}

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

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: Form Data Form Data
// PM> Install-Package IronPdf
using IronPdf;

// Step 1.  Creating a PDF with editable forms from HTML using form and input tags

var 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=''>
                    </form>
                </body>
            </html>";

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

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

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

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

FormDocument.SaveAs("FilledForm.pdf");
' PM> Install-Package IronPdf
Imports IronPdf

' Step 1.  Creating a PDF with editable forms from HTML using form and input tags

Private 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=''>
                    </form>
                </body>
            </html>"

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

' Step 2. Reading and Writing PDF form values.
Using FormDocument = PdfDocument.FromFile("BasicForm.pdf")
	
	'Set and Read the value of the "firstname" field
	Dim FirstNameField = FormDocument.Form.GetFieldByName("firstname")
	FirstNameField.Value = "Minnie"
	Console.WriteLine("FirstNameField value: {0}", FirstNameField.Value)
	
	'Set and Read the value of the "lastname" field
	Dim LastNameField As IronPdf.Forms.FormField = FormDocument.Form.GetFieldByName("lastname")
	LastNameField.Value = "Mouse"
	Console.WriteLine("LastNameField value: {0}", LastNameField.Value)
	
	FormDocument.SaveAs("FilledForm.pdf")
End Using

PDFs with editable forms can be created from HTML simply by adding <form>, <input>, and <textarea> tags. The PdfDocument.Form.GetFieldByName can be used to read and write the value of any form field. The name of the field will be the same as the 'name' attribute given to that field in your HTML. The PdfDocument.Form object can be used to:
- Populate the default value of form fields (must be focused in Adobe Reader to display this value)
- Read data from user filled PDF forms in any language.

C# + VB.Net: Rasterize a PDF to Images Rasterize a PDF to Images
// PM> Install-Package IronPdf
using IronPdf;
using System.Drawing;

//Example rendering PDF documents to Images or Thumbnails

using 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\thumbnail_*.jpg", 100, 80);


//Extract all pages as System.Drawing.Bitmap objects
System.Drawing.Bitmap[] pageImages = Pdf.ToBitmap();
' PM> Install-Package IronPdf
Imports IronPdf
Imports System.Drawing

'Example rendering PDF documents to Images or Thumbnails

Private var As using

'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\thumbnail_*.jpg", 100, 80)


'Extract all pages as System.Drawing.Bitmap objects
Dim pageImages() As System.Drawing.Bitmap = Pdf.ToBitmap()

IronPDF allows any PDF document to be exported to image files in convenient formats or Bitmap objects. Image dimensions and page number ranges may also be specified.

C# + VB.Net: Editing PDFs Editing PDFs
// PM> Install-Package IronPdf
using IronPdf;
using System.Collections.Generic;

// Instantiate Renderer
var Renderer = new IronPdf.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"));
using 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");

foreach (var pdf in PDFs)
{
	pdf.Dispose();
}
' PM> Install-Package IronPdf
Imports IronPdf
Imports System.Collections.Generic

' Instantiate Renderer
Private Renderer = New IronPdf.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"))
Using 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")
	
'INSTANT VB NOTE: The variable pdf was renamed since Visual Basic will not allow local variables with the same name as parameters or other local variables:
	For Each Me.pdf_Conflict In PDFs
		Me.pdf_Conflict.Dispose()
	Next pdf_Conflict
End Using

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.

C# + VB.Net: Passwords, Security and MetaData Passwords, Security and MetaData
// PM> Install-Package IronPdf
using IronPdf;

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

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

//Edit file security settings

//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 encrpytion password
Pdf.SecuritySettings.OwnerPassword = "top-secret"; // password to edit the pdf
Pdf.SecuritySettings.UserPassword = "sharable";  // password to open the pdf
Pdf.SaveAs("secured.pdf");
' PM> Install-Package IronPdf
Imports IronPdf

'Open an Encrypted File, alternatively create a new PDF from Html
Private PdfDocument As using

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

'Edit file security settings

'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 encrpytion 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.Net: PDF Watermarking PDF Watermarking
// PM> Install-Package IronPdf
using IronPdf;

// Stamps a Watermark onto a new or existing PDF
var Renderer = new IronPdf.ChromePdfRenderer();

using var Pdf = Renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
Pdf.WatermarkAllPages("<h2 style='color:red'>SAMPLE</h2>", IronPdf.Editing.WaterMarkLocation.MiddleCenter, 50, -45, "https://www.nuget.org/packages/IronPdf");
Pdf.SaveAs(@"C:\Path\To\Watermarked.pdf");
' PM> Install-Package IronPdf
Imports IronPdf

' Stamps a Watermark onto a new or existing PDF
Private Renderer = New IronPdf.ChromePdfRenderer()

Private var As using
Pdf.WatermarkAllPages("<h2 style='color:red'>SAMPLE</h2>", IronPdf.Editing.WaterMarkLocation.MiddleCenter, 50, -45, "https://www.nuget.org/packages/IronPdf")
Pdf.SaveAs("C:\Path\To\Watermarked.pdf")

IronPDF provides methods to 'watermark' PDF documents with HTML. Watermarks may be set to render above or below existing content, and have built in capacity for opacity, rotation and hyperlinks.

You can download a file project from this link.

C# + VB.Net: Backgrounds & Foregrounds Backgrounds & Foregrounds
// PM> Install-Package IronPdf
using IronPdf;

// With IronPDF, we can easily merge 2 PDF files using one as a backgorund or foreground
var Renderer = new IronPdf.ChromePdfRenderer();
using 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");
' PM> Install-Package IronPdf
Imports IronPdf

' With IronPDF, we can easily merge 2 PDF files using one as a backgorund or foreground
Private Renderer = New IronPdf.ChromePdfRenderer()
Private var As using
pdf.AddBackgroundPdf("MyBackground.pdf")
pdf.AddForegroundOverlayPdfToPage(0, "MyForeground.pdf", 0)
pdf.SaveAs("C:\Path\To\Complete.pdf")

An existing or rendered PDF may be used as the Background or Foreground for another PDF document. This is particularly useful for design consistency and templating.

How add a Background (or overlay) to a PDF in C#

  1. Load or create a multi-page PDF as an IronPdf.PdfDocument object.
  2. You can add backgrounds using PdfDocument.AddBackgroundPdf. There are several background insertion methods and overrides in the IronPdf.PdfDocument documentation
  3. You can add Foregrounds also known as "Overlays" using PdfDocument.AddForegroundOverlayPdfToPage. There are several foreground insertion methods and overrides in the IronPdf.PdfDocument documentation
  4. Save the PDF to disk, or serve it as a FileActionResult via MVC.

Support For .NET Core Coders

Regardless of whether its technical or sales inquiries, the Iron Team are close by to help with the majority of your questions. Connect with Iron to benefit as much as possible from our library in your project.

Get in Touch
C# .NET HTML-to-PDF

C# & VB HTML-to-PDF Library for .NET Core

IronPDF utilizes a Chromium renderer for .NET Chromium to convert HTML files to PDF documents. There's no need for APIs to position or layout PDFs: IronPDF uses standard HTML, ASPX, JS, CSS and Images.

See Tutorials
C# .NET PDF OCR Library

Read PDF Text

IronPDF enables you to extract all embedded text content from PDFs to pass into your C# & .NET Core APPs. Import content from PDF archives into your business process systems.

Full API Reference
How To Edit PDF Documents in C#

Edit PDFs in .NET Core

From Appending, converging, parting, and altering PDFs, utilize your own coding skills to precisely to get the correct PDF every time. IronPDF puts the development capabilities specifically into your hands, inside your C#/VB .NET Core Project.

Read Our Docs
Convert HTML5, JS, CSS and Image files to PDF documents using  .NET Code.

Supports Your Document Types

Point IronPDF .NET Core Library at your HTML file, string or URL to simply convert to PDF. This uses your current documents and website pages to render your information to a PDF file.

For ASP Dot Net Core, C#, VB, MVC, ASPX, .Net

Get Setup Now
Visual Studio Library for PDF Creation and Content Editing.

Get Going Fast with Microsoft Visual Studio

IronPDF puts PDF creation and editing control in your very own hands, rapidly with complete intellisense support and a Visual Studio installer. Use NuGet for Visual Studio or download the DLL. You'll be set up in a matter of moments. Only one DLL.

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 $499.

Project C# + VB.NET 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 Tutorials From Our Community

Tutorial + Code Examples ASPX to PDF | ASP.NET Tutorial

C# PDF ASP.NET ASPX

Jacob Müller Software Product Designer @ Team Iron

ASPX to PDF | ASP.NET Tutorial

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 | C Sharp & VB.Net Tutorial

C# PDF HTML

Jean Ashberg .NET Software Engineer

C# HTML to PDF | C Sharp & VB.Net Tutorial

For many this is the most efficient way to generate PDF files from .Net, because there is no additional 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

Learn how to create and edit PDF documents in VB.Net applications and websites. A free tutorial with code examples.…

View Veronica's Vb.Net PDF 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
Join Them Today
Iron Software Enterprise .NET Component Developers

Thousands of corporations, governments, SMEs and developers alike trust Iron software products.

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

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