我能打印在Adobe AIR的HTMLLoader(PDF)? [英] Can I print an HTMLLoader (pdf) in Adobe Air?

查看:375
本文介绍了我能打印在Adobe AIR的HTMLLoader(PDF)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 AlivePDF ,以创建一个PDF文件,然后将其保存到桌面。然后我可以使用的HTMLLoader显示我的可爱的PDF文件。

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.

现在,Adobe Reader中的打印按钮正常工作。然而,将使用该应用程序年幼的孩子,所以我想有一个大的打印按钮正上方。

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.

我想我可以只启动一个打印作业,并给它我的HTMLLoader中。这是行不通的,因为HTML装载机光栅化的内容。

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.

有什么建议?

推荐答案

一个答案,我发现,为了解决这个问题被称为的跨脚本访问PDF内容。这个想法是,一​​个PDF可以嵌入的JavaScript,可以从JavaScript的HTML页面住房中调用表示PDF(对象标记而已,没有嵌入)。

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).

网站是特别的帮助。我不得不从该页面简化的JavaScript下降不少。我一直得到语法错误。

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

我还需要我的程序来生成PDF和HTML内容。我不能随嵌入JS和HTML文件指向一个单一的PDF文件。它们需要被动态地由用户生成。这是一个基本的破败:

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();

现在,我们有我们的两个文件,​​HTML和PDF,我们可以查看的PDF,并创建一个巨大的紫色打印按钮作为我们年轻的/观光impared用户

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);
 }
}

下面是我用JS和HTML。我在这里将这些为笑。我敢肯定有一个更好的方式来做到这一点,但我累了,就晚了。

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>';
}

该PrintTitleWindow是与它的打印按钮,一个简单的标题窗口。在code打印很简单。

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

myHtmlLoader.window.callPdfFunctionFromJavascript('Print');

呃瞧的!我有一个gigantor打印按钮,如下所示:

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

击中了大大的紫色打印按钮是一样的打在PDF工具栏上的打印图标。所不同的对我来说是我的用户,谁可能是小学或初中的孩子,就不必到处寻找愚蠢的按钮。

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.

所以,这是各地块很长的路要走。不过,如果你需要打印并不能依靠了Adobe的工具栏按钮,这里是你的答案:)。

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 :) .

这篇关于我能打印在Adobe AIR的HTMLLoader(PDF)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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