我需要将多个pdf文件合并为一个pdf并在我的网络浏览器中显示。 我知道如何显示一个文件:
File file = new File(activite.getLienUploadUn());
FileInputStream inputStream = new FileInputStream(file);
byte[] buffer = new byte[8192];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1)
{
baos.write(buffer, 0, bytesRead);
}
response.setHeader("Content-Disposition","inline; filename=\""+file.getName()+"\"");
response.setContentType("application/pdf");
ServletOutputStream outputStream = response.getOutputStream();
baos.writeTo(outputStream);
outputStream.flush();
我想我将使用PdfBox及其PDFMergerUtility类来合并文件:
PDFMergerUtility mergePdf = new PDFMergerUtility();
mergePdf.addSource(file);
mergePdf.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
但是从那里我如何将合并的文档转换为byteArrayOutputStream?
答案 0 :(得分:1)
您可以致电PDFMergerUtility.setDestinationStream(OutputStream destStream)
传递输出流(javadoc)。