The C# PDF Library

ironpdf makes it easy to generate pdfs in your .net apps & websites.

C# PDF

PDF Generation for .Net Developers

IronPDF is the fun, stable C# PDF Library. It makes use of skills that developers already have... generating PDFs from C#, Html or Aspx in milliseconds.

Because there is no new API to learn, most coders are up and running in 60 seconds using the Nuget installer for Visual Studio.   C# PDF Cheat Sheet »   Features »   Install Now »

C# HTML TO PDF

IronPdf provides a diverse PDF generation library for C# and .Net developers. It is suitable for use in windows Applications, WPF, MVC and ASPX based .net websites and applications.

IronPDF.ASPXtoPDF

The ASPXtoPDF class allowing any .net web forms web application page (ASPX) to be turned into a PDF. The content remains the same, but the output format becomes a PDF instead of HTML. This functionality can be implemented in 1 line.

The AspxToPdf.FileBehaviour enumeration allows the developer to choose the PDF to behave as either an attachment, or a PDF in browser.

IronPDF.HTMLToPDF

A class allowing the generation of a PDF file from .Net code. The PDF is designed using HTML, wither in the form of inline HTML, or as URL to a web page.

Usging HTML as the design language means makes PDF design and development easy, without needing to learn a long, complex API

IronPDF.PDFPrintOptions

The PDFPrintOptions print options class allows fit tuning of PDF output behavior including:

  • Turning HTML forms into Editable PDF forms data collection
  • Settings High DPI for high quality print jobs
  • Choosing between media='screen' and media='print stylesheets'
  • Enabling or Disabling javascript and AJAX
  • Custom or Standardized Paper sizes
  • Customized paper margins, including zero-margin printing
  • Adding Headers and Footers with optional page-numbering
Requirements

IronPdf can be used in any .Net App or website targeting Framework 4.0 or higher, on the windows platforms.


C# HTML TO PDF

HTML to PDF

The IronPDF HTML to PDF class allows .Net developers to create PDFs from HTML

You can point it to any web-page, or input HTML as a string, and wham - you have created a PDF file with your .Net App or Website.


ASPX TO PDF

ASPX to PDF

The IronPDF ASPX to PDF function is a new concept in PDF generation for ASP.Net Developers that involves almost no additional coding.

Add IronPDF.ASPXToPDF to any ASPX Web Page to instantly transform it from HTML into an identical Pdf file.

Start generating PDFs in .Net in 60 seconds…

Install C# PDF into Visual Studio

Install IronPdf to your .Net Project

The easiest way to install IronPdf is using NuGet Package Manager for Visual-Studio:

  1. The package name is "IronPdf"
  2. If NuGet is unfamiliar to you… read this tutorial
  3. If you would prefer to download IronPDF as a dll and install manually, be our guest.
C# PDF Example Code Demo

Get Coding

IronPDF has a very simple API based on HTML as a design language:

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");
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;  //millimenters
Renderer.PrintOptions.MarginLeft = 20;  //millimenters
Renderer.PrintOptions.MarginRight = 20;  //millimenters
Renderer.PrintOptions.MarginBottom = 40;  //millimenters

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


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

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



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

private void Form1_Load(object sender, EventArgs e)
{
PdfPrintOptions Options = new PdfPrintOptions()
{
DPI = 300,
EnableJavaScript = false,
//.. many more options available  
};
AspxToPdf.RenderThisPageAsPDF(AspxToPdf.FileBehaviour.Attachment,Options,"MyPdfFile.pdf");
}
using IronPdf;

private void Form1_Load(object sender, EventArgs e)
{
AspxToPdf.RenderThisPageAsPDF();      
//Changes the ASPX output into a pdf instead of html   
}
using IronPdf;
//Open an Encrypted File
PdfDocument PDF = PdfDocument.FromFile("encrypted.pdf", "password");

// Save and change the encryption password.
PDF.Password = "my-password";
PDF.SaveAs("secured.pdf");
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");
//  Extracting PDF Image and Text Content

using IronPdf;

// open a 128 bit encrypted PDF
PdfDocument PDF = PdfDocument.FromFile("encrypted.pdf", "password");

//Get all text to put in a search index
string AllText = PDF.ExtractAllText();

//Get all Images
IEnumerable<ystem.Drawing.Image> AllImages = PDF.ExtractAllImages();

//Or even find the precise text and images for each page in the document
for (var index = 0; index < PDF.PageCount; index++) {
    int PageNumber = index + 1;
    string Text = PDF.ExtractTextFromPage(index);
    IEnumerable<System.Drawing.Image> Images = PDF.ExtractImagesFromPage(index);
    ///...
}
using IronPdf;

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

// add a header to very 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} 
 

using IronPdf;

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


// Build a footer using html to styjle 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 assset
// 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 New IronPdf.HtmlToPdf()


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

' Build a header using an image assset
' Note the use of BaseUrl to set a relative path to the assets
Renderer.PrintOptions.Header = New HtmlHeaderFooter() With { .Height = 20, .HtmlFragment = "<img src='logo.png'>", .BaseUrl = New Uri("C:\assets\image").AbsoluteUri  }
Imports IronPdf 
Dim Renderer As New IronPdf.HtmlToPdf()

IronPdf.HtmlToPdf Renderer = new IronPdf.HtmlToPdf()

' add a header to very 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 New IronPdf.HtmlToPdf()

' Render an HTML document or snippet as a string     
Renderer.RenderHtmlAsPdf("Hello World").SaveAs("html-string.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.RenderHTMLFileAsPdf("my-content.html").SaveAs("my-content.pdf")

Imports IronPdf

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

Imports IronPdf

Private Sub Form1_Load(sender As Object, e As EventArgs)
    '.. many more options available  
  Dim Options As New PdfPrintOptions() With { .DPI = 300, .EnableJavaScript = False    }
  AspxToPdf.RenderThisPageAsPDF(AspxToPdf.FileBehaviour.Attachment, Options, "MyPdfFile.pdf")
End Sub
Imports IronPdf

Private Sub Form1_Load(sender As Object, e As EventArgs)
  AspxToPdf.RenderThisPageAsPDF()
  'Changes the ASPX output into a pdf instead of html in 1 line of VB code
End Sub
Imports IronPdf
Dim PDF As PdfDocument = PdfDocument.FromFile("encrypted.pdf", "password")

' Save and change the encryption password.
PDF.Password = "my-password"
PDF.SaveAs("secured.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")
'  Extracting PDF Image and Text Content

Imports IronPdf
' open a 128 bit encrypted PDF
Dim PDF As PdfDocument = PdfDocument.FromFile("encrypted.pdf", "password")

'Get all text to put in a search index
Dim AllText As String = PDF.ExtractAllText()

'Get all Images
Dim AllImages As IEnumerable(Of System.Drawing.Image) = PDF.ExtractAllImages()

'Or even find the precise text and images for each page in the document
For index As var = 0 To PDF.PageCount - 1
  Dim PageNumber As Integer = index + 1
  Dim Text As String = PDF.ExtractTextFromPage(index)
    '''...
  Dim Images As IEnumerable(Of System.Drawing.Image) = PDF.ExtractImagesFromPage(index)
Next

This is the droid you have been looking for…

C# PDF Generator Documentation

Well Documented

Clear online manuals in plain English.

C# & VB Docs
C# PDF Library Licensing

Flexibly Licensed

Free Development. Commercial from $299.

Explore Licenses
C# PDF Open-Source Examples

Human Support

Talk directly with our development team

Ask a Question
visual studio Install C# PDF Generator by IronPdf

1 Minute Setup

Use Nuget Package Manager to install in under 60 seconds.