从 AIR/Flex 应用程序打印导致将大文件发送到打印机 [英] Printing from AIR/Flex application causes large files being sent to printer

查看:14
本文介绍了从 AIR/Flex 应用程序打印导致将大文件发送到打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 Adob​​e AIR (2.0) 应用程序,其中包含允许用户打印文档(例如工资单)的功能.这些文件最初是 PDF 格式.由于某些情况,我们无法在 AIR 应用程序中直接显示这些 PDF(例如使用 flash.html.HTMLLoader).因此,我们将 PDF 转换为 SWF(使用 pdf2swf 工具,请参阅 http://www.swftools.org/).SWF 使用 mx.controls.SWFLoader 加载到应用程序中,如下所示:

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}" />

其中salarySlip.swf 是一个包含SWF 内容的ByteArray.

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

接下来,我们有一个启动 FlexPrintJob 的按钮,如下所示:

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

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

等等:

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

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

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

这很有效(文档在打印机上推出并且看起来不错),尽管我注意到发送到打印机的文件有时会变得非常大,例如 > 100MB(!!!),这可能需要相当长的时间才能到达打印机,例如 > 30 秒(显然取决于与打印机的连接速度).原始 PDF 大约 150KB,SWF 大约 100KB.

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.

是否有人在使用 mx.printing Flex API 进行打印时遇到类似问题?如果是这样,我该如何解决这个问题?

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

最好的问候,
鲍勃

Best regards,
Bob

推荐答案

尝试使用这个;它大大减少了我的打印作业大小.我仍然想知道它是否可以更小..所以如果有人有更多建议,请与我们分享.printJob.printAsBitmap=false;

Try using this; It reduced my printjobs size a lot. Still i wonder if it can be even smaller.. so if anyone has more suggestions, please share it with us. printJob.printAsBitmap=false;

var printJob:FlexPrintJob = new FlexPrintJob();
printJob.printAsBitmap=false;

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

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

这篇关于从 AIR/Flex 应用程序打印导致将大文件发送到打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