This article is about the simple .NET PDF generator and visual designer called the SmallPDFDesigner. This is the first release of this tool. A separate class library was developed (the SmallPDFDesigner .NET SDK) as the primary extension tool for the 3rd party solutions. The presented visual designer offers the basic functionality for the PDF documents visual creation. You can add pages (set format and orientation), and page elements (images, text fields and graphic objects such as straight lines and rectangles). Each of these page elements can be modified additionaly.
There are many different solutions for PDF design and generation on the CodeProject web site, so feel free to explore them, and compare to this one. There was no intention to write the ultimate PDF visual design tool, nor the SDK, but only the basic designer that can deal with basic PDF elements, natively supported by the latest official PDF standard. Although the generated PDF documents are exported as the PDF v1.3, they are fully compatible with all general PDF readers. Also, the exported PDF documents were checked by the PDF online verification tools and there are minimal warnings generated.
Using the PDF visual designer tool
This visual tool is intended to be used like any other visual designer. From the main menu, after the application initialization, please select the Insert submenu, and the Page... option, like on the image below:
You can add as many pages as You like, in Your document. The pages can be added at any moment, during the document design phase. So, see the screenshot after adding the few pages:
The tree control on the left side contains the list of all pages in Your document. By selecting each of them, the currently selected page will be renedered on the screen, on the right side. To change the page attributes, use the Edit submenu, from the main manu, and the Page properties... option, like on the image below:
The following dialog appears:
we will change the orientation of the first page from portrait to landscape. Here is the final result:
In the similar manner You can change the page size, by using the predefined page formats: A0, A1, A2, A3, A4, A5 and Letter.
Adding the page elements is similar to adding the page. From the Insert submenu, of the main menu, select the element You want to add: image, text, rectangle or line. You can add as many page elements as you like. They will appear on the right side, at the top-left position on Your currently selected page. Each page element has the four anchor handles by which it can be resized. To move the currently selected page element (it must be selected in the tree list, in the left panel) simply click anywhere inside the selected object and drag the mouse.
The page elements can be modified later by selecting the Edit submenu, from the main menu, and the corresponding edit option, for each page element type. Here are the screens, for all of them:
The PDF document also contains some additional information about the content and the author. All these informations You can set by clicking on the Edit submenu, of the main menu, and the Document properties... option. The following dialog appears:
To remove any of the selected page elements, or the selected page itself, use the Remove submenu, of the main menu, and the Remove selected object option.
When Your document is ready to be exported to the final PDF document, please use the File submenu, of the main menu, and the Save... option. Pick the location of the new PDF file on Your local or network storage and export it. Finally, You can open the exported PDF document and compare it to the document in the SmallPDFDesigner. Here is the generated PDF document from the example project in this article (from the screenshot at the begining of this article):
Using the included .NET 2.0 PDF generator SDK tool
For the purpose of this visual designer, the special SDK tool was developed. It is the .NET 2.0 compiled class library called PDFClasses.dll. It can be added as the reference in the custom project and the embedded PDF classes can be used. There are the following .NET 2.0 classes currently available:
PDFPbject - the general abstract class that is derived in all of the following classes, except in the
PDFPage - the PDF page class that defines the single PDF document page
PDFResources - the PDF resources class that keeps the page resources collection (fonts, images, etc.), as the part of the
PDFContents - the PDF contents class that keeps the page elements collection (text and graphical objects), as the part of the
PDFImage - the PDF image class that defines the PDF image element
PDFText - the PDF text class that defines the PDF text element
PDFFont - the PDF font class that defines the type of the PDF text element, as the part of the
PDFRectangle - the PDF rectangle class that defines the PDF rectangle element
PDFLine - the PDF line class that defines the PDF line element
PDFDocument - the PDF document class that defines the general PDF document
PDFInfo - the PDF info class that keeps the general PDF document information, as the part of the
PDFCatalog - the PDF document catalog class that keeps the pages collection, as the part of the
PDFOutlines - the PDF outlines class that defines the outlines of the PDF pages, as the part of the
PDFCatalog class (not implemented in this release of SDK)
PDFPages - the PDF pages class that keeps the pages collection, as the part of the
The usage of this SDK should be in the following manner:
static void Main(string args)
PDFDocument pdfDoc = new PDFDocument();
pdfDoc.Info.Author = "Test Author";
pdfDoc.Info.Creator = "Test Creator";
pdfDoc.Info.Keywords = "Test Keywords";
pdfDoc.Info.Producer = "Test Producer";
pdfDoc.Info.Subject = "Test Subject";
pdfDoc.Info.Title = "Test Title";
PDFPage pdfPage = pdfDoc.AddPage();
PDFText pdfText = pdfPage.AddText();
pdfText.Text = "Hello, World !!!";
pdfText.Position = new Point(110, 100);
PDFLine pdfLine = pdfPage.AddLine();
pdfLine.LineStart = new Point(100, 120);
pdfLine.LineEnd = new Point(200, 120);
pdfLine.LineWidth = 3;
pdfLine.StrokeColor = Color.Red;
Here is the screenshot of the SDK generated PDF document:
Each defined PDF class, from the included SDK, has many methods for setting of different parameters of the PDF document elements, so feel free to explore them in Your custom projects.
Points of Interest
This project was one of the most interesting projects so far, for me. While exploring of the Adobe PDF Specification, I had a very good time during the PDF objects class definition and implementation. There are many features left out of this visual designer and the provided SDK, just waiting to be implemented.
SmallPDFDesigner v1.0 and SDK - November, 2014.