Hello All,

We have a requirement to add watermark (text) to every
page of the existing PDF document. After browsing the
forum, I could find that adding watermark to existing
PDF can be done using PDFStamper class. 

I am posting the sample code below. 

                try
                {
                        PdfReader reader = new
PdfReader(getFileAsByteArray("c:\\in.pdf"));
                        ByteArrayOutputStream out = new
ByteArrayOutputStream();
                        PdfStamper stamper = new PdfStamper(reader,out);
                        BaseFont bf =
BaseFont.createFont(BaseFont.HELVETICA,BaseFont.WINANSI,
BaseFont.EMBEDDED);
                        PdfContentByte over;
                        int total = reader.getNumberOfPages() + 1;
                        for (int i = 1; i < total; i++) 
                        {    
                                over = stamper.getOverContent(i);
                                over.beginText();    
                                over.setFontAndSize(bf, 10);    
                                over.setTextMatrix(10, 10);    
                                over.showText("This document was printed from 
Test
Env");
                                over.setFontAndSize(bf, 10);
                                over.endText(); 
                        }
                        stamper.close();
                        
                                byte[] result = out.toByteArray();
                                OutputStream os = new
FileOutputStream("c:\\out.pdf");
                                os.write(result);
                                os.close();
                }
                catch(Exception e)
                {
                        e.printStackTrace();
                }



However, I would like to hide the watermark text when
viewing the document, but while priniting, I should be
able to print the PDF along with added watermark text.


I am not sure if this is possible with PDFStamper?
Please share your experience on this and let me know
if this can be doable?

Thanks,
Vijay


      
____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to