打印PDF创建于iTextSharp的,然后控制返回给浏览器 [英] Print PDF Created in iTextSharp and then Return Control to Browser

查看:299
本文介绍了打印PDF创建于iTextSharp的,然后控制返回给浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是有点回归到我2012的问题 - 的是否有可能触发一个按键事件已用于加载PDF文件一个iframe,我想我可能会被误接受。回答有



目前的情况是这样的 -




  • 文件的主页上有 onkeypress事件事件连接到它,这将在用户扫描特定的条形码的PDF加载到一个对象

  • 使用iTextSharp的创建PDF,并具有开放的动作集 - writer.SetOpenAction(新PdfAction(PdfAction.PRINTDIALOG))作家 PdfWriter )。



因此,一个用户将扫描的自动加载它打开它的打印对话框的PDF文件的条形码。然后,用户将选择打印机和打印PDF。问题是当用户需要扫描他们需要的HTML正文中单击某处下一个单元(但PDF对象外)和然后的扫描条码为新的PDF加载。



我一看的这个并认为这是可能的设置某种的PDF插件和浏览器之间的通信,但可以告诉插件交出控制权交给浏览器/ JavaScript的



修改
一些额外的背景信息 -




  • 我已经使用对象和和iframe中尝试了。

  • 使用调试器,如果我键入 document.activeElement.id 给出一个元件的ID的适当元件然而(在文本输入的情况下)的任何按键不会出现。

  • 使用调试我可以使用模糊有源元件带来焦点到另一个元件连更改输入的值,但没有用户输入的是由HTML / JavaScript的用户类型/扫描。

  • 这是在Internet Explorer的兼容性模式的遗留应用程序运行。


只是为了总结 - 我要扫描的打开,将自动打印对话框的条形码,这将打开一个PDF(已完成)(已完成)用户打印的PDF,然后不与任何页面进一步人机交互(即用户不需要使用鼠标或键盘点击打印对话框中的打印按钮),用户应该能够扫描其他条码,这将打开一个新的PDF后。


解决方案

而不是渲染的iframe /对象中的PDF,为什么不利用现代HTML5和Mozilla的辛勤工作和使用的 https://github.com/mozilla/pdf.js/ - 这是一个完全的HTML5 / JavaScript的PDF渲染器,并且不需要任何插件<。 / p>

有在的 http://mozilla.github.io/pdf.js/web/viewer.html



然后,你将用JavaScript在同一页上一路下来,并可能避免通过两个环境之间对焦/事件等,所以你能赶上活动页面轻松地够上的任何地方。


This is somewhat of a return to my 2012 question - Is it possible to fire a keypress event for an iframe that has been used to load a PDF file, I think I may have been mistaken accepting the answer there.

The current situation is this -

  • The document of the main page has an onkeypress event attached to it which will load a PDF into an object when the user scans a particular barcode.
  • The PDF is created using iTextSharp and has the open action set - writer.SetOpenAction(new PdfAction(PdfAction.PRINTDIALOG)) (writer is a PdfWriter).

So a user will scan the barcode which automatically loads a PDF file which opens it's print dialog. The user will then choose the printer and print the PDF. The problem comes when the user wants to scan the next unit they need to click somewhere within the html body (but outside of the PDF object) and then scan the barcode for the new PDF to be loaded.

I had a look at this and saw that it is possible to setup some kind of communication between the PDF plugin and the browser but is is possible to tell the plugin to surrender control to the browser/javascript

EDIT Some extra background information -

  • I've tried using both objects and and iframes.
  • Using the debugger, if I type document.activeElement.id gives the ID of an element an appropriate element however (in the case of text inputs) any key presses do not appear.
  • Using the debugger I can use blur the active element bring focus to another element even change the value of an input but no user input is seen by the HTML/javascript when the user types/scans.
  • This is a legacy application runs in Internet Explorer compatibility mode.

Just to sum up - I want to scan a barcode which will open a PDF (already done) which opens it's print dialog automatically (already done) the user prints the PDF and then without any further human interaction with the page (i.e. the user does not need to use the mouse or keyboard after clicking the print button in the print dialog) the user should be able to scan another barcode which will open a new PDF.

解决方案

Rather than render the PDF inside an iframe/object, why not take advantage of modern HTML5 and Mozilla's hard work and render it using https://github.com/mozilla/pdf.js/ - it is a fully HTML5/javascript PDF renderer and does not require any plugins.

There is a nice online demo at http://mozilla.github.io/pdf.js/web/viewer.html

Then you would be on the same page with JavaScript all the way down and could avoid having to pass focus/events etc between the two environments, so you could catch events anywhere on the page easily enough.

这篇关于打印PDF创建于iTextSharp的,然后控制返回给浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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