Java 需要使用itext pdf在客户端计算机中下载pdf文件
我正在使用itext pdf生成我的pdf,它正确地保存在服务器中,但应该在客户端下载(保存)。我调用该方法从jsp页面生成pdf。 这是我的密码:Java 需要使用itext pdf在客户端计算机中下载pdf文件,java,jsp,pdf,itext,Java,Jsp,Pdf,Itext,我正在使用itext pdf生成我的pdf,它正确地保存在服务器中,但应该在客户端下载(保存)。我调用该方法从jsp页面生成pdf。 这是我的密码: calling: Document b = new JavaPdfHelloWorld().Generate_pdf(con.getCon(), file_no, pdt); definition: public class JavaPdfHelloWorld { public Document G
calling:
Document b = new JavaPdfHelloWorld().Generate_pdf(con.getCon(), file_no, pdt);
definition:
public class JavaPdfHelloWorld {
public Document Generate_pdf(Connection con, String file_no, PensionDataDao pdt) throws IOException, IOException {
Document document = new Document();
String home = System.getProperty("user.home");
System.out.println(home);
File file = new File(home + "/Downloads/dcrg-diff/" + name_of_pensioner + " " + space + " "
+ updated_file_no + ".pdf");
FileOutputStream pdfFileout = new FileOutputStream(file);
PdfWriter.getInstance(document, pdfFileout);
document.open();
document.add(new Paragraph("CALCULATION SHEET AS PER GRATUITY ACT 1972",
FontFactory.getFont(FontFactory.COURIER_BOLD, 18, Font.BOLD, BaseColor.RED)));
document.close();
writer.close();
return document;
您需要将文件输出流写入响应对象,而不仅仅是返回文档。除此之外,您还需要将响应的内容类型设置为“application/pdf”,然后不向服务器写入,而是设置响应的输出流。@M.Deinum请给出一些示例。。。怎么做?我需要使用servlet吗?实际上我是新来的。所以请告诉我怎么做。当我调用一个从jsp页面生成pdf的方法时。