Block copy PDF document

Posted by Wiliam Witter on Stack Overflow See other posts from Stack Overflow or by Wiliam Witter
Published on 2011-01-06T13:32:12Z Indexed on 2011/01/06 13:53 UTC
Read the original article Hit count: 243

Filed under:
|
|

hello Gentlemen, I would like block copy (ctrl+c ctrl+v) PDF document using java. I have a code that build a PDF document with JasperReport...

//seta o caminho dos arquivos jasper
        String pathLote = ScopeSupport.getServletContext().getRealPath("priv/sgc/relatorios/AtaPregaoLotePageReport.jasper");
        String pathCabecalho = ScopeSupport.getServletContext().getRealPath("priv/sgc/relatorios/CabecalhoPageReport.jasper");
        String pathRodape = ScopeSupport.getServletContext().getRealPath("priv/sgc/relatorios/rodapePageReport.jasper");
        String imagemDir = ScopeSupport.getServletContext().getRealPath("/priv/comum/img");

        //HashMap parametros passa o parametro usado na query e o caminho da imagem
        HashMap<String,Object> parametros = new HashMap<String,Object>();
        parametros.put("idPregao", idPregao);
        parametros.put("idLote", idLote);
        parametros.put("IMAGEM_DIR", imagemDir + "/");
        parametros.put("USUARIO", "NomeUsuario" );
        parametros.put("texto", texto);
        parametros.put("numeroAta", numAta);

        if(numAta != null && numAta > 0)
            parametros.put("relatorio", "Ata "+numAta);

        HashMap<String,Object> parametrosSub = new HashMap<String,Object>();
        parametrosSub.put("CabecalhoPageReport", pathCabecalho);
        parametrosSub.put("rodapePageReport", pathRodape);
        parametrosSub.put("AtaPregaoPorLotePageReport", pathLote);

        for(String element : parametrosSub.keySet()){
            parametros.put(element, (JasperReport) JRLoader.loadObject((String) (parametrosSub.get(element))));
        }

        JasperReport report = (JasperReport) JRLoader.loadObject( pathLote );
        JasperPrint printRel = JasperFillManager.fillReport( report, parametros, getJDBCConnection() );
        byte[] bytes = JasperExportManager.exportReportToPdf(printRel);

        httpResponse.setHeader("Content-Disposition","attachment; filename=\""+ report.getName() + ".pdf" +"\";");
        httpResponse.setContentLength(bytes.length);
        httpResponse.setContentType("application/pdf");

        ServletOutputStream ouputStream = httpResponse.getOutputStream();
        ouputStream.write(bytes, 0, bytes.length);
        ouputStream.flush();
        ouputStream.close();

Who can help me with this?

© Stack Overflow or respective owner

Related posts about java

Related posts about pdf