How to Create New PDFs in C# with IronPDF

IronPDF enables C# developers to create new PDF documents programmatically by using the PdfDocument constructor for blank PDFs, importing existing PDFs from various sources, or converting HTML, images, RTF, Markdown, and XML to PDF format. Whether building business reports, generating invoices, or creating dynamic documents from web content, IronPDF provides the tools for PDF generation in .NET applications.

Quickstart: Create Your First PDF in C#

// 1. Install IronPDF from NuGet
// 2. Create a blank PDF
var pdf = new IronPdf.PdfDocument(270, 270);

// 3. Or convert HTML to PDF
var renderer = new IronPdf.ChromePdfRenderer();
var pdfFromHtml = renderer.RenderHtmlAsPdf("<h1>Hello PDF!</h1>");

// 4. Save your PDF
pdf.SaveAs("myNewPdf.pdf");
// 1. Install IronPDF from NuGet
// 2. Create a blank PDF
var pdf = new IronPdf.PdfDocument(270, 270);

// 3. Or convert HTML to PDF
var renderer = new IronPdf.ChromePdfRenderer();
var pdfFromHtml = renderer.RenderHtmlAsPdf("<h1>Hello PDF!</h1>");

// 4. Save your PDF
pdf.SaveAs("myNewPdf.pdf");
$vbLabelText   $csharpLabel

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. Copy and run this code snippet.

    new IronPdf.PdfDocument { DefaultPageSize = new IronPdf.PageSize(270,270) }.SaveAs("blankPage.pdf");
  3. Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer


How Do I Create a Blank PDF Example?

There are multiple ways to create a PDF object. Start with the simplest method, which requires only the width and height of the PDF. This PdfDocument constructor creates a new blank PDF, ready for customization and use. The dimensions are specified in points (1/72 of an inch), enabling precise sizing for various applications like labels, business cards, or custom document formats.

For developers who need more control over page dimensions, IronPDF supports custom paper sizes and various predefined formats including Letter, A4, and Legal sizes. You can set different orientations using the page orientation features.

What Parameters Are Required for a Blank PDF?

:path=/static-assets/pdf/content-code-examples/how-to/create-new-pdfs.cs
using IronPdf;

PdfDocument pdf = new PdfDocument(270, 270);

pdf.SaveAs("blankPage.pdf");
$vbLabelText   $csharpLabel

Once you've created a blank PDF, you can enhance it by adding headers and footers, applying watermarks, or inserting images.


How Can I Import PDF from File?

Before a PDF can be modified or converted, it must first be imported as a PdfDocument object. Use the static FromFile method of the PdfDocument class to accomplish this. Importing PDFs from JSON, byte arrays, streams, and URLs is supported within the same class. This flexibility suits scenarios where you need to merge multiple PDFs, extract specific pages, or modify existing documents.

When working with PDFs stored in cloud services, IronPDF integrates with Azure Blob Storage and other cloud platforms. You can load PDFs from memory streams for efficient processing without file system access.

Which Import Methods Are Available?

:path=/static-assets/pdf/content-code-examples/how-to/create-new-pdfs-from-file.cs
using IronPdf;

PdfDocument pdf = PdfDocument.FromFile("sample.pdf");

pdf.SaveAs("export.pdf");
$vbLabelText   $csharpLabel

After importing, you can perform various operations like extracting text and images, adding annotations, or applying digital signatures.


How Do I Convert from Other Formats?

In addition to the previously mentioned methods for obtaining a PdfDocument object, you can convert various formats into PDF. The most sophisticated method is converting HTML to PDF, which renders the HTML along with all its assets—including JavaScript, images, links, and CSS styling using the Chrome engine. Besides HTML, you can convert other formats into PDFs, such as images, RTF, Markdown, and XML.

