Guide
How to create a blank PDF in C#
Use Pdf.Create(...) to start a new document, choose the page size up front, and save the
output stream.
A new PDF starts with one page. From there you can keep the default page, set a specific media box, or add more pages before you save.
The shortest working example
If you just need a blank PDF with the default first page, create it and save it.
using ZingPDF;
using var pdf = Pdf.Create();
using var output = File.Create("blank.pdf");
await pdf.SaveAsync(output);
Set the page size when you create the document
If you already know the page size you want, set the media box during creation.
using ZingPDF;
using ZingPDF.Syntax.CommonDataStructures;
using var pdf = Pdf.Create(options =>
{
options.MediaBox = Rectangle.FromDimensions(595, 842);
});
await pdf.SaveAsync(File.Create("a4-blank.pdf"));
That keeps the first page aligned with the output you want instead of creating a default page and changing it later.
Add more pages before you save
A new document starts with one page, so call AppendPageAsync(...) when you need more.
using var pdf = Pdf.Create(options =>
{
options.MediaBox = Rectangle.FromDimensions(595, 842);
});
await pdf.AppendPageAsync();
await pdf.AppendPageAsync();
await pdf.SaveAsync(File.Create("three-pages.pdf"));
Ready to put content on the page?
The next step is usually drawing text, paths, or images onto the new document.