为了解决这个问题,我找到了一个答案
Cross-scripting PDF content
.其想法是,一个pdf可以有嵌入的javascript,可以从html页面中的javascript调用“housing”说pdf(仅对象标签,不嵌入)。
这个
site
特别有用。我不得不把这个页面上的javascript简化了很多。我一直有语法错误。
我还需要我的程序来生成PDF和HTML内容。我不能发送带有嵌入式JS和指向它的HTML文件的单个PDF。它们需要由用户动态生成。下面是一个基本的概要:
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,我们可以
看法
并创建一个
巨大的紫色打印按钮
对于年轻/视力受损的用户。
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。我在这里加这些是为了取笑。我相信有更好的方法可以做到这一点,但我累了,已经很晚了。
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 '
';}
PrintTitleWindow是一个简单的标题窗口,上面有打印按钮。要打印的代码很简单。
myHtmlLoader.window.callPdfFunctionFromJavascript('Print');
埃维奥伊拉
!我有一个巨大的打印按钮,就像这样:
点击那个大的紫色打印按钮和点击PDF工具栏中的打印图标是一样的。对我来说不同的是,我的用户,可能是小学或中学的孩子,不必四处寻找愚蠢的按钮。
所以,绕着街区走很长一段路。不过,如果您需要打印,并且不能依赖Adobe工具栏按钮,那么下面是您的答案:)。