Quantcast

PDF Watermark resize

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

PDF Watermark resize

failsafe
Hello,

I have a watermark that I would like to put into my pdf. The watermark is a .bmp image, and is 2290 x 3026.  I am having a lot of trouble trying to resize this picture to fit the page, does anyone have any suggestions?

Document document = new Document();
                PdfWriter.getInstance(document, new FileOutputStream("result.pdf"));
                document.open();

                document.add(new Paragraph("hello"));
                document.close();
                PdfReader reader = new PdfReader("result.pdf");
                int number_of_pages = reader.getNumberOfPages();
                PdfStamper pdfStamper = new PdfStamper(reader, new FileOutputStream("result_watermark.pdf"));
                // Get the PdfContentByte type by pdfStamper.
                Image watermark_image = Image.getInstance("abstract(0307).bmp");
                int i = 0;
                watermark_image.setAbsolutePosition(0, 0);
                watermark_image.scaleAbsoluteWidth(626);
                watermark_image.scaleAbsoluteHeight(900);
                PdfContentByte add_watermark;
                while (i < number_of_pages) {
                        i++;
                        add_watermark = pdfStamper.getUnderContent(i);
                        add_watermark.addImage(watermark_image);
                       
                }
                pdfStamper.close();
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: PDF Watermark resize

iText Software
Hello,
please subscribe the OFFICIAL mailing-list instead of registering for a
third party service.
See http://lowagie.com/nabble for more info.

On 19/06/2012 21:07, failsafe wrote:
> Hello,
>
> I have a watermark that I would like to put into my pdf. The watermark is a
> .bmp image, and is 2290 x 3026.  I am having a lot of trouble trying to
> resize this picture to fit the page, does anyone have any suggestions?

In your code, I don't see you asking the reader for the page size, nor
for the origin of the page. Get the pagesize and use the scaleToFit()
method instead of the scaleAbsolute() methods. Don't forget to define
the offset of the image based on the origin of the coordinate system,
otherwise you risk adding the watermark outside the visible area of the
page.

> --
> View this message in context: http://itext-general.2136553.n4.nabble.com/PDF-Watermark-resize-tp4655377.html
> Sent from the iText - General mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
iText-questions mailing list
[hidden email]
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
Loading...