Java如何使用PDF javascript关闭PDF? [英] Java How to close PDF from using pdf javascript?

查看:180
本文介绍了Java如何使用PDF javascript关闭PDF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用servlet将pdf流发送到浏览器.

I'm using a servlet to send a pdf stream to a browser.

当我向用户显示pdf时,要求pdf必须打开打印对话框. 我使用iText api成功做到了这一点.像这样:

There is a request that the pdf must open the print dialog when I show it to the user. I was successful doing this using iText api. Something like this:

stamper.setPageAction(PdfWriter.PAGE_OPEN, new PdfAction(PdfAction.PRINTDIALOG), 1);

现在,在打印后,我确实需要关闭pdf文件.我尝试使用pdfactions,但是我听不懂.我试过的是:

Now I do need to close the pdf file after print. I tried using pdfactions, but I'm can't get it. What I tried is:

writer.setAdditionalAction(PdfWriter.DID_PRINT, PdfAction.javaScript("app.execMenuItem('Close');", writer));

writer.setAdditionalAction(PdfWriter.DID_PRINT, PdfAction.javaScript("app.close();", writer));

我不一定需要使用pdfAction,但是在用户将pdf发送给打印机后,我看不到如何获取它.

I don't necessarily need to use pdfActions, but I don't see how to get it after user sent the pdf to printer.

你有什么主意吗?

推荐答案

app.execMenuItem('Close');app.close()不起作用是有原因的.这些方法旨在关闭Adobe Reader/Acrobat的独立版本.我想您正在浏览器中查看PDF,在这种情况下,您将使用Adobe Reader作为插件,Chrome的PDF查看器,Firefox中的pdf.js或任何其他PDF查看器.

There's a reason why app.execMenuItem('Close'); and app.close() don't work. These methods are designed to close the standalone version of Adobe Reader/Acrobat. I guess you're viewing the PDF in a browser, in which case you use Adobe Reader as a plug-in, Chrome's PDF viewer, pdf.js in Firefox, or any other PDF viewer.

问题1:您需要关闭PDF文档中的浏览器窗口. PDF无法控制您的浏览器.假设他们会:那不是一个严重的安全问题吗?

Problem #1: you need to close the browser window from a PDF document. PDFs don't have the power to control your browser. Suppose they would: wouldn't that be a serious security issue?

问题2:您将PDF嵌入HTML页面(例如,使用<object>标记)和

Problem #2: you embed the PDF inside a HTML page (e.g. using an <object> tag) and establish a communication between the JavaScript in the PDF and the JavaScript in the HTML. I've described how to do this in my book, but: it won't work with all browsers on all OSs. For instance: Chrome's PDF viewer and Firefox's pdf.js will completely ignore your commands.

您正在使用我们的iText库提出解决方案,但您正在问一些使用任何软件都无法完成的事情.

You are asking a solution using our iText library, but you're asking something that can't be done with any software.

这篇关于Java如何使用PDF javascript关闭PDF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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