Skip navigation
Currently Being Moderated

Can Flex print to PDF

Jul 21, 2009 8:52 AM

Does Flex have the ability to print to a PDF instead of just printing to a printer installed on a user's machine?  I want to print a datagrid.  I can do so but must select an installed printer.  I would prefer Flex print directly to a PDF instead of relying upon a local printer.  Can this be done?

 

Thanks!

 
Replies
  • Currently Being Moderated
    Jul 21, 2009 9:28 AM   in reply to lee704

    Yes it can be done - you have some options but you need a server on the backend... unless user just used a PDF Print Driver...

     

    Check out:

    http://alivepdf.org/

    http://flexblog.faratasystems.com/?p=237

    http://www.kalengibbons.com/blog/index.php/tag/custom-printing-with-fl ex/

     

    LCDS also had good server side PDF Generation with more exact text format and image location.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 22, 2009 7:06 AM   in reply to lee704

    From my use, we have always used LiveCycle to do our PDF generation.  Anthony is correct about their information though, but you certainly can't require someone to install a "print to pdf" driver on their machine.  Another thing you could do is create a a Flex page that is laid out much like a pdf (look and feel), and just populate text boxes within that page and they can do a file->save as... on the page.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 25, 2010 9:36 PM   in reply to lee704

    you might want to check out my little prototype which goes from flex tlf to print read

    y pdfs. http://hybridmindset.com/blog/How-I-Got-WYSIWYG-TLF-Text-To-PDF-from-F lex-Part-1

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 10, 2010 7:52 AM   in reply to hybridmindset

    hybrid, that demo is incredible!  Now the question I have is can this be reproduced for non-text components, specifically- charts?

     

    You say on your blog:

     

    "This method renders the text in the pdf as vector text, so when printing you get the exact representation of the text keeping perfect print fidelity. The XSL-FO language facilitates inline graphic images"

     

    But are those graphic images also vector based?  I can get images into a pdf, but they are not vector based so they scale horribly and this defeats the whole purpose for me of having them in a pdf format.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 10, 2010 8:01 AM   in reply to Cr99

    You can have your bitmaps filtered with bilinear filtering in PDF just as you can in Flex so that they look good when stretched.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 10, 2010 8:13 AM   in reply to Karl_Sigiscar_1971

    Hmm, that's the first I've heard about this algorithm.  How do you enable it?  I am just sending a byte array now to the server and creating the png file there:

     

    // flex code for image generation

    ImageSnapshot.defaultEncoder = PNGEncoder;

     

    private function sendAllImages():void {

        var imgArray:ArrayCollection = new ArrayCollection();

        for (var i:int=0; i<vFrameList.length; i++) {

              var vFrame:VBox = vFrameList.getItemAt(i) as VBox;

              var cp:ChartPanel = getChartPanelFromBox(vFrame);

              if (cp != null) {

                  var imageSnap:ImageSnapshot = ImageSnapshot.captureImage(cp);

                   var imageByteArray:ByteArray = imageSnap.data as ByteArray;

                  imgArray.addItem(imageByteArray);

             }

        }  

        reportRetrieval.saveAllImages(report, imgArray);        

        }

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 10, 2010 8:19 AM   in reply to Cr99

    If you use a PDF template created with LiveCycle Designer, you have created an ImageField property to display your image dynamically. Just make sure the sizing property is set to Scale Image Proportionally. By default, the image will be filtered.

     

    PS: If you want an example of what this algorithm give in Flex (with the smoothing property of a Bitmap set to true), check this comparison sample:

    http://sigiscarinc.com/

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 10, 2010 8:28 AM   in reply to Cr99

    Thanks, well I haven't tried printing flex components to pdf but I know you could use the method I layed out in my post for charts and graphs of data. As long as the charts and graphs are svg objects. And as for images, I was referring to svg vector images. So the only way you will get scaling of images and keep their quality is to use a vector based image. I hope to post the Part II that I am working on, up on my blog pretty soon which will show the demo of svg images, bitmaps, and text rendered to pdf with exact replication!

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 10, 2010 8:46 AM   in reply to hybridmindset

    @hybrid:  I'll be interested to see what you come up with.  Charts are DisplayObjects and I'm not sure how to get them into SVG format.  I know flex draws them using vectors while in the app and I just wish there was a way to go straight from that vector based rendering to PDF.

     

    @karl:  The smoothing example looks decent enough.  It's just too bad there is not a way to preserve the kind of crispness you get with vector based images.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 10, 2010 9:56 AM   in reply to Cr99

    here is a link to an tutorial on creatng svg charts with data in an xml file. You can just export the data from your flex charts and form an xml file and process it on the server side using xslt files. http://fgeorges.blogspot.com/2008/04/simple-svg-chart-generation-with- xslt.html

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points