views:

34

answers:

1

Dear friends,

I am working on an Adobe AIR (2.0) application that contains a feature to allow users to print documents (such as salary slips). Those documents are originally in PDF format. Due to circumstances we cannot directly display those PDFs in the AIR application (for example using flash.html.HTMLLoader). Therefore we convert the PDFs to SWFs (using the pdf2swf tool, see http://www.swftools.org/). The SWFs are loaded into the application using a mx.controls.SWFLoader, like so:

<mx:SWFLoader
        id="salarySlipImage"
        loaderContext="{someLoaderContext}"
        trustContent="true"
        maintainAspectRatio="true"
        scaleContent="true"
        source="{salarySlip.swf}" />

where salarySlip.swf is a ByteArray containing the SWF's content.

Next, we have a button that starts a FlexPrintJob, like so:

<mx:Button label="Print" click="print()" />

and so:

public function print():void {
    var printJob:FlexPrintJob = new FlexPrintJob();

    if (printJob.start() != true) {
        return;
    }

    printJob.addObject(salarySlipImage, FlexPrintJobScaleType.MATCH_HEIGHT);
    printJob.send();
}

This works pretty well (documents come rolling out the printer and look good), although I've noticed that the files that are being sent to the printer can sometimes become very big, like > 100MB (!!!), which can take quite some time to reach the printer, like > 30s (obviously depending on the speed of the connection to the printer). The original PDFs are around 150KB and the SWFs around 100KB.

Does anyone have similar issues when printing using the mx.printing Flex APIs? If so, how can I fix this?

Best regards,
Bob

A: 

I'm not 100% sure that this response will help you as I will not have tested any of the following, but what happens if you use the BitmapData class and run a draw(salarySlipImage). You'd have to get that object into a UIComponent so that your printJob can accept it via addObject, but it might drastically reduce file sizes (especially if you're looking at 100MB [which is what I assumed you meant instead of Mb]).

jeremy.mooer