Use different colors to fill : Stroke « PDF « Java Tutorial






import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.CMYKColor;
import com.lowagie.text.pdf.GrayColor;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;

public class MainClass {
  public static void main(String[] args) throws Exception {
    Document document = new Document();
      PdfWriter writer = PdfWriter.getInstance(
          document,
          new FileOutputStream("2.pdf"));
      document.open();
      PdfContentByte cb = writer.getDirectContent();
      cb.setColorFill(new GrayColor(0));
      cb.rectangle(36, 770, 36, 36);
      cb.fillStroke();

      cb.setGrayFill(1);
      cb.rectangle(470, 716, 36, 36);
      cb.fillStroke();

      cb.setColorFill(new Color(1f, 1f, 1f));
      cb.rectangle(416, 662, 36, 36);
      cb.fillStroke();

      cb.setRGBColorFillF(1f, 1f, 1f);
      cb.rectangle(416, 608, 36, 36);
      cb.fillStroke();

      cb.setColorFill(new CMYKColor(0f, 0f, 0f, 1f));
      cb.rectangle(416, 554, 36, 36);
      cb.fillStroke();

      cb.setCMYKColorFillF(0f, 0f, 0f, 1f);
      cb.rectangle(416, 500, 36, 36);
      cb.fillStroke();
    document.close();
  }
}








29.51.Stroke
29.51.1.Finish a stroke
29.51.2.close Path Stroke
29.51.3.Color stroke and color fill
29.51.4.fill Stroke
29.51.5.close Path Fill Stroke
29.51.6.eoFillStroke method
29.51.7.Use different colors to fill