現(xiàn)在系統(tǒng)需要拆分pdf,我使用pdfbox包,進(jìn)行處理。代碼如下:已經(jīng)實(shí)現(xiàn)將一個(gè)大pdf按頁(yè)拆分為多個(gè)pdf。但是,現(xiàn)在還有兩個(gè)問(wèn)題:1.在拆分時(shí),怎么實(shí)現(xiàn)設(shè)置頁(yè)數(shù)拆分(eg:每5頁(yè)拆分為一個(gè)小pdf)2.load時(shí),是將整個(gè)文件加載到內(nèi)存中;如果文件很大,該怎么處理
1 回答

一只名叫tom的貓
TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超3個(gè)贊
document = PDDocument.load(file, MemoryUsageSetting.setupTempFileOnly());
不把文件加載到內(nèi)存。
指定頁(yè)數(shù)拆分pdf:不使用splitter進(jìn)行拆分,使用getPages,然后新建一個(gè)臨時(shí)對(duì)象,往里邊添加指定數(shù)量的頁(yè)數(shù)
File file = new File(fileStr); document = PDDocument.load(file, MemoryUsageSetting.setupTempFileOnly()); document.getPages(); PDDocument doc = new PDDocument(); for (int i = startPageNum - 1; i < endPageNum; i++) { doc.addPage(document.getPage(i)); } doc.save(outputStream);
- 1 回答
- 0 關(guān)注
- 882 瀏覽
添加回答
舉報(bào)
0/150
提交
取消