<a class="savetopdf" href="#" onclick='
<%
try {
String w = result;// "<html><body> This is my Project </body></html>";
OutputStream file = new FileOutputStream(new File("E:\\newfile.pdf"));
Document document = new Document();
PdfWriter.getInstance(document, file);
document.open();
@SuppressWarnings("deprecation")
HTMLWorker htmlWorker = new HTMLWorker(document);
htmlWorker.parse(new StringReader(w));
document.close();
file.close();
} catch (Exception e) {
e.printStackTrace();
}
%>
>Save as PDF</a>
這是我的代碼保存爲PDF當前它保存到給定的目錄但我想我點擊但保存爲PDF然後它應該下載文件,將PDF格式。如何下載文件保存爲Pdf在Jsp
閱讀本SO線程 - http://stackoverflow.com/questions/1936615/jsp-download-application-octet-stream和文章[即成文件(http://balusc.blogspot.in/ 2007/07/fileservlet.html) – adatapost