Today version 0.0.5 of PdfPig was released. This is the first version which includes the ability to create PDF documents in C#.
There aren't many fully open source options around for both reading and writing PDF documents so the addition of PDF document creation to PdfPig is an exciting next step for the API.
The actual design of document creation isn't finished yet and there's more work to be done around the currently unsupported use cases such as splitting, merging and editing existing documents as well as adding non-ASCII text, working with forms and adding images to new documents but the functionality in 0.0.5 should provide enough for simple use cases and the open source Apache 2.0 license means that it can be used in commercial software.
You can create a new document using a document builder:
PdfDocumentBuilder builder = new PdfDocumentBuilder();
This creates a completely empty document. To add the first page we use the imaginatively named add page method.
PdfPageBuilder page = builder.AddPage(PageSize.A4);
This supports various page sizes defined by the
PageSize enum, such as the North American standard
PageSize.Letter. It also allows the choice of portrait (default) or landscape pages.
Once a page builder has been created text, lines and rectangles can be added to it.
In order to draw text a font must be chosen. Version 0.0.5 supports TrueType fonts as well as the 14 default fonts detailed in the PDF Specification. These are called the Standard 14 fonts and while their use is beginning to be phased out, all PDF readers should still support them.