Professional Documents
Culture Documents
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
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 ) ;
Not the answer you're looking for? Browse other questions tagged image insert
background itext or ask your own question.