我有一个循环用于生成xml数据,并导出它的PDF文件
@ResourceMapping("doPrint")
public void printFunction( @ModelAttribute(FILTER_STAMPA_MODEL_ATTRIBUTE) ListManlevaRequestDTO filter, ResourceRequest request, ResourceResponse response ){
ByteArrayOutputStream out = new ByteArrayOutputStream();
ListManlevaResponseDTO manlevaResponse=manlevaServiceFacade.listManleva(filter);
for(int i = 0; i<manlevaResponse.getResults().size();i++){
String resultGeneration= FopManlevaUtil.createPdf(manlevaResponse.getResults().get(i), out, request);
// Send content to Browser
HttpServletResponse hsr = PortalUtil.getHttpServletResponse(response);
if (hsr != null) {
hsr.setHeader("Pragma", "public");
hsr.setHeader("Expires", "0");
hsr.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
hsr.setHeader("Content-Disposition", String.format("attachment; filename=%s.%s", resultGeneration, "pdf"));
}
// Prepare response
response.setContentType("application/pdf");
response.setContentLength(out.size());
response.getPortletOutputStream().write(out.toByteArray());
out.flush();
out.close();
response.getPortletOutputStream().flush();
response.getPortletOutputStream().close();
}
}
我的问题是它只生成一个文件,而不是多个文件。谢谢大家
答案 0 :(得分:0)
通过一个响应,您只能返回一个文件。您可以创建包含许多pdf的压缩文件并将其返回。