1 回答

TA貢獻(xiàn)1806條經(jīng)驗(yàn) 獲得超5個(gè)贊
這是因?yàn)槲募拿?。您的代碼 new FileOutputStream(outputfolder + "\\" + "tempcontrat" + debut + "-" + i + "_.pdf") 將產(chǎn)生:
tempcontrat0-0_.pdf
tempcontrat0-1_.pdf
...
tempcontrat0-10_.pdf
tempcontrat0-11_.pdf
...
tempcontrat0-1000_.pdf
其中tempcontrat0-1000_.pdf將放置在tempcontrat0-11_.pdf之前,因?yàn)槟诤喜⒅鞍醋帜疙樞驅(qū)ζ溥M(jìn)行排序。
最好0使用leftPad()方法org.apache.commons.lang.StringUtils或?qū)⑻畛湮募幪?hào)與字符一起保留,java.text.DecimalFormat并使其像這樣tempcontrat0-000000.pdf , tempcontrat0-000001.pdf , ... tempcontrat0-9999999.pdf。
而且您還可以做得更簡(jiǎn)單,跳過(guò)寫(xiě)入文件,然后從文件步驟中讀取并在填寫(xiě)表格后立即合并文檔,這樣會(huì)更快。但這取決于您要合并的文檔數(shù)量和大小以及您有多少內(nèi)存。
因此,您可以將填充的文檔保存到該流中的字節(jié)中,ByteArrayOutputStream并在stamper.close()創(chuàng)建新PdfReader的字節(jié)之后調(diào)用pdfSmartCopy.getImportedPage()該閱讀器。簡(jiǎn)而言之,它看起來(lái)像:
// initialize
PdfSmartCopy pdfSmartCopy = new PdfSmartCopy(document, memoryStream);
for (int i = debut; i < fin; i++) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
// fill in the form here
stamper.close();
PdfReader reader = new PdfReader(out.toByteArray());
reader.consolidateNamedDestinations();
PdfImportedPage pdfImportedPage = pdfSmartCopy.getImportedPage(reader, 1);
pdfSmartCopy.addPage(pdfImportedPage);
// other actions ...
}
添加回答
舉報(bào)