如何显示为iText生成的PDF另存为对话框? [英] How to show a Save As dialog for a iText generated PDF?

查看:252
本文介绍了如何显示为iText生成的PDF另存为对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我发送由iText在servlet中生成的PDF文件时,我想显示一个<另存为对话框。我如何才能实现这一点?

解决方案

我在此页面上找到:
http://www.geek-tutorials .com / java / itext / servlet_jsp_output_pdf.php



该方法是直接用getOutputStream()(而不是文件路径)写入,并发送内容类型标题!

  response.setContentType(application / pdf); 
Document document = new Document();
try {
PdfWriter.getInstance(document,
response.getOutputStream());
// pdf生成代码

这么简单...


I want to show a Save As dialog when I send the PDF file which is generated by iText in a servlet. How can I achieve this?

解决方案

Ok I solved my problem!! I found on this page : http://www.geek-tutorials.com/java/itext/servlet_jsp_output_pdf.php

The method is to write directly with getOutputStream() (not in file path) and send content type header!

response.setContentType("application/pdf");
Document document = new Document();
try{
    PdfWriter.getInstance(document, 
    response.getOutputStream());
    //pdf generate code

It was so simple...

这篇关于如何显示为iText生成的PDF另存为对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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