導航:首頁 > 文檔加密 > 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相關的資料

熱點內容
java打賞源碼搭建 瀏覽:363
pdf32 瀏覽:254
植發加密100天效果 瀏覽:957
離心壓縮機檢修規程 瀏覽:430
如何收聽安卓手機發來的鏈接 瀏覽:399
福建微法院app怎麼用 瀏覽:208
android陀螺儀應用 瀏覽:719
新加坡加密貨幣騙局 瀏覽:910
電腦文件夾打開自動變為全屏 瀏覽:969
簡易單斷面計演算法 瀏覽:850
php社區程序 瀏覽:976
python現在就業怎麼樣 瀏覽:305
php上傳目錄許可權設置 瀏覽:736
php合同檔案管理系統 瀏覽:366
tshock伺服器地址 瀏覽:877
php解析文件流 瀏覽:780
伺服器機箱銅片有什麼用 瀏覽:969
樂視手機如何使用原生態安卓 瀏覽:216
dns伺服器怎麼備份啊 瀏覽:865
蘋果退款app怎麼重新購買 瀏覽:655