閱讀PDF我已經寫了一個jsp的servlet使用itextpdf PDF閱讀,我結束了例外,誰能告訴我異常異常原因而在JSP
page.jsp
<html>
<%@page import="java.io.File"%>
<%@page import="java.io.*"%>
<%@page import="javax.servlet.*"%>
<%@page import="com.itextpdf.text.Image"%>
<%@page import="com.itextpdf.text.Document"%>
<%@page import="com.itextpdf.text.DocumentException"%>
<%@page import="com.itextpdf.text.pdf.PdfReader"%>
<%@page import="com.itextpdf.text.pdf.PdfImportedPage"%>
<%@page import="com.itextpdf.text.pdf.PdfWriter"%>
<%@page import="com.itextpdf.text.pdf.PdfContentByte"%>
<%
response.reset();
response.setContentType("application/pdf");
response.setHeader("Content-Disposition",
"inline;filename=Saba_PhBill.pdf");
File file = new File(
"D:\\TNWRD_Documents\\Knowladge_Base\\CHAPTER_I.pdf");
String OUTPUTFILE = "D:\\TNWRD_Documents\\CHAPTER_II.pdf";
FileInputStream in = new FileInputStream(file);
PdfReader reader = new PdfReader(in);
Document document = new Document();
//PdfWriter writer = PdfWriter.getInstance(document,
// new FileOutputStream(OUTPUTFILE));
OutputStream outputStream = new FileOutputStream(OUTPUTFILE);
PdfWriter writer = PdfWriter.getInstance(document, outputStream);
document.open();
//PdfReader reader = new PdfReader(INPUTFILE);
PdfContentByte cb = writer.getDirectContent();
int n = reader.getNumberOfPages();
PdfImportedPage pages;
// Go through all pages
for (int i = 1; i <= n; i++) {
// Only page number 2 will be included
pages = writer.getImportedPage(reader, i);
Image instance = Image.getInstance(pages);
document.add(instance);
cb.addTemplate(pages, 0, 0);
document.addHeader("pdf", "pdf");
}
document.close();
%>
</html>
你能上傳你的PDF嗎? – 2013-04-25 11:41:12
現在更改了代碼,我可以讀寫pdf,但內容沒有在jsp中顯示,上面是最新代碼 – 2013-04-25 12:17:30
MichaëlDemey yes我可以上傳和下載,但需要顯示jsp中的寫作內容 – 2013-04-25 12:19:38