servlet/jsp 中的打印对话框
我想在 servlet/jsp 中显示打印对话框。 下面是我的代码:
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet () ;
PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
PrintService service = javax.print.ServiceUI.printDialog(null, 200, 200, printService, defaultService, flavor, pras);
if (service != null)
{
DocPrintJob job = service.createPrintJob();
Doc doc = new SimpleDoc(decodedImageData, flavor, null);
job.print(doc, null);
}
它在独立应用程序中运行良好。 但是,我无法在 servlet/jsp 中显示打印对话框。
I want to display print dialog in servlet/jsp. Below is my code:
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet () ;
PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
PrintService service = javax.print.ServiceUI.printDialog(null, 200, 200, printService, defaultService, flavor, pras);
if (service != null)
{
DocPrintJob job = service.createPrintJob();
Doc doc = new SimpleDoc(decodedImageData, flavor, null);
job.print(doc, null);
}
It works well in a standalone application. However, I am not able to display print dialog in servlet/jsp.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要注意,不是客户端在此处执行您的代码。 这是服务器。
您必须创建一个 javascript 函数才能使其工作。
You need to be aware that it is not the client that is executing your code here. It's the server.
You'll have to make a javascript function for that to work.
我会在 javascript 中调用
window.print();
。 下面试试吧。I would call
window.print();
in javascript. Try it below.