使用Apache FOP导出多个pdf文件 - portlet Liferay

时间:2013-12-18 10:00:29

标签: pdf export portlet apache-fop

我有一个循环用于生成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();              
            }   
}

我的问题是它只生成一个文件,而不是多个文件。谢谢大家

1 个答案:

答案 0 :(得分:0)

通过一个响应,您只能返回一个文件。您可以创建包含许多pdf的压缩文件并将其返回。