第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

按順序合并多個(gè)pdf

按順序合并多個(gè)pdf

慕妹3146593 2021-09-03 13:28:11
嘿伙計(jì)們,對(duì)于長(zhǎng)篇大論和糟糕的語(yǔ)言,如果有不必要的細(xì)節(jié),我使用 excel 文檔從一個(gè) pdf 模板創(chuàng)建了多個(gè) 1page pdf,我現(xiàn)在有這樣的東西tempfile0.pdftempfile1.pdftempfile2.pdf...我試圖合并所有使用 itext5 在單個(gè) pdf 中創(chuàng)建文件,但它表明結(jié)果 pdf中的頁(yè)面與第一頁(yè)tempfile1中的每個(gè)示例tempfile0.pdf 中 我想要的順序不同 。這里的 2000 頁(yè) 是我使用的代碼。我使用的程序是:1 從哈希圖中填充一個(gè)2 將填充的表單保存為一個(gè) pdf3 將所有文件合并為一個(gè) pdfpublic void fillPdfitext(int debut,int fin) throws IOException, DocumentException {    for (int i =debut; i < fin; i++) {        HashMap<String, String> currentData = dataextracted[i];        // textArea.appendText("\n"+pdfoutputname +" en cours de preparation\n ");        PdfReader reader = new PdfReader(this.sourcePdfTemplateFile.toURI().getPath());        String outputfolder = this.destinationOutputFolder.toURI().getPath();        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outputfolder+"\\"+"tempcontrat"+debut+"-" +i+ "_.pdf"));        // get the document catalog        AcroFields acroForm = stamper.getAcroFields();        // as there might not be an AcroForm entry a null check is necessary        if (acroForm != null) {            for (String key : currentData.keySet()) {                try {                    String fieldvalue=currentData.get(key);                    if (key=="ADRESSE1"){                        fieldvalue = currentData.get("ADRESSE1")+" "+currentData.get("ADRESSE2") ;                        acroForm.setField("ADRESSE", fieldvalue);                    }                    if (key == "IMEI"){                        acroForm.setField("NUM_SERIE_PACK", fieldvalue);                    }                    acroForm.setField(key, fieldvalue);                    // textArea.appendText(key + ": "+fieldvalue+"\t\t");                } catch (Exception e) {                    // e.printStackTrace();                }            }            stamper.setFormFlattening(true);        }        stamper.close();    }}我的問(wèn)題是如何在生成的 pdf 中保持文件的順序相同
查看完整描述

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 ...

}


查看完整回答
反對(duì) 回復(fù) 2021-09-03
  • 1 回答
  • 0 關(guān)注
  • 185 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)