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.
PdfDocument constructor API is consistent across supported runtimes (.NET Framework 4.6.2+, .NET Core 3.1+, .NET 5 and later), though performance on older runtimes will differ from the benchmarks below.// 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
Dim pdf As New IronPdf.PdfDocument(270, 270)
' 3. Or convert HTML to PDF
Dim renderer As New IronPdf.ChromePdfRenderer()
Dim pdfFromHtml As IronPdf.PdfDocument = renderer.RenderHtmlAsPdf("<h1>Hello PDF!</h1>")
' 4. Save your PDF
pdf.SaveAs("myNewPdf.pdf")Minimal Workflow (5 steps)
- Download IronPDF from NuGet for creating new PDFs
- Use the PdfDocument constructor to create a blank PDF
- Import existing PDF from file, URL, byte array, or JSON
- Convert multiple formats to PDFs such as HTML, RTF, Markdown, images, and XML
- Export the PDF document
How Do I Create a Blank PDF?
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, with page orientation control alongside them.
What Parameters Are Required for a Blank PDF?
using IronPdf;
PdfDocument pdf = new PdfDocument(270, 270);
pdf.SaveAs("blankPage.pdf");Imports IronPdf
Dim pdf As New PdfDocument(270, 270)
pdf.SaveAs("blankPage.pdf")How Fast Is Blank PDF Creation?
| Metric | Blank A4 | A4 + Metadata | A4 (10 pages) | Letter | Custom (270×270) |
|---|---|---|---|---|---|
| Average create time | 266.6 ms | 279.4 ms | 287.2 ms | 262.4 ms | 280.6 ms |
| Output file size | 0.60 KB | 3.82 KB | 1.79 KB | 0.60 KB | 0.60 KB |
| Memory per call | 1.62 MB | 1.61 MB | 1.64 MB | 1.61 MB | 1.62 MB |
| Pages produced | 1 | 1 | 10 | 1 | 1 |
Creation time stays flat at roughly 260-290 ms across every variation, and file size, not speed, is what moves when you add metadata or pages. Once you've created a blank PDF, you can enhance it with headers and footers, watermarks, or inserted 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.
You can also load PDFs from memory streams for efficient processing without touching the file system.
Which Import Methods Are Available?
using IronPdf;
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");
pdf.SaveAs("export.pdf");Imports IronPdf
Private pdf As PdfDocument = PdfDocument.FromFile("sample.pdf")
pdf.SaveAs("export.pdf")After importing, you can perform operations like extracting text and images, adding annotations, or applying digital signatures.
The IronSuite play a crucial role in our operations. These are tools that increase efficiencies across the business including creating floor plans and improving inventory management.
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 main 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 highly accurate conversions that preserve 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. The format list below covers Markdown, XML, and image conversion as well.
What Rendering Options Should I Configure?
Set RenderingOptions on the renderer before the call: paper size, margins, and header or footer HTML all live there.
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");Imports IronPdf
' Instantiate Renderer
Private 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
Dim pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/")
' Export to a file or Stream
pdf.SaveAs("url.pdf")Output
Which Formats Can Be Converted to PDF?
IronPDF supports conversion from multiple formats:
- HTML to PDF: Convert HTML strings, HTML files, or URLs with full CSS and JavaScript support
- Image to PDF: Convert JPG, PNG, GIF, BMP, and TIFF images
- Document Formats: Convert DOCX and RTF files
- Markup Languages: Convert Markdown and XML
- ASP.NET Pages: Convert ASPX and Razor pages
Conclusion
A PdfDocument starts from a constructor, an import, or a conversion, and every route ends at the same object: create it blank and stamp content on, load it with FromFile and edit, or render it from HTML, images, RTF, Markdown, or XML. From here, export the result to disk, memory, or an HTTP response, or start from a Word file with DOCX to PDF.
Frequently Asked Questions
How do I create a new PDF in C# using IronPDF?
To create a new PDF in C# with IronPDF, install IronPDF via NuGet, then use the `PdfDocument` constructor for a blank PDF or utilize the `ChromePdfRenderer` for converting HTML to PDF. Save the PDF using the `SaveAs` method.
Can I convert HTML to PDF using IronPDF?
Yes, you can convert HTML to PDF using IronPDF's `ChromePdfRenderer`. This method supports full CSS and JavaScript rendering, ensuring visual fidelity.
What are the available import methods for PDFs in IronPDF?
IronPDF supports importing PDFs from various sources using the `FromFile` method, including file paths, URLs, JSON, byte arrays, and streams.
What formats can be converted to PDF using IronPDF?
IronPDF can convert multiple formats to PDF, including HTML, images (JPG, PNG, GIF, BMP, TIFF), DOCX, RTF, Markdown, XML, and ASP.NET pages like ASPX and Razor pages.
How can I create a blank PDF with specific dimensions using IronPDF?
Use the `PdfDocument` constructor, specifying the width and height in points to create a blank PDF with custom dimensions.
Does IronPDF support PDF creation with custom paper sizes?
Yes, IronPDF allows setting custom paper sizes and offers various predefined formats like Letter, A4, and Legal, with controls for page orientation.
Is it possible to extract text and images from PDFs using IronPDF?
Yes, after importing a PDF into IronPDF, you can extract text and images, add annotations, or apply digital signatures.
What should I configure when converting HTML to PDF using IronPDF?
When using IronPDF to convert HTML to PDF, configure `RenderingOptions` such as paper size, margins, and enabling JavaScript execution to ensure precise rendering.
How fast is creating a blank PDF with IronPDF?
Creating a blank PDF with IronPDF is efficient, taking approximately 260-290 ms depending on the page dimensions and whether metadata or multiple pages are included.
Can IronPDF handle legacy HTML markup in conversions?
IronPDF, like other Chromium-based renderers, can encounter layout issues with legacy HTML. It's recommended to validate HTML before conversion for better results.

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.