IronPDF's Chrome rendering engine ensures pixel-perfect conversions that maintain the visual fidelity of your source content. The renderer supports modern web standards including HTML5, CSS3, and JavaScript frameworks, making it suitable for converting complex web pages or Razor views into PDFs.

The following code snippet demonstrates converting HTML to PDF. The HTML conversion uses IronPDF's rendering engine to maintain content integrity with all styling applied. You can also convert Markdown to PDF, XML to PDF, and images to PDF.

What Rendering Options Should I Configure?

:path=/static-assets/pdf/content-code-examples/how-to/create-new-pdfs-from-html.cs
using IronPdf;

// Instantiate Renderer
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.EnableJavaScript = true;
renderer.RenderingOptions.PrintHtmlBackgrounds = true;
renderer.RenderingOptions.PaperFit.UseResponsiveCssRendering(1800);
renderer.RenderingOptions.WaitFor.RenderDelay(5000);
renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;

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

Which Formats Can Be Converted to PDF?

IronPDF supports conversion from multiple formats:

The generated PDF can be viewed using an embedded PDF viewer, as shown here. The iframe below displays the output PDF.

For advanced scenarios, explore rendering WebGL sites, handling JavaScript delays, or implementing custom logging for troubleshooting conversion issues.

Frequently Asked Questions

How do I install the library to start creating PDFs in C#?

Install IronPDF via NuGet Package Manager in Visual Studio. You can search for 'IronPDF' in the NuGet Package Manager UI or use the Package Manager Console with the command 'Install-Package IronPdf'. Once installed, you can immediately start creating PDFs using the PdfDocument constructor or ChromePdfRenderer class.

What's the quickest way to create a blank PDF document?

The fastest way to create a blank PDF with IronPDF is using the PdfDocument constructor with width and height parameters: new IronPdf.PdfDocument(270, 270).SaveAs('blank.pdf'). The dimensions are specified in points (1/72 of an inch). You can also set custom page sizes, orientations, and add metadata like author and title.

Can I convert HTML content to PDF format?

Yes, IronPDF excels at HTML to PDF conversion using the ChromePdfRenderer class. Simply create a renderer instance and use RenderHtmlAsPdf() method: var renderer = new IronPdf.ChromePdfRenderer(); var pdf = renderer.RenderHtmlAsPdf('

Hello PDF!

'). This supports full HTML5, CSS3, and JavaScript rendering.

What file formats can be converted to PDF?

IronPDF supports converting multiple formats to PDF including HTML, images (JPG, PNG, GIF, BMP), RTF documents, Markdown files, and XML. Each format has specific methods - for example, use RenderHtmlAsPdf() for HTML, ImageToPdf() for images, and specialized renderers for other formats.

How do I add custom metadata to my PDF documents?

After creating a PdfDocument with IronPDF, access the MetaData property to set custom information: pdf.MetaData.Author = 'Your Name'; pdf.MetaData.Title = 'Document Title'; pdf.MetaData.CreationDate = DateTime.Now. This metadata helps with document organization and searchability.

Can I import existing PDFs from different sources?

IronPDF allows importing existing PDFs from various sources including local files, URLs, byte arrays, or JSON data. Use PdfDocument.FromFile() for local files, FromUrl() for web-based PDFs, or FromBytes() for byte array data. This enables you to work with and modify existing PDF documents.

How do I add multiple pages to a PDF document?

Use the AppendPage() method on your PdfDocument object to add blank pages dynamically. IronPDF also supports inserting pages at specific positions, copying pages from other PDFs, and merging multiple PDF documents together. Each new page inherits the default page size unless specified otherwise.

What page sizes and orientations are supported?

IronPDF supports custom paper sizes specified in points, as well as predefined formats like Letter, A4, and Legal. You can set page orientation (portrait or landscape) and create documents with mixed page sizes. Custom dimensions give you precise control for specialized applications like labels or business cards.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More
Ready to Get Started?
Nuget Downloads 17,012,929 | Version: 2025.12 just released