0

I am new to iText pdf library. Can any one guide me how to add background color to entire page (not for chunk or paragraph) using iText pdf in java.

Jens
  • 63,364
  • 15
  • 92
  • 104
Arun
  • 15
  • 1
  • 5

2 Answers2

1

This code will do the job:

Rectangle pageSize = new Rectangle(216, 720);
pageSize.setBackgroundColor(new BaseColor(0xFF, 0xFF, 0xDE));
Document document = new Document(pageSize);
Jens
  • 63,364
  • 15
  • 92
  • 104
  • Thank you so much.But error shows as color can not converted to base color at line " pageSize.setBackgroundColor(new java.awt.Color(0xFF, 0xFF, 0xDE)); " – Arun May 13 '15 at 05:25
  • @Arunjk wich version of Itext do you use? have you imported the correct objects? – Jens May 13 '15 at 05:31
  • ooops my mistake. i did not imported. Could you please tell me how to add background color to alternate pages? I tried but couldn't get through. Thanks in advance. – Arun May 13 '15 at 05:57
  • @Arunjk Sorry can't get you. Do you want to have e.g. first page yellow. second page red and so on? – Jens May 13 '15 at 05:59
  • I want only first two pages in blue color and rest of pages in white color. – Arun May 13 '15 at 06:05
  • 1
    In this case you have to use PageEvents. Look [here](http://what-when-how.com/itext-5/adding-page-events-to-pdfwriter-itext-5/) – Jens May 13 '15 at 06:17
  • Thank you so much.I really appreciate your help. – Arun May 13 '15 at 06:31
0

Use this code:

Rectangle pageSize = new Rectangle(400, 720); 
pageSize.setBackgroundColor(BaseColor.YELLOW);
Document document = new Document(pageSize);
Dada
  • 5,692
  • 6
  • 21
  • 39
Krishna
  • 1
  • 3