Choosing a PDF Generator
If your goals include building PDF files from scratch, you'll
want to look at one of the many PDF generator products on
the market. You'll quickly find that these products span a vari-
ety of price points and capabilities. Understanding your choic-
es will help you narrow down the selection to the products
that will best fit your needs.
Generally speaking, you can choose between seven different
methods of programmatically generating PDF files:
Object Model Synthesis - This is the most common
approach. Starting with some top-level object, such as
Document or Pdf, you build up your PDF by adding objects
representing text, images, bookmarks, and the other parts of
a PDF file. Within this category, you'll find three broad
approaches to the problem of representing the structure of a
PDF file. Some products place a very thin wrapper over the
low-level structure used by Adobe for PDF itself. Others start
from the object model developed in the System.Drawing
namespace of the .NET Framework, and mimic it to produce a
set of objects and members that are more familiar to .NET
developers. Still others develop their own abstract model of
the objects that make up a document. When you're using an
object model to build PDF files, you need to decide which of
these styles you prefer. You also need to investigate the rich-
ness of the object model to determine whether it includes
objects representing all of the features that you'd like to use
in your document. For example, if you want to include a table,
do you need to draw it with lines and calculate where to place
text yourself, or is there some higher-level abstraction repre-
senting a table already baked into the object model?
Windows Forms Control- Instead of providing an abstract
class, some vendors provide an object model wrapped as a
Windows Forms control or an ActiveX control that can be
instantiated on a Windows Form. This approach tends to be
similar to the object model approach as far as building the
actual document, but precludes you from using with ASP.NET,
windowless Windows Services, and/or console applications.
Event-Driven Generation- This approach is analogous to the
method used by the System.Drawing.Printing namespace in
the .NET Framework. With this approach, you create a top-
level object and register your own event handlers for events
such as the start of printing each page. When your code is
called back in response to these events, it's up to you to sup-
ply the appropriate objects to be printed. This sort of "pull"
approach can help minimize memory requirements for large
Streaming Generation- Another approach that can result in
lower memory requirements for large documents is an API
that allows streaming a PDF directly to a FileStream or other
output object. Typically, products that implement such an API
let you open a file and then send paragraphs of text, images,
and other objects to the file without maintaining the entire
document in memory. While this way of producing a PDF can
lower the resource hit for producing large documents, it also
typically constrains you from using some features such as
cross-references within a document.
Merging Data- Some products can generate PDF files by
merging data from existing files such as text and image files.
These may be plain text files, or files containing special
markup codes that are interpreted by the batch generation
software. This approach is best suited for applications such as
batch generation of invoices or form letters.
XML Transformation- Several products implement their own
XML Document Object Model to represent the parts of a PDF.
With these products, you can directly open an XML document
that follows the correct DOM and immediately save it as PDF
with no further processing. Alternatively, you can use XSL to
transform another XML document to the expected format and
then save it as PDF. You may also be able to combine this sort
of XML-based PDF creation with object model based modifica-
tion in a hybrid approach.
XSL-FO Processing- Another way to combine PDF genera-
tion with XML standards is to use an XSL-FO formatting
engine together with the XSL-FO standard. Several of the
products in this Guide implement XSL-FO engines in .NET
code. See the section "Understanding XSL-FO" later in this
Guide for more information.
If you're generating PDF, you should consider where you'll be
storing the generated PDFs. Various products offer more or
less flexibility in their output APIs.
Disk Files- At the most basic level, any product should be
able to generate a file on disk. But you may need more flexi-
bility than that.
Stream Object- Some products let you send their output to
any Stream object (FileStream, MemoryStream, and so on).
ASP.NET Response Object- If you're working in an ASP.NET
application, you will probably want a product that can write
directly to the ASP.NET Response object. The alternative is to
output PDFs to temporary files and then point the user's Web
How-To-Select a PDF Component for .NET
Covers PDF components for use in both WinForm and WebForm/ASP.NET applications
Still have questions, want more details, need advice, or have suggestions?