I have written an small iText program to watermark our internal pdf files.  I
am using the PdfStamper and Image classes to add the watermark.  The
resulting pdf displays an error pop-up in Adobe Reader (but not in Google
Chrome or PDF Exchange Viewer) and the added image is not visible.  The code
snippet is below and I have attached a sample watermarked
http://itext-general.2136553.n4.nabble.com/file/n3498739/socrates.pdf
socrates.pdf  pdf:

private File applyWatermarkToPdf(File newImageFile) throws Exception
        {
                Rectangle pdfRectangle = pdfReader.getPageSize(1);
                                
                File watermarkedPdfFile = new File(workDir, pdfFile.getName());
                PdfStamper stamper = new PdfStamper(pdfReader, new
FileOutputStream(watermarkedPdfFile));
                stamper.setRotateContents(false);
                
                Image image = Image.getInstance(newImageFile.getAbsolutePath());
                
                float maxPdfDimension = (pdfWidth > pdfHeight ? pdfWidth : 
pdfHeight);
                float minPdfDimension = (pdfWidth < pdfHeight ? pdfWidth : 
pdfHeight);
                float newImageWidth = 0.3f * maxPdfDimension;
                float newImageHeight = imageFileHeight * (newImageWidth / 
imageFileWidth);
                
                image.scaleToFit(newImageWidth, newImageHeight);
                image.setTransparency(new int[] {50,255});
                image.setRotationDegrees(pageRotation);
                if (pageRotation == 0.0f || pageRotation == 180.0f)
                        image.setAbsolutePosition(xOffsetWatermark, pdfHeight -
yOffsetWatermark);
                else
                        image.setAbsolutePosition(xOffsetWatermark, 
yOffsetWatermark);
                                
                PdfGState gstate = new PdfGState();
                gstate.setFillOpacity(0.3f);
                gstate.setStrokeOpacity(0.3f);
                PdfContentByte pdfContent = stamper.getOverContent(1);
                pdfContent.saveState();
                pdfContent.setGState(gstate);
                pdfContent.addImage(image);     
                
                stamper.close();
        
                return watermarkedPdfFile;
        }

--
View this message in context: 
http://itext-general.2136553.n4.nabble.com/Image-added-to-PdfStamper-gives-Error-exists-on-this-page-tp3498739p3498739.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
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

Reply via email to