我想使用java来阻止复制(ctrl + c ctrl + v)PDF文档。我有一个用JasperReport构建PDF文档的代码......
//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();
谁可以帮我这个?
答案 0 :(得分:0)
使用jasper report 5.6.x
时应该尝试这个 SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
configuration.setEncrypted(true);
configuration.set128BitKey(true);
configuration.setUserPassword("jasper");
configuration.setOwnerPassword("reports");
configuration.setPermissions(PdfWriter.ALLOW_PRINTING); //PdfWriter.ALLOW_COPY is no set
exporter.setConfiguration(configuration);
//extrac of http://jasperreports.sourceforge.net/sample.reference/pdfencrypt/index.html
在旧版中,您可以使用JRExporterParameter
pdfExporter.setParameter(JRPdfExporterParameter.PERMISSIONS, PdfWriter.ALLOW_PRINTING);
//when you want copy files use
//pdfExporter.setParameter(JRPdfExporterParameter.PERMISSIONS, PdfWriter.ALLOW_PRINTING | PdfWriter.ALLOW_COPY);
pdfExporter.setParameter(JRPdfExporterParameter.IS_ENCRYPTED, true);
pdfExporter.setParameter(JRPdfExporterParameter.USER_PASSWORD, ".sigaAr4gos@");
注意:JRPdfExporterParameter
是deprecade
答案 1 :(得分:-1)
可能我错了,但我坚信这是不可能的。您正在构建PDF文档并使用PDF Reader进行审阅。复制部分文档的能力是读者的功能,因此您无法在文档构建阶段控制此功能。 PDF不是HTML,您可以自己处理事件,从而阻止其中的一些事件。
我很高兴知道我错了......