How to Create a New PDF from Scratch in C#

Curtis Chau
Curtis Chau
Updated: October 14, 2026

IronPDF builds a new PDF directly in C#, with no HTML and no Chrome renderer: the PdfDocument constructor returns a blank page of any size, and the DrawText, DrawBitmap, DrawLine and DrawRectangle methods put content on it. This route suits fixed layouts where you control every coordinate, such as labels, certificates, tickets and overlays, and simple generated documents that need no HTML templating. It is one of several routes to PDF generation in .NET; starting from HTML? See HTML String to PDF.

Please note: Last verified on an AMD Ryzen 7 5800U workstation (8 cores / 16 threads, 16 GB RAM, Windows 11, .NET 8, IronPDF 2026.7.2). The 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.
Quickstart: Create Your First PDF in C#
// 1. Install IronPDF from NuGet
// 2. Create a blank PDF page, 270 by 270 millimetres
var pdf = new IronPdf.PdfDocument(270, 270);

// 3. Draw text on the first page, X and Y in points from the bottom-left corner
pdf.DrawText("Hello PDF!", IronSoftware.Drawing.FontTypes.TimesNewRoman.Name, FontSize: 18, PageIndex: 0, X: 40, Y: 120, IronSoftware.Drawing.Color.Black, Rotation: 0);

// 4. Save your PDF
pdf.SaveAs("myNewPdf.pdf");
C#
Tips: Working with an AI coding assistant? The AI setup guide shows how to point it at IronPDF's documentation, so the code it writes against this page compiles on the first try.

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 millimetres, 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.

How Are Page Dimensions Measured?

using IronPdf;

// Create a blank page, width and height in millimetres
PdfDocument pdf = new PdfDocument(270, 270);

pdf.SaveAs("blankPage.pdf");
C#

The constructor takes a width and a height in millimetres, so the common paper sizes are:

Paper sizePortrait (width × height, mm)Landscape
A4210 × 297297 × 210
Letter215.9 × 279.4279.4 × 215.9
Legal215.9 × 355.6355.6 × 215.9

Swap the two values for landscape. The 270 × 270 page above is 270 mm square.

Warning: The constructor works in millimetres, but the Draw methods below work in points (1/72 of an inch), measured from the bottom-left corner of the page. An A4 page is 595 × 842 points to draw on, and a larger Y is higher on the page.

How Fast Is Blank PDF Creation?

MetricBlank A4A4 + MetadataA4 (10 pages)LetterCustom (270×270)
Average create time266.6 ms279.4 ms287.2 ms262.4 ms280.6 ms
Output file size0.60 KB3.82 KB1.79 KB0.60 KB0.60 KB
Memory per call1.62 MB1.61 MB1.64 MB1.61 MB1.62 MB
Pages produced111011
Please note: The table above shows how the snippet performs when you vary the page dimensions, add metadata, or merge multiple blank pages. Each variation runs in its own process; numbers are averaged over 5 iterations after a warm-up.

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 Do I Add More Pages?

The constructor returns one page. To build a longer document, create further blank pages and join them: AppendPdf adds another PdfDocument after the last page, and InsertPdf places one at a given index, so a landscape page can sit in front of portrait ones.

using IronPdf;

// Create a blank A4 page, 210 by 297 millimetres
PdfDocument pdf = new PdfDocument(210, 297);

// Append another blank page at the end
pdf.AppendPdf(new PdfDocument(210, 297));

// Insert a landscape A4 page at index 0, so it becomes the first page
pdf.InsertPdf(new PdfDocument(297, 210), 0);

pdf.SaveAs("threePages.pdf");
C#

Pages are indexed from 0 when you draw on them. To copy, reorder or delete pages later, see add, copy and delete PDF pages.

How Do I Draw Text on a Page?

DrawText places a string at a point on one page. It takes the text, a font name, the font size, the page index, the X and Y position in points from the bottom-left corner, a colour and a rotation. FontTypes in IronSoftware.Drawing lists the built-in fonts by name, and Color accepts a named colour or a hex string.

using IronPdf;
using IronSoftware.Drawing;

// Create a blank A4 page
PdfDocument pdf = new PdfDocument(210, 297);

// Draw a heading near the top, X and Y in points from the bottom-left corner
pdf.DrawText("Certificate of Completion", FontTypes.TimesNewRoman.Name, FontSize: 24, PageIndex: 0, X: 60, Y: 760, Color.Black, Rotation: 0);

// Draw a smaller line of text 30 points below the heading
pdf.DrawText("Awarded to Morgan Ellis", FontTypes.TimesNewRoman.Name, FontSize: 14, PageIndex: 0, X: 60, Y: 730, Color.Black, Rotation: 0);

pdf.SaveAs("drawText.pdf");
C#

For custom font files and the full parameter reference, see draw text and bitmaps.

How Do I Draw Images?

DrawBitmap places an AnyBitmap on a page at a position and size in points, with the position marking the image's bottom-left corner, scaling the image to the width and height you give. Load the image with AnyBitmap.FromFile, then draw it on the page index you choose.

using IronPdf;
using IronSoftware.Drawing;

// Create a blank A4 page
PdfDocument pdf = new PdfDocument(210, 297);

// Load the image from file
AnyBitmap logo = AnyBitmap.FromFile("logo.png");

// Draw the image 200 by 80 points, its bottom-left corner at 60, 60
pdf.DrawBitmap(logo, 0, 60, 60, 200, 80);

pdf.SaveAs("drawImage.pdf");
C#

The same call works for logos, signatures and photographs. Transparency is controlled by the optional PixelFormat argument, covered in draw text and bitmaps.

My favorite library of this kind is IronPDF. It allows for fast and efficient manipulation of PDF files. It also has many valuable features, like exporting to PDF/A format and digitally signing PDF documents.

Milan Jovanovic

Microsoft MVP

View case study

IronOCR means we can save $40,000 annually from manual processing, while enhancing productivity and freeing up resources for high-impact tasks. I would highly recommend it.

Brent Matzelle

Chief Technology Officer, OPYN

View case study

How Do I Draw Lines and Rectangles?

DrawLine joins two PointF positions with a stroke of the width and colour you give. DrawRectangle takes a RectangleF (the X and Y of its bottom-left corner, then width and height), a border colour, a fill colour and a border width. Both types come from IronSoftware.Drawing, and both methods draw on one page index.

using IronPdf;
using IronSoftware.Drawing;

// Create a blank A4 page
PdfDocument pdf = new PdfDocument(210, 297);

// Draw a 1-point black line, 110 points up from the bottom of the page
pdf.DrawLine(0, new PointF(60, 110), new PointF(535, 110), 1, Color.Black);

// Draw a 475 by 80 point box above the line, with a black border and a pale blue fill
pdf.DrawRectangle(0, new RectangleF(60, 140, 475, 80), Color.Black, new Color("#F1F9FB"), 1);

pdf.SaveAs("drawShapes.pdf");
C#

Rules, boxes and table grids are the usual uses. For further examples, see draw lines and rectangles.

Output

Both shapes sit exactly at their coordinates, measured up from the bottom of the page.


How Do I Add Headers, Page Numbers and Metadata?

Headers and footers are added to the finished document rather than drawn: AddTextHeaders and AddTextFooters take a TextHeaderFooter and stamp it on every page, and the {page} and {total-pages} placeholders expand per page. Document properties live on MetaData, which exposes Title, Author, Subject, Keywords and the creation and modification dates.

using IronPdf;
using System;

// Create a two-page A4 document
PdfDocument pdf = new PdfDocument(210, 297);
pdf.AppendPdf(new PdfDocument(210, 297));

// Create a text header, and a footer whose placeholders print as 1 of 2, 2 of 2
TextHeaderFooter header = new TextHeaderFooter
{
    CenterText = "Monthly Report",
};
TextHeaderFooter footer = new TextHeaderFooter
{
    CenterText = "{page} of {total-pages}",
};

// Add them to every page
pdf.AddTextHeaders(header);
pdf.AddTextFooters(footer);

// Set the title, author and creation date shown in the document properties
pdf.MetaData.Title = "Monthly Report";
pdf.MetaData.Author = "Iron Software";
pdf.MetaData.CreationDate = DateTime.Today;

pdf.SaveAs("reportWithHeaders.pdf");
C#

Both methods accept a list of page indexes to limit which pages receive the header or footer. HTML headers and footers and their margins are covered in headers and footers and page numbers; custom properties in metadata.

Output

Each page is numbered automatically, and the metadata appears under the PDF's document properties.


When Should I Use HTML to PDF Instead?

Drawing gives exact control and no layout engine, which is what a fixed template wants. The moment the content needs to flow, wrap, paginate or restyle, write it as HTML and render it with ChromePdfRenderer instead: text reflows around images, tables break across pages, and CSS does the styling. HTML String to PDF is the starting point, and the PDF generation overview lists the other sources IronPDF renders.

Conclusion

This guide covered creating a blank PDF with a set page size, adding pages, drawing text, images and shapes, and adding headers, page numbers and metadata. To save the finished document to disk, memory or an HTTP response, see Save and Export PDF Documents. If your content is easier to lay out in HTML, use HTML String to PDF instead.

Frequently Asked Questions

How do I create a new PDF in C# using IronPDF?

Install IronPDF from NuGet, create a PdfDocument with the constructor, passing the page width and height in millimetres, draw content onto it with the Draw methods, then call SaveAs to write the file.

How do I create an A4 or Letter page from scratch?

Pass the width and height in millimetres to the PdfDocument constructor: new PdfDocument(210, 297) for A4 and new PdfDocument(215.9, 279.4) for US Letter. Swap the two values for landscape.

How do I add more pages to a PDF created from scratch?

Create another blank PdfDocument and join it to the first: AppendPdf adds it after the last page and InsertPdf places it at the index you specify.

How do I draw text on a blank PDF with IronPDF?

Call DrawText with the text, a font name from FontTypes, the font size, the page index, the X and Y position in points from the bottom-left corner, a Color and a rotation. Each call draws one string on one page.

How do I draw text in a custom font?

Read the font file's bytes and add them with pdf.Fonts.Add, then pass the returned font's Name to DrawText. The font is embedded in the PDF as soon as it is added, so there is no need to call Embed() as well.

How do I add an image to a PDF created from scratch?

Load the image as an AnyBitmap, for example with AnyBitmap.FromFile, then call DrawBitmap with the page index, the X and Y position, and the width and height in points.

Can I draw lines and rectangles on a PDF with IronPDF?

Yes. DrawLine takes a page index, two PointF positions, a width and a Color. DrawRectangle takes a page index, a RectangleF, a border colour, a fill colour and a border width.

Can I put page numbers in the footer instead of the header?

Yes. Put {page} and {total-pages} in a TextHeaderFooter and pass it to AddTextFooters instead of AddTextHeaders. The placeholders are replaced on every page, in a footer as in a header.

How do I set the title and author of a PDF in IronPDF?

Set the properties on MetaData, such as Title, Author, Subject, Keywords, CreationDate and ModifiedDate, before saving.

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.

Should I build from scratch or use an HTML template for tickets, labels or invoices?

Draw from scratch when every element sits at a fixed position, as on tickets and labels. Use an HTML template rendered with ChromePdfRenderer when the content changes length, as invoice line items do, because HTML wraps text and breaks tables across pages.

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 21,739,885Version:2026.10just released