Atalasoft
Welcome to Atalasoft Community Sign in | Join | Help
in

Atalasoft Staff Blog

This is where Atalasoft Staff members will post on topics such as new KB articles, Demos, sample code, or just Atalasoft Information.

Extensibility with DotImage

In this entry I will describe some recent changes that were made to our PDF Demo.  The new code is available in the latest version of DotImage.

I recently came across the question of how to save a PDF image using Jpeg2000 or Jbig2 compression.  This is a simple task to accomplish with our PDF encoder, but perhaps not all that obvious.  Instead of just quickly answering the question and moving on, I decided to add this ability to the PDF demo program thats installed with DotImage.  This demo doesn't contain a whole lot of features so this would be a nice addition. 

Here is a little information about how our PDF encoder works.  To save a single image, you can simply pass the encoder one of our AtalaImage objects, but for multiple pages we have two options.  The first option is to pass it an ImageCollection object, which is *surprise* a collection of AtalaImage objects.  Using this method doesn't allow for any control over pdf specific options, such as compression type, this is what the second method is for.  This method is to pass a PdfImageCollection object (a collection of PdfImage objects) to the encoder.  The great thing about this is that each PdfImage has a property called Compression, which can be set to a different compression type for each page in the pdf.  The downside to this method is that it requires some extra knowledge about the PDF encoder to select different compressions, which I didn't want because I would like to keep the demo simple.

So now the question comes up, how to add the feature.  I didn't want to alter the existing demo code too much, and I wanted to make this feature easy to understand and use.  Intuitively, the process of compressing the image data is in the encoder class, but our encoder (class 'PdfEncoder') doesn't have the ability to set the type of compression.  The compression type is a property of each page (class 'PdfImage') individually.  I had this idea in my head that I did not  want the demo code to change the way it uses the PdfEncoder, but I wanted to be able to save Pdf files using Jpeg2000 or Jbig2 compression.

One great thing about the demo is that we have a property window that allows the user to select options for the encoder.  So, the solution I thought of was to use the existing properties window to choose the compression type.  The way I went about this is quite simple, just extend the existing PdfEncoder class.  I created two new properties to select Jpeg2000 or Jbig2 compression type, and added the appropriate code to do so.  Since our property window uses reflection to load all the properties, my additions are automatically added.  This is a great solution because all I did was add a new class to the project, and change the one line of code where the encoder is created.  I am really happy with this result because I don't have to change the demo code at all, and the UI remains in the exact same format.

Published Wednesday, March 01, 2006 2:31 PM by Sean Mckenna

Comments

No Comments
Anonymous comments are disabled