Bom dia, eu estou com um problema tenho que restringir um arquivo .pdf para não deichar o usuario copiar apenas visualizar, estou gerando meu relatório com jasperReport
public void printPdfUISub(HttpServletResponse httpResponse, String pathRelatorio, Map<String,Object> param, Map<String,Object> paramSub) throws Exception {
Connection conn = getJDBCConnection();
try {
for(String element : paramSub.keySet()){
param.put(element, (JasperReport) JRLoader.loadObject((String) (paramSub.get(element))));
}
JasperReport report = (JasperReport) JRLoader.loadObject( pathRelatorio );
JasperPrint printRel = JasperFillManager.fillReport( report, param, conn );
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();
} catch (Exception e) {
throw new RuntimeException("Erro ao gerar relatório.",e);
}
finally{
conn.close();
}
}
PdfEncryptor.encrypt(pdfReader, ouputStream, PdfWriter.STRENGTH128BITS, null, null, PdfWriter.AllowPrinting);