PdfContentByte drawing state : Draw State « PDF RTF « Java






PdfContentByte drawing state

PdfContentByte drawing state
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.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;

public class StatePDF {
  public static void main(String[] args) {
    Document document = new Document();

    try {
      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("StatePDF.pdf"));
      document.open();

      PdfContentByte cb = writer.getDirectContent();

      cb.setColorFill(Color.red);
      cb.circle(250.0f, 500.0f, 250.0f);
      cb.fill();
      cb.saveState();
      
      cb.setColorFill(Color.BLACK);
      cb.circle(350.0f, 500.0f, 200.0f);
      cb.fill();
      cb.saveState();
      
      cb.setColorFill(Color.blue);
      cb.circle(460.0f, 500.0f, 150.0f);
      cb.fill();
      
      cb.restoreState();
      cb.circle(560.0f, 500.0f, 100.0f);
      cb.fill();
      
      cb.restoreState();
      cb.circle(660.0f, 500.0f, 50.0f);
      cb.fill();
    } catch (Exception de) {
      System.err.println(de.getMessage());
    }
    document.close();
  }
}
           
       








itext.zip( 1,748 k)

Related examples in the same category