Pattern of ellipses : Pattern « PDF « Java Tutorial






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

import com.lowagie.text.Document;
import com.lowagie.text.pdf.PatternColor;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfPatternPainter;
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();
    
    
    PdfPatternPainter ellipse = cb.createPattern(15, 10, 20, 25);
    ellipse.setColorFill(new Color(0xFF, 0xFF, 0x00));
    ellipse.setColorStroke(new Color(0xFF, 0x00, 0x00));
    ellipse.ellipse(2f, 2f, 13f, 8f);
    ellipse.fillStroke();

    PatternColor ellipses = new PatternColor(ellipse);

    cb.setColorFill(ellipses);
    cb.rectangle(144, 716, 72, 72);
    cb.fillStroke();
    
    document.close();
  }
}








29.73.Pattern
29.73.1.Square pattern
29.73.2.Pattern of ellipses
29.73.3.Pdf Pattern Painter
29.73.4.Line pattern
29.73.5.Create and use PdfGState
29.73.6.Use SpotColor