Question

Is it possible to generate PDF Documents in an Adobe AIR application without resorting to a round trip web service for generating the PDF? I've looked at the initial Flex Reports on GoogleCode but it requires a round trip for generating the actual PDF.

Given that AIR is supposed to be the Desktop end for RIAs is there a way to accomplish this? I suspect I am overlooking something but my searches through the documentation don't reveal too much and given the target for AIR I can't believe that it's just something they didn't include.

Was it helpful?

Solution

There's AlivePDF, which is a PDF generation library for ActionScript that should work, it was made just for the situation you describe.

OTHER TIPS

Just added a Adobe Air + Javascript + AlivePDF demo:

This demo doesn't require flex and is pretty straight forward.

http://www.drybydesign.com/2010/02/26/adobe-air-alivepdf-without-flex/

One of the other teams where I work is working on a Flex-based drawing application and they were totally surprised that AIR / Flex does not have PDF authoring built-in. They ended up rolling their own simple PDF creator based on the PDF specification.

Yes it is very easy to create PDF using AlivePDF, here is the sample code, first method create a pdf and second method save the pdf on disk and return the path, feel free to ask any question.

public function createFlexPdf() : String
{
    pdf = new PDF();
    pdf.setDisplayMode (Display.FULL_WIDTH,Layout.ONE_COLUMN,Mode.FIT_TO_PAGE,0.96);
    pdf.setViewerPreferences(ToolBar.SHOW,MenuBar.HIDE,WindowUI.SHOW,FitWindow.RESIZED,CenterWindow.CENTERED);
    pdf.addPage();
    var myFontStyle:IFont = new CoreFont ( FontFamily.COURIER );
    pdf.setFont(myFontStyle,10);
        pdf.addText('Kamran Aslam',10,20);//String, X-Coord, Y-Coord 
    return savePDF();
}
private function savePDF():String
{
    var fileStream:FileStream = new FileStream();
    var file:File = File.createTempDirectory();
    file = file.resolvePath("temp.pdf");
    fileStream.open(file, FileMode.WRITE);
    var bytes:ByteArray = pdf.save(Method.LOCAL);
    fileStream.writeBytes(bytes);
    fileStream.close();
    return file.url;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top