Pattern by PdfContentByte : Pattern « PDF RTF « Java






Pattern by PdfContentByte

Pattern by PdfContentByte
import java.awt.Color;
import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.PageSize;
import com.lowagie.text.pdf.CMYKColor;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfPatternPainter;
import com.lowagie.text.pdf.PdfSpotColor;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.SpotColor;

public class PatternPdfContentByte {
  public static void main(String[] args) {
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    try {
      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("PatternPdfContentByte.pdf"));
      document.open();

      PdfContentByte cb = writer.getDirectContent();
      
      PdfPatternPainter pat = cb.createPattern(10, 10, null);
      pat.setLineWidth(2);
      pat.moveTo(0, -5);
      pat.lineTo(15, 10);
      pat.stroke();
      
      cb.setPatternFill(pat, Color.red);
      cb.rectangle(100, 400, 30, 210);
      cb.fillStroke();
      
    } catch (Exception de) {
      de.printStackTrace();
    }
    document.close();
  }
}

           
       








itext.zip( 1,748 k)

Related examples in the same category

1.Text Pattern ColorText Pattern Color
2.Text Pattern ShapeText Pattern Shape
3.Shading PatternShading Pattern
4.Shading Pattern TextShading Pattern Text
5.PdfPatternPainter DemoPdfPatternPainter Demo
6.Set Pattern colorSet Pattern color
7.Setting PdfContentByte for PdfPatternPainterSetting PdfContentByte for PdfPatternPainter
8.PdfSpotColor for PatternPdfSpotColor for Pattern
9.Image Pattern: ShapeImage Pattern: Shape