Custom Page Elements

Custom Page Elements are used to output PDF code to a page or can utilize other already existing page element objects.

PageElement API

All page elements must inherit from the PageElement base class and override its Draw method. This method accepts a PageWriter object. When the Page Element is added to the page this method is called. PDF operators can then be added to the page using the methods of the PageWriter object. You will need to use the SetXXXX (i.e. SetLeading, SetColor, SetGraphicsMode, etc.) methods to set the state on page. You can then use the Write_XX (i.e. Write_l_, Write_m_, Write_re) methods to add the PDF graphic or text operators to the page. Most of the PDF operators have a Write_XXXX method associated with them. If the operator only differs by case, the lower case operator has a trailing "_" character. This is done to comply with the Common Language Specification (CLS).

A RotatingPageElement base class is also included. You can inherit from this to automatically provide support for rotating your page element.

When working with page elements, you do not have to be concerned with compression, encryption or PDF object numbering. This is all handled internally by DynamicPDF Core Suite for .NET.

Custom PageElement Guidelines

  1. Always use the SetXXXX method to set graphics and text states. This allows the minimum amount of PDF code to be output to the page and allows the next page element that is called to properly set the state that it needs. If you are not going to use these methods you will need to use the q and Q operators to store the current state and then restore it before leaving the Draw method.
  2. Always use a top margin to bottom margin and left margin to right margin coordinate system for the properties of your page element. Remember that PDF uses a bottom edge to top edge and left edge to right edge coordinate system that is complex and confusing to most users. This complexity should be hidden from the user of your page element. The GetPDFX, GetPDFY methods are provided on the PageWriter Dimensions property to help with this translation.
  3. Use the X, Y, Width, and Height properties where applicable.
  4. Use the built-in Color, LineStyle, and Font objects wherever possible. This makes your Page Element function in the same fashion as the built-in page elements and makes it easier for users to use them.

Development Tips

When developing custom page elements, set the document's compression level to zero and don't use security or encryption. Create a simple application that adds one page to the PDF document and adds your custom page element to that page. This makes it possible for you to output the PDF document to a file and view the PDF output from your page element in a text editor.

PDF Resources

An excellent resource for PDF development is "PDF Reference" published by Adobe. This can be downloaded free of charge from the Adobe site. This resource includes documentation of all of the PDF graphic and text operators.

In this topic