I have a existing pdf file "layer_source.pdf", I want to add a background
picture "watermark.jpg" on each page of this file. I hope the background pic
is only visible on screen and won't be printed on paper. I use Pdflayer
class of itext v5.1.2 here. I use the mothed "setPrint("Print", false)", but
the pic is always printed on paper.
Below are my code. Could you guys give me some suggestion? Thanks a lot!
public static void addLayer() throws Exception{
PdfReader pdfReader = new PdfReader("D:\\layer_source.pdf");
PdfStamper stamper = new PdfStamper(pdfReader, new
FileOutputStream("D:\\layer_target.pdf"));
Image watermarkImage = Image.getInstance("D:/watermark.jpg");
PdfLayer wmLayer = new PdfLayer("watermark", stamper.getWriter());
wmLayer.setOnPanel(true);
// set layer parameters
wmLayer.setOn(false);
wmLayer.setView(true);
wmLayer.setPrint("Print", false);
// Prepare transperancy
PdfGState transparent = new PdfGState();
transparent.setStrokeOpacity(1f);
transparent.setFillOpacity(1f);
PdfContentByte cb;
int toPage = stamper.getReader().getNumberOfPages();
for (int i = 1; i <= toPage; i++) {
cb = stamper.getUnderContent(i);
Rectangle rectangle = stamper.getReader()
.getPageSizeWithRotation(i);
cb.beginLayer(wmLayer);
cb.setGState(transparent); // set block trasparency properties
//
position relative to top
watermarkImage.scaleAbsoluteHeight(rectangle.getHeight() - 20);
watermarkImage.scaleAbsoluteWidth(rectangle.getWidth() - 20);
float absoluteY = rectangle.getBottom() +
(rectangle.getHeight() -
watermarkImage.getPlainHeight() - 10);
watermarkImage.setAbsolutePosition(10, 10);
cb.addImage(watermarkImage);
cb.endLayer();
}
stamper.close();
}
--
View this message in context:
http://itext-general.2136553.n4.nabble.com/Make-a-PDF-layer-only-visible-on-screen-can-not-be-printed-on-paper-tp3846123p3846123.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php