C# PDF

ironpdf makes it easy to generate PDF in C#.

C# PDF

C# PDF - PDF Download with C# Code Examples

IronPDF is a convenience C-Sharp package for authoring, editing, extracting and OCRing PDF documents

C# PDF tutorial PDF
Download the C# PDF Tutorial Now


PDF (Portable Document Format) is a document format that duplicates the attributes of a printed document that you can read, create, print or forward digitally. You can make PDF document automatically from C# applications using IronPDF. When you add text or images and so on they look simply like they would if printed. IronPDF is the library that effectively makes PDF files in applications written in C#, VB.Net or any other ASP.NET language. It also fully supports "Html to PDF". IronPDF enables you to make PDF files straightforwardly from your C# web, desktop or console application.

C# PDF Nuget
Install IronPdf for C# PDF Development on Nuget


There are numerous free PDF C# libraries accessible in the web like PDFsharp, iTextSharp and so on. However, IronPDF goes beyond the approach of these to make a library that is both powerful and useful as well as incredibly quick and easy to install. IronPDF is backed up with developer support directly from the Iron software development team. The attached PDF document is intended to help provide the basics to get started with Iron PDF (The .Net PDF creator / converter / gnerator library for C#).

C# PDF Document Team

The C# PDF Document team consists of 3 C# developers and 1 Project Manager located in Wyoming, USA. The team was put together for their skills in the .NET C# programming environment with over 20 years of combined .Net development experience. Our Purpose is to build tutorials and document Iron's PDF product can be used to best effective for industries across the world. IronPDF is a strong and reliable C# VB.NET PDF Library for creating, editing and extracting data content from PDF documents.

PDF (Portable Document Format) is a file format that revolutionized printed document digitalization. Underlying the simple exterior of a PDF document underlies a complex set of functions and algorithms for converting documents to PDFs and preserving the visual integrity of the intended outcome both on screen and in a printed form. Bringing the best of PDF to C# has been a long and sometimes difficult journey involving many developers and software houses throughout the industry.

IronPDF can be downloaded as a dll at http://ironpdf.com/ or utilizing the Nuget Package Manager https://www.nuget.org/packages/IronPdf/ for inclusion into windows / .net programs and web applications.

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.