创建“仅打印”按钮PDF文件与itext [英] Create a "print-only" PDF with itext

查看:120
本文介绍了创建“仅打印”按钮PDF文件与itext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题与我最近发布的另一个问题有关:使用Java / JSP检查打印

This question is related to another one I've posted recently: Check printing with Java/JSP

我们正在寻找替代目前我们如何通过applet在Java Web应用程序中打印支票的方法。似乎共识是使用PDF进行打印,并且itext提供了使用Java执行此操作的能力。

We're looking for alternatives to how we currently print checks in a Java web application via an applet. It seems the consensus is to use PDF for printing and that itext offers the ability to do so with Java.

然而,在我们的特定情况下,检查是仅打印非常重要 - 用户不应该在应用程序中具有任何能力保存支票(我知道一个精明的用户可以做一个PrintScreen,但我们想要覆盖我们的后备,并在应用程序中没有保存检查的原生功能)。

However, it's important in our particular case that the checks are "print-only" - the user should not have any ability in the application to save the check (I know a savvy user could do a PrintScreen but we want to cover our rears and make no native functionality in the app to save checks).

I没有成功浏览网页,以确定是否可以用这种方式用itext创建PDF。我看过有关限制PDF权限的帖子,但我真正想要的是禁用使用itext在本地保存PDF的方法。

I haven't been successful in browsing the web to find out if it's possible to create a PDF with itext in this manner. I have seen posts on restricting permissions in a PDF but what I'm really looking for is a way to disable the ability to save a PDF locally using itext.

这个功能是否存在?如果是这样,你能指点我的文档/代码示例吗?

Does this functionality exist? If so, could you point me to documentation/code samples on it?

推荐答案

我假设你'重新提供此PDF并希望在没有安装任何普通客户端插件的Web应用程序/网站中打印它。

如果使用常规方法(例如Adobe Reader)打印PDF,则可以将PDF 必须下载到浏览器的缓存中以进行打开和打印。没有办法解决这个问题。

If printing the PDF using conventional means (e.g. Adobe Reader), the PDF MUST be downloaded to the browser's cache to be opened and printed. There is no way around that.

现在你可以通过以下技术阻止普通的Joe在本地保存PDF,但任何精明的用户都可以检查你的HTML的来源和直接下载PDF。

Now you can probably prevent the average Joe from saving the PDF locally via the following technique, but any savvy user will be able to inspect your HTML's source and download the PDF directly.


  1. 在iText中输出PDF,这样当打开PDF时,打印操作自动发生

  2. 在您加载此PDF的HTML页面上放置一个不可见的IFRAME,但在浏览器中看不到您的用户

  1. Output your PDF in iText such that when the PDF is opened, a print action automatically occurs
  2. Put an invisible IFRAME on your HTML page which loads this PDF, but is not visible in the browser to your user

当用户加载时在您的HTML页面中,PDF将被加载到IFRAME中并发送给用户打印机(假设在浏览器中安装了Adobe Reader)。是的,PDF将最终出现在浏览器缓存中,但是用户必须足够聪明才能识别出来然后在浏览器的缓存中搜索它。

When the user loads your HTML page, the PDF will be loaded in the IFRAME and sent to the users printer (presuming that Adobe Reader is installed in the browser). Yes, the PDF will end up in the browser cache, but the user would have to be savvy enough to both recognize this and then hunt it down in their browser's cache.

如果这是不可接受的,您将不得不考虑将PDF转换为另一种文件类型(例如,页面呈现为浏览器中显示的图像,或者可能是将文档中的每个页面发送到打印机的Flash / Java对象直接)

If this is not acceptable, you're going to have to look at converting the PDF to another file type (e.g. pages are rendered to images displayed in the browser or perhaps a Flash / Java object that sends each page in the document to the printer directly)

这篇关于创建“仅打印”按钮PDF文件与itext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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