One of the most exciting features to be added to 3.3 and one that we think a lot of you are going to be able to use immediately is the support for native PDF. As most of you are aware the current PDF mechanism basically grabs screen shots of the grid and adds to the page. This works great and most scenarios but the biggest drawback of this mechanism is the quality of the PDF. This is because a screenshot is at the end of the day a bitmap image. It is not a vector and it doesn't scale.

In this release we're basically changing how the AlivePDFPrinter works. Conceptually if you think about our print mechanism what we do is we basically just render the grid to either the printer or the PDF. The grid already takes care of the complex mechanism of figuring out the page size, identifying which rows belong to which page how much data can be fit within a single page and all of that good stuff. So far all we did is let the grid take care of the rendering mechanism and then capture the screen shot of the grid. In this release what we're doing is extending the printer to instead of capturing the screenshot of the grid we basically take the rendering information from the grid and then use that to render native PDF objects.

From design standpoint our PDF pages basically include a report header, page header, the grid area, the page footer and the report footer.  The report header and a report footer are on the first page and the last page respectively. The page header and page footers exists on all pages.  Report headers footers and page headers footers are always a fixed size. You define the sizes when you define these renderers.  Once the sizes for these fixed areas is allocated the grid then takes up the remaining size and on basis of the size of the grid on each page we have to identify which cells in which rows exist on each page. We do all of these calculations up front and then use that information to build the preview. What we can do now with this release is use the same information to render out natural PDF using the API provided by the PDF library which is our case, Alive PDF.

Now that you understand technically what the change means let's talk about what it means to you from a code change perspective. the most obvious change to  enable this behavior is to basically said a flag on the PDF options object.

/**

        * Flag added in 3.3 to enable passing an image to the pdf printer as opposed to the

        * actual display object. Defaults to true, because currently we just add a snapshot of the

        * current view to the PDF page. If this flag is set to false, we will pass the actual display object

    * (and not the image snapshot) to the pdf printer. The pdf printer then has to be smart enough to

        * parse through the Display Object, and call the appropriate APIs on the pdf library to convert

        * the Display Object to PDF version of it.

        * */   

        public var pdfUseScreenShot:Boolean=true;



And then set this flag to false:

protected function vbox1_creationCompleteHandler(event:FlexEvent):void

              {

                    grid.pdfOptions.pdfUseScreenShot = false;

                   

              }

When you set this flag to false what it tells the grid  is that instead of capturing the screenshot of the grid what we want is to capture the information from the page itself.  All of this work is done in the printer.


The next thing you have to do is to use the updated version of the printer you can download this here:

 

The final caveat to keep in mind is that there are two modes for the printer - there's a wrap mode and the no wrap mode.  On the screen if the text with the the cell is larger than the area of the cell in other words if there's not enough space to render the entire content of the cell we usually just cut off the part of the cell text that cannot fit within the area. We can replicate that same behavior in the printer or we can try to fit as much as possible by wrapping the text.  The advantage of not wrapping is that the PDF looks cleaner but the disadvantage is that the information is cut off.  On the other hand if you set the wrap mode to true we'll be able to fit more information but it looks a little cramped. Below are sample outputs - Before, After with wrap, and After No Wrap.

You can flip the wrap setting using the following line of code in AlivePDFPrinter:

           private var pdfWrapText:Boolean=false;

 

To Summarize:

  1. This release includes pure native pdf exports as opposed to the older screenshot based pdf

  2. Now PDF’s can be scaled, they are no longer bitmap images

  3. You can select and copy text from generated PDF files

  4. PDFPrinter supports wrap and no wrap modes (example outputs follow)

  5. To use, set the flag on pdfOptions, and use the new AlivePDF Printer

  6. If you have customized report/page header/footer, modify the AlivePDFPrinter to account for that.

  7. Help us improve this feature by providing feedback!


 

 

 

Enjoy!

Before / After documents : 

Older Screenshot based PDF.pdf (108.29 kb) (Flexicious 3.2 or earlier)

Pure Native PDF With Wrap.pdf (498.74 kb) (Flexicious 3.3)

Pure Native PDF No Wrap.pdf (491.82 kb) (Flexicious 3.3)

Alive PDF Printer Class : AlivePdfPrinter.as (18.18 kb)

Sample Project: OnePager.zip (172.25 kb)