PdfShading.simpleAxial : Shading « PDF « Java Tutorial






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

import com.lowagie.text.Document;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfShading;
import com.lowagie.text.pdf.PdfShadingPattern;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.ShadingColor;

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();
    PdfShading axial = PdfShading.simpleAxial(writer, 36, 716, 396, 788, Color.orange, Color.blue);


    PdfShadingPattern axialPattern = new PdfShadingPattern(axial);
    ShadingColor axialColor = new ShadingColor(axialPattern);
    cb.setColorFill(axialColor);
    cb.rectangle(36, 608, 72, 72);
    cb.rectangle(144, 608, 72, 72);
    cb.rectangle(252, 608, 72, 72);
    cb.rectangle(360, 608, 72, 72);
    cb.fillStroke();
    document.close();
  }
}








29.15.Shading
29.15.1.PdfShading.simpleRadial
29.15.2.PdfShading.simpleAxial
29.15.3.Spot Color