我可以在 Adob​​e Air 中打印 HTMLLoader (pdf) 吗? [英] Can I print an HTMLLoader (pdf) in Adobe Air?

查看:23
本文介绍了我可以在 Adob​​e Air 中打印 HTMLLoader (pdf) 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 AlivePDF 创建 PDF 文件,然后将其保存到桌面.然后我可以使用 HTMLLoader 来显示我可爱的 ​​PDF 文件.

现在,Adobe Reader 中的打印按钮工作正常.但是,会有年幼的孩子使用该应用程序,所以我想在它的正上方有一个大的打印"按钮.

我想我可以开始打印作业并将其提供给我的 HTMLLoader.这将不起作用,因为 HTML 加载程序会光栅化内容.

有什么建议吗?

解决方案

为了解决这个问题,我找到的一个答案叫做
(来源:cetola.net)

点击那个紫色的大打印按钮与点击 PDF 工具栏中的打印图标是一样的.对我而言,不同之处在于我的用户(可能是小学生或中学生)不必四处寻找愚蠢的按钮.

所以,它绕着街区走了很长一段路.不过,如果您需要打印并且不能依赖那个 adobe 工具栏按钮,这就是您的答案:).

I'm using AlivePDF to create a PDF file, then save it to the desktop. I can then use an HTMLLoader to display my lovely PDF file.

Now, the print button in Adobe Reader works fine. However, there will be young children using the app, so I'd like to have a big "Print" button right above it.

I figured I could just start up a print job and feed it my HTMLLoader. This won't work because the HTML loader rasterizes the content.

Any suggestions?

解决方案

One answer I have found in order to solve this problem is called Cross-scripting PDF content. The idea is that a PDF can have embedded JavaScript, which can be called from the JavaScript within the HTML page "housing" said PDF (object tag only, no embed).

This site was of particular help. I had to simplify the JavaScript from that page down quite a bit. I kept getting syntax errors.

I also need my program to generate the PDF and the HTML content. I cannot ship a single PDF with embedded JS and an HTML file pointing to it. They need to be dynamically generated by the user. Here is a basic rundown:

private function printText(text:String):void
{
 var p:PDF=new PDF(Orientation.PORTRAIT, Unit.MM, Size.LETTER);
 p.addPage();
 p.addText(text, 100, 100);
 p.addJavaScript(this.getJavascript());
 var f:FileStream=new FileStream();

 var html:File=File.desktopDirectory.resolvePath("exported.html");
 f.open(html, FileMode.WRITE);
 f.writeUTF(this.getHtml());
 f.close();

 var file:File=File.desktopDirectory.resolvePath("exported.pdf");
 f.open(file, FileMode.WRITE);
 var bytes:ByteArray=p.save(Method.LOCAL);
 f.writeBytes(bytes);
 f.close();

Now that we have our two files, HTML and PDF, we can view the PDF, and create a giant purple print button for our younger / sight-impared users.

 if (HTMLLoader.pdfCapability == HTMLPDFCapability.STATUS_OK)
 {
  var win:PrintTitleWindow;  //the window w/giant button
  var htmlLoader:HTMLLoader=new HTMLLoader();
  var url:URLRequest=new URLRequest(html.url);
  htmlLoader.width=880;
  htmlLoader.height=(appHeight - 150);  //i figure out the height elsewhere
  htmlLoader.load(url);
  var holder:UIComponent=new UIComponent();
  holder.addChild(htmlLoader);
  win=PrintTitleWindow(PopUpManager.createPopUp(mainWindow, PrintTitleWindow, true));
  win.width=900;
  win.height=(appHeight - 50);
  win.addChild(holder);
  win.addContent(htmlLoader);
  PopUpManager.centerPopUp(win);
 }
}

Here is the JS and HTML I used. I'm adding these in here for laughs. I'm sure there is a better way to do this, but I'm tired and it is late.

private function getJavascript():String
{
 return 'function myOnMessage(aMessage) { print({ bUI: true, bSilent: false, bShrinkToFit: true }); } function myOnDisclose(cURL,cDocumentURL) { return true; } function myOnError(error, aMessage) { app.alert(error); } var msgHandlerObject = new Object(); msgHandlerObject.onMessage = myOnMessage; msgHandlerObject.onError = myOnError; msgHandlerObject.onDisclose = myOnDisclose; this.hostContainer.messageHandler = msgHandlerObject;';
}

private function getHtml():String
{
return '<html><head><script>function callPdfFunctionFromJavascript(arg) { pdfObject = document.getElementById("PDFObj");pdfObject.postMessage([arg]);}</script></head><body><object id="PDFObj" data="exported.pdf" type="application/pdf" width="100%" height="100%"></object></body></html>';
}

The PrintTitleWindow is a simple title window with the print button on it. The code to print is simple.

myHtmlLoader.window.callPdfFunctionFromJavascript('Print');

Eh Voila! I have a gigantor-print-button like so:


(source: cetola.net)

Hitting that big purple print button is the same as hitting the print icon in the PDF toolbar. The difference for me is that my users, who could be elementary or middle-school kids, won't have to look around for the stupid button.

So, it's a long way around the block. Still, if you need to print and can't rely on that adobe toolbar button, here's your answer :) .

这篇关于我可以在 Adob​​e Air 中打印 HTMLLoader (pdf) 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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