Generate pdf file in Secured mode

Monday, May 5, 2014

I have written a code for pdf generation and it is working fine but now I to generate a pdf file in secured mode.

Here is my code for Secured mode

try {
HttpServletResponse response = ServletActionContext.getResponse();
PDFGenerator pdf = new PDFGenerator();

PDFGenerator generator=new PDFGenerator();

/* byte[] bytes = null;
bytes = (generator.generatepdf(sosValues.getCmaId(), null)).toByteArray();

//bytes = buffer.toByteArray();

if (bytes != null) {
bis = new ByteArrayInputStream(bytes);

ByteArrayOutputStream baos=generator.generatepdf(sosValues.getCmaId(), null);
bis = new ByteArrayInputStream(baos.toByteArray());

PdfReader pdfReader=new PdfReader(bis);

PdfStamper pdfStamper=new PdfStamper(pdfReader, baos);
pdfStamper.setEncryption(null,null, PdfWriter.HideToolbar, PdfWriter.STRENGTH40BITS);
pdfStamper.setEncryption("Hello".getBytes(), "World".getBytes(), PdfWriter.AllowPrinting
| PdfWriter.AllowCopy, PdfWriter.STRENGTH40BITS);


} catch (Exception e) {

While debugging I was getting an exception at this line pdfStamper.setEncryption(null,null, PdfWriter.HideToolbar, PdfWriter.STRENGTH40BITS);

Exception in browser was

The server encountered an internal error that prevented it from fulfilling this request.