Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将完整PDF文件附加到FOP PDF_Java_Apache Fop - Fatal编程技术网

Java 将完整PDF文件附加到FOP PDF

Java 将完整PDF文件附加到FOP PDF,java,apache-fop,Java,Apache Fop,我已经创建了一个xml文件,并通过servlet将其呈现为PDF: TraxInputHandler input = new TraxInputHandler( new File(XML_LOCATION+xmlFile+".xml"), new File(XSLT_LOCATION) ); ByteArrayOutputStream out = new ByteArrayOutputStream(); //driver is just `new Driver()` synchro

我已经创建了一个xml文件,并通过servlet将其呈现为PDF:

TraxInputHandler input = new TraxInputHandler(
   new File(XML_LOCATION+xmlFile+".xml"),
   new File(XSLT_LOCATION)
);
ByteArrayOutputStream out = new ByteArrayOutputStream();

//driver is just `new Driver()`
synchronized (driver) {
  driver.reset();
  driver.setRenderer(Driver.RENDER_PDF);
  driver.setOutputStream(out);
  input.run(driver);
}

//response is HttpServletResponse
byte[] content = out.toByteArray();
response.setContentType("application/pdf");
response.setContentLength(content.length);
response.getOutputStream().write(content);
response.getOutputStream().flush();
这一切都很好


但是,我现在有另一个PDF文件需要包含在输出中。这只是我收到的一个完全独立的
.pdf
文件。是否有任何方法可以将此文件附加到响应、驱动程序、
out
,或任何其他内容,以将其包含在对客户端的响应中?这行得通吗?或者我还需要做些什么?

我们也使用FOP生成一些文档,我们接受上传的文档,所有这些文档最终都合并成一个PDF

您不能只按顺序将它们发送出流,因为组合的结果需要适当的PDF文件头、元数据等

我们使用来组合文件,从

PdfReader reader = new PdfReader(/*String*/fileName);
reader.consolidateNamedDestinations();
稍后,我们将循环将每个pdf中的页面添加到新的组合目标pdf中,并在执行过程中调整书签/页码

好吧,FOP不提供这种功能