PdfStamper and ServletOutputStream
Display watermark in PDF documents from a byte[]
This show the pdf with waterMark in the client.
byte[] docB = null;
docB = doc.getContent();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfReader reader = new PdfReader(docB);
int n = reader.getNumberOfPages();
PdfStamper stamp = new PdfStamper(reader, baos);
int i = 0;
PdfContentByte under;
Image img = Image.getInstance("iconCsn.jpg");
img.setAbsolutePosition(200, 400);
while (i < n) {
i++;
under = stamp.getUnderContent(i);
under.addImage(img);
}
stamp.close();
getResponse().setHeader("Expires", "0");
getResponse().setHeader("Cache-Control", "must-revalidate, post-check=0,pre-check=0");
getResponse().setHeader("Pragma", "public");
getResponse().setContentType("application/pdf");
getResponse().setContentLength(baos.size());
ServletOutputStream out = getResponse().getOutputStream();
baos.writeTo(out);
out.flush();
This show the pdf with waterMark in the client.