Click here to Skip to main content
14,357,666 members

SmallPDFDesigner v1.0

Rate this:
4.96 (20 votes)
Please Sign up or sign in to vote.
4.96 (20 votes)
5 Nov 2014CPOL
This article is about the simple .NET PDF generator and visual designer

Image 1

Introduction

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.

Background

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:

Image 2

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:

Image 3

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:

Image 4

The following dialog appears:

Image 5

we will change the orientation of the first page from portrait to landscape. Here is the final result:

Image 6

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:

Image 7 Image 8  Image 9 Image 10

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:

Image 11

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):

Image 12

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 PDFDocument class
  • 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 PDFPage class
  • PDFContents - the PDF contents class that keeps the page elements collection (text and graphical objects), as the part of the PDFPage class
  • 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 PDFText class
  • 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 PDFDocument class
  • PDFCatalog - the PDF document catalog class that keeps the pages collection, as the part of the PDFDocument class
  • 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 PDFCatalog class

The usage of this SDK should be in the following manner:

namespace PDF_Generator
{
    class Program
    {
        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;
            pdfDoc.SavePDF("test2.pdf");
        }
    }
}

Here is the screenshot of the SDK generated PDF document:

Image 13

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.

History

SmallPDFDesigner v1.0 and SDK - November, 2014.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

darkoman
Software Developer (Senior) Elektromehanika d.o.o. Nis
Serbia Serbia
He has a master degree in Computer Science at Faculty of Electronics in Nis (Serbia), and works as a C++/C# application developer for Windows platforms since 2001. He likes traveling, reading and meeting new people and cultures.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Prasad Khandekar7-Nov-14 4:14
professionalPrasad Khandekar7-Nov-14 4:14 
GeneralMy vote of 5 Pin
mpino6-Nov-14 4:15
membermpino6-Nov-14 4:15 
GeneralMy vote of 5 Pin
Yvan Rodrigues5-Nov-14 6:55
professionalYvan Rodrigues5-Nov-14 6:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Article
Posted 5 Nov 2014

Stats

19.4K views
1.3K downloads
36 bookmarked