![](/img/trans.png)
[英]Silently download and print PDF document from Java Applet on Windows
[英]How to silently print a pdf from a servlet output in a web application
在struts1 Web應用程序中,我們有一個itextpdf生成器,可直接將pdf寫入struts servlet輸出流。 我們使用itextepdf生成收據,因此我們需要在不向用戶顯示的情況下打印生成的pdf。 用戶應該不能下載收據,以避免兩次打印相同的收據。 做到這一點的最佳方法是什么? 服務pdf的代碼如下:
public ActionForward printReceipt(final ActionMapping mapping,
final ActionForm form, final HttpServletRequest request,
final HttpServletResponse response) throws Exception {
final OutputStream out = response.getOutputStream();
final Document doc = new Document();
final PdfWriter docWriter = PdfWriter.getInstance(doc, out);
doc.open();
final PdfContentByte cb = docWriter.getDirectContent();
cb.beginText();
// .. write all required data in the pdf
doc.close();
docWriter.close();
out.flush();
out.close();
return mapping.findForward(null);
}
您可以嘗試按照以下步驟操作:
使用以下命令從主html提供打印命令
window.frames["printf"].print();
其中printf是iframe的ID
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.