Login
 
Atalasoft DotImage
Released: 04/18/2010

Building a PDF Document with DotImage

There are a number of different ways that PDF documents can be created.  Documents can be created by hand in page layout programs, or they can be generated by automated reports.  Too often, it is the case that these separate applications do not work well with each other or if they do, the process is either limited or challenging.

In DotImage 9.0, Atalasoft is providing a set of .NET tools that can take collections of PDF documents, in part or in whole, and assemble them into new documents.  This allows clients to integrate PDF document production into their workflow without needing to worry about how the PDF documents are produced.  For example, a workflow may need to assemble a corporate coversheet, a legal disclaimer, and a production efficiency report into one document.  If the coversheet was produced by the art department, the disclaimer from legal, and the report from a database query, there are few good solutions, other than doing this manually with Adobe Acrobat.

Atalasoft provides a suite of tools that allows you to do this previous example in a single line of code:

PdfDocument.Combine("FinalReport.pdf", "CoverSheet.pdf";,
                                       "Disclaimer.pdf", "Report.pdf");

To use this code, you need the following using statements

using Atalasoft.PdfDoc;
using Atalasoft.Imaging.Codec.Pdf;

This line assembles the file CoverSheet.pdf, followed by Disclaimer.pdf and finally Report.pdf into the file FinalReport.pdf.  The static method, Combine, takes an output file (or Stream) and any number of input files (or Streams).  Building from this simple example, we can put in some logic to start to customize the report.  Suppose that we want to distinguish between an internal and an external document and need to add in an additional disclaimer if the process report involves chemicals.  This could be done like this:

List<string> filesToAdd = new List<string>();
filesToAdd.Add(isInternal ? "InternalCoverSheet.pdf" :  
                            "ExternalCoverSheet.pdf");
filesToAdd.Add("StandardDisclaimer.pdf");
if (isChemicalProcess)
    filesToAdd.Add("ChemicalDisclaimer.pdf");
filesToAdd.Add("Report.pdf");

PdfDocument.Combine("FinalReport.pdf", filesToAdd.ToArray());

As you would hope, most of the work is up-front, determining which files to add to the final document, instead of worrying about the mechanism of how the documents will be combined.

It is also possible to build documents from existing document subsets.  For example, suppose you wanted to insert the cover sheet from an existing document into a generated report.  You could do that with the following code:

PdfDocument oldReport = new PdfDocument("2009AnnualReport.pdf");
PdfDocument draftReport = new PdfDocument("draftReport.pdf");
draftReport.Pages.Insert(0, oldReport.Pages[0]);
draftReport.Save("2010AnnualReport.pdf");
oldReport.Close();
draftReport.Close();

This example, introduces the PdfDocument object.  This object is an abstract representation of a PdfDocument.  When constructed from a file or Stream, it will have a property called Pages that represents each page in the document.  In the code example, we create two PdfDocument objects.  The first is built from the previous annual report, the second from the current draft.  Then the first page from the previous annual report is inserted at the beginning of the draft report.

The Pages collection is extremely lightweight and can be treated like any .NET collection.  Elements in the collection can be shuffled, removed, replaced, inserted or moved from one document to another.

Using these simple methods in PdfDocument, it is possible to build a solution to deliver customizable PDF content to clients.  This can be done from desktop applications or from an Asp.Net project.

PDF is a very complicated document format.  Using the Atalasoft PDFDocument class, it is possible to merge and edit PDF files without having to understand the underlying complexities of PDF. This allows you to deliver specialized content to your customers more efficiently than ever before.

Download 30-day Trial
preload preload preload