iText - 在循环中读取pdf并逐个合并 [英] iText - Read pdfs in a loop and merge one by one
问题描述
我有一个循环,我每次都读取一个pdf文件。我想将这些pdf文件添加到另一个最终的pdf中。基本上将所有pdf合并为一个新的pdf文件。
I have a loop where I read a pdf file every time. And I want to add these pdf files into another final pdf. Basically merging all pdfs into one new pdf file.
我尝试了以下方式:
我试图连接byteArrays循环内部像
I tried to concatenate byteArrays inside the loop like
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
for (............){
outputStream.write(myInfo.getByteArray());
}
pdfreader = new PdfReader(outputStream.toByteArray());
FileOutputStream fileout = new FileOutputStream(file);
PdfStamper pdfStamper = new PdfStamper(pdfreader, fileout);
pdfStamper.close();
pdfreader.close();
最终的pdf没有所有pdf的问题。相反,它只有一个pdf。
The problem the final pdf does not have all the pdfs. Instead it has only one pdf.
而且我不确定这是否是正确的方法。
或者还有其他任何一个一个合并pdfs?
And I am not sure if this is the right way to do it. Or is there any other to merge pdfs one by one ?
推荐答案
查看PdfMerger的文档: itextsupport.com/apidocs/iText7/7.0.3/com/itextpdf/kernel/utils/PdfMerger.html
Have a look at the documentation for PdfMerger: itextsupport.com/apidocs/iText7/7.0.3/com/itextpdf/kernel/utils/PdfMerger.html
如果需要,我可以稍后准备一个例子。
I can prepare an example later if needed.
这篇关于iText - 在循环中读取pdf并逐个合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!