• warning: Parameter 1 to tac_lite_node_grants() expected to be a reference, value given in /home/rbezemer/softwarebyrichard.com/includes/module.inc on line 483.
  • warning: Parameter 2 to gmap_gmap() expected to be a reference, value given in /home/rbezemer/softwarebyrichard.com/includes/module.inc on line 483.
  • warning: Parameter 1 to tac_lite_node_grants() expected to be a reference, value given in /home/rbezemer/softwarebyrichard.com/includes/module.inc on line 483.
  • warning: Parameter 1 to tac_lite_node_grants() expected to be a reference, value given in /home/rbezemer/softwarebyrichard.com/includes/module.inc on line 483.
  • warning: Parameter 1 to tac_lite_node_grants() expected to be a reference, value given in /home/rbezemer/softwarebyrichard.com/includes/module.inc on line 483.
  • warning: Parameter 1 to tac_lite_node_grants() expected to be a reference, value given in /home/rbezemer/softwarebyrichard.com/includes/module.inc on line 483.
  • warning: Parameter 1 to tac_lite_node_grants() expected to be a reference, value given in /home/rbezemer/softwarebyrichard.com/includes/module.inc on line 483.
  • warning: Parameter 1 to tac_lite_node_grants() expected to be a reference, value given in /home/rbezemer/softwarebyrichard.com/includes/module.inc on line 483.

AlivePDF

AlivePDF is a fantastic client side pdf generation library for ActionScript that I found a few months ago. It's opensource and a relatively new project but I've found it is an extremely powerful and fast library. Using the library is simple. Most of the configuration is done all from creating an instance of the PDF class :

  1.  
  2. var _pdf:PDF = new PDF(_orientation, Unit.INCHES, _page_size);
  3. _pdf.setDisplayMode( Display.FULL_PAGE, Layout.SINGLE_PAGE );
  4. _pdf.setBottomMargin(0);

Then you can write content to the pdf in a similar fashion to other drawing libraries. For example to write some text :
  1.  
  2. pdf.setFont(pdf_font_family, (pdf_font_size));
  3. pdf.textStyle(pdf_font_color, _alpha);
  4. pdf.setXY(currTL.x, currTL.y);
  5. pdf.addCell(currWH.x, currWH.y, StringUtil.trim(words), 0, 0, pdf_align);

or to output an image :
  1.  
  2. pdf.addImage(this, null, tl.x, tl.y, wh.x, wh.y, 0, this.alpha);

The powerful thing about this code above is that you can pass the addImage any DisplayObject, and the library will take care of converting the object into a image resource for you, instead of having to deal with the ImageSnapshot and PNGEncoder classes to generate the image. However the one significant drawback of doing any images with alivepdf is the fact that there is still no support for transparency in images, any images with transparent sections will show up with a large ugly black area on that section. Apparently this is on their feature list, but it's still on it's way to being implemented. Saving the pdf from a flex application is pretty easy as well
  1. _pdf.save( Method.REMOTE, "http://www.mysite.com/createpdf.php", Download.ATTACHMENT, "my.pdf" );

And this will call the above file on the server and popup a save dialog box to download the generated pdf file. The server file is pretty straightforward :
  1. <?php
  2.  
  3. $method = $_GET['method'];
  4. $name = $_GET['name'];
  5.  
  6. if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) {
  7.  
  8. // get bytearray
  9. $pdf = $GLOBALS["HTTP_RAW_POST_DATA"];
  10.  
  11. // add headers for download dialog-box
  12. header('Content-Type: application/pdf');
  13. header('Content-Length: '.strlen($pdf));
  14. header('Content-disposition:'.$method.'; filename="'.$name.'"');
  15. echo $pdf;
  16.  
  17. } else echo 'An error occured.';
  18.  
  19. ?>

Once again a great library that a lot of hard work has gone in to, definitely still a few rough spots here and there, but definitely good to use if you need basic pdf printing support in your flex / flash / air application.

Trackback URL for this post:

http://softwarebyrichard.com/trackback/115
Your rating: None Average: 2.8 (25 votes)

Comments

I realise that this is a

I realise that this is a fairly old post, but we've now added transparency support to AlivePDF.

http://www.moodshare.co/blog/2011/06/transparency-support-for-alivepdf/

Excellant that's great news.

Excellant that's great news. I have several projects that I've been waiting for transparency support to be in!