Print your dialog box to PDF with AlivePDF without PHP or such


 I use AlivePDF (http://alivepdf.bytearray.org/) and it is really good.
Btw i had some small problem :
1 ) When i try print my dialog box, it was truncated :(
2 ) I don't want use create.php for economy of bandwidth.

After fighting with many website I found the solution, it is pretty simple !
That's the source :

            protected function btnPrint_clickHandler(event:MouseEvent):void
            {
                var printPDF:PDF = new PDF( Orientation.LANDSCAPE, Unit.MM, Size.A4 );
                printPDF.setDisplayMode( Display.FULL_PAGE, Layout.SINGLE_PAGE );
                printPDF.addPage();
                var r:Resize=new Resize(Mode.FIT_TO_PAGE,Position.CENTERED);
                var image:ImageSnapshot = ImageSnapshot.captureImage(this, 0, new
                             mx.graphics.codec.JPEGEncoder(70));
                printPDF.addImageStream(image.data,ColorSpace.DEVICE_RGB,r);
                var fileReference:FileReference=new FileReference();
                var bytes:ByteArray = printPDF.save( Method.LOCAL );
                fileReference.save(bytes,"export.pdf");
            }

Some point :

  1. I don't use addImage, because that's truncate my dialog box. And if something is on your dialog box,it will be print with your dialogbox, that's not what we want !
  2. I used JPEGEncoder : PNGEncorder don't work with alivePDF, that's sad, but because the alpha, it send an error, so i use JPEG. bit sad, because it is slow...I try to put the quality less, and put 0 for DPI for means "pixel matching"..
  3. As i use addImageStream, I need use ImageSnapshot for have my diaigog box.
  4. I use Method.LOCAL for have a ByteArray, and a FileReference (new in flash 10) for save in local, without use bandwith with the famous "create.php" i saw everywhere.

A link : http://www.kalengibbons.com/blog/index.php/2009/03/custom-printing-with-flex-part-2-generating-pdfs-with-alivepdf/ who is the begin of solution I exposed here.

Aucun commentaire: