導航:首頁 > 文檔加密 > java處理pdf

java處理pdf

發布時間:2025-01-26 03:57:52

1. java處理pdf文件

FileInputStream 讀取文件流就OK 至於在頁面顯示

1、客戶機上要有PDF2、URL url =new URL("file:///"+ 你的文件路徑);response.setContentType(url.openConnection().getContentType());response.setHeader("Content-Disposition", "inline; filename="+ 文件名);或在jsp頁面中加入 <% response.setHeader("Content-disposition", "attachment; filename=*.pdf"); %> 以上會提示下載、保存 <% response.setHeader("Content-disposition", "filename=*.pdf"); %> 不要attachment; 就會直接打開,顯示pdf了

2. java解析pdf文件,求大神提供代碼,請注意是java語言的

給你提供一個參考例子,你可以在這個例子上試試,修改修改。也是解析PDF的。

importjava.io.File;
importjava.io.FileOutputStream;
importjava.io.OutputStreamWriter;
importjava.io.Writer;
importjava.net.MalformedURLException;
importjava.net.URL;
importorg.apache.pdfbox.pdmodel.PDDocument;
importorg.apache.pdfbox.util.PDFTextStripper;
publicclassPdfReader{
publicvoidreadFdf(Stringfile)throwsException{
//是否排序
booleansort=false;
//pdf文件名
StringpdfFile=file;
//輸入文本文件名稱
StringtextFile=null;
//編碼方式
Stringencoding="UTF-8";
//開始提取頁數
intstartPage=1;
//結束提取頁數
intendPage=Integer.MAX_VALUE;
//文件輸入流,生成文本文件
Writeroutput=null;
//內存中存儲的PDFDocument
PDDocumentdocument=null;
try{
try{
//首先當作一個URL來裝載文件,如果得到異常再從本地文件系統//去裝載文件
URLurl=newURL(pdfFile);
//注意參數已不是以前版本中的URL.而是File。
document=PDDocument.load(pdfFile);
//獲取PDF的文件名
StringfileName=url.getFile();
//以原來PDF的名稱來命名新產生的txt文件
if(fileName.length()>4){
FileoutputFile=newFile(fileName.substring(0,fileName
.length()-4)
+".txt");
textFile=outputFile.getName();
}
}catch(MalformedURLExceptione){
//如果作為URL裝載得到異常則從文件系統裝載
//注意參數已不是以前版本中的URL.而是File。
document=PDDocument.load(pdfFile);
if(pdfFile.length()>4){
textFile=pdfFile.substring(0,pdfFile.length()-4)
+".txt";
}
}
//文件輸入流,寫入文件倒textFile
output=newOutputStreamWriter(newFileOutputStream(textFile),
encoding);
//PDFTextStripper來提取文本
PDFTextStripperstripper=null;
stripper=newPDFTextStripper();
//設置是否排序
stripper.setSortByPosition(sort);
//設置起始頁
stripper.setStartPage(startPage);
//設置結束頁
stripper.setEndPage(endPage);
//調用PDFTextStripper的writeText提取並輸出文本
stripper.writeText(document,output);
}finally{
if(output!=null){
//關閉輸出流
output.close();
}
if(document!=null){
//關閉PDFDocument
document.close();
}
}
}
/**
*@paramargs
*/
publicstaticvoidmain(String[]args){
//TODOAuto-generatedmethodstub
PdfReaderpdfReader=newPdfReader();
try{
//取得E盤下的SpringGuide.pdf的內容
pdfReader.readFdf("d:\b.pdf");
}catch(Exceptione){
e.printStackTrace();
}
}
}
閱讀全文

與java處理pdf相關的資料

熱點內容
python判斷ip網段 瀏覽:362
穿越火線更新怎麼開新伺服器 瀏覽:315
腹部超聲pdf 瀏覽:920
解壓縮全能王能解壓7z文件嗎 瀏覽:248
python目錄比較 瀏覽:645
公司程序員戴假發 瀏覽:345
oracle查看資料庫狀態命令 瀏覽:840
查汽車app叫什麼 瀏覽:747
經濟學英文pdf下載 瀏覽:798
python列表順序 瀏覽:698
雲南邊緣計算伺服器雲伺服器 瀏覽:105
小公司如何選擇伺服器 瀏覽:791
android指紋識別驅動 瀏覽:447
榮耀手機的系統有方舟編譯器嗎 瀏覽:629
單片機應用的論文 瀏覽:474
什麼app可以查網購的真偽 瀏覽:444
培訓班的程序員怎麼樣找工作 瀏覽:813
codeblocks編譯器位數 瀏覽:447
bios加密怎麼設置 瀏覽:350
台電u盤加密大師損壞 瀏覽:850