You are on page 1of 2

Stack Overflow is a question and answer site for professional and enthusiast programmers.

It's 100% free, no registration required.

Tell me more

How to insert a image under the text as a pdf background using iText?

I need some sample code to insert a image as a pdf background, is there any this kind of sample code ? and I have wrote the text well, then i need to insert a image under the text.
image insert background itext

asked Nov 25 '09 at 4:22 MemoryLeak 2,041 5 33 77

1 Answer
I think you are looking for water marking the pages in a PDF file.. check the below code. You could also use the Watermarker class.

P d f R e a d e rr e a d e r=n e wP d f R e a d e r ( " t e x t . p d f " ) ; i n tn=r e a d e r . g e t N u m b e r O f P a g e s ( ) ; / /C r e a t eas t a m p e rt h a tw i l lc o p yt h ed o c u m e n tt oan e wf i l e P d f S t a m p e rs t a m p=n e wP d f S t a m p e r ( r e a d e r , n e wF i l e O u t p u t S t r e a m ( " t e x t 1 . p d f " ) ) ; i n ti=1 ; P d f C o n t e n t B y t eu n d e r ; P d f C o n t e n t B y t eo v e r ; I m a g ei m g=I m a g e . g e t I n s t a n c e ( " w a t e r m a r k . j p g " ) ; B a s e F o n tb f=B a s e F o n t . c r e a t e F o n t ( B a s e F o n t . H E L V E T I C A , B a s e F o n t . W I N A N S I ,B a s e F o n t . E M B E D D E D ) ; i m g . s e t A b s o l u t e P o s i t i o n ( 2 0 0 ,4 0 0 ) ; w h i l e( i<n ) { / /W a t e r m a r ku n d e rt h ee x i s t i n gp a g e u n d e r=s t a m p . g e t U n d e r C o n t e n t ( i ) ; u n d e r . a d d I m a g e ( i m g ) ; / /T e x to v e rt h ee x i s t i n gp a g e o v e r=s t a m p . g e t O v e r C o n t e n t ( i ) ;

o v e r=s t a m p . g e t O v e r C o n t e n t ( i ) ; o v e r . b e g i n T e x t ( ) ; o v e r . s e t F o n t A n d S i z e ( b f ,1 8 ) ; o v e r . s h o w T e x t ( " p a g e"+i ) ; o v e r . e n d T e x t ( ) ; i + + ; } s t a m p . c l o s e ( ) ; Regards, Abdel Olakara


answered Nov 25 '09 at 6:41 Abdel Olakara 8,936 3 27 71 Is it possible to apply layer with itext ? do you have any sample code ? also do you have a MSN ? MemoryLeak Nov 27 '09 at 1:50

Not the answer you're looking for? Browse other questions tagged image insert
background itext or ask your own question.

You might also like