PdfSpotColor for Pattern : Pattern « PDF RTF « Java






PdfSpotColor for Pattern

PdfSpotColor for Pattern
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.PdfTemplate;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.SpotColor;

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

      PdfContentByte cb = writer.getDirectContent();
      PdfTemplate tp = cb.createTemplate(400, 300);
      
      PdfPatternPainter pat = cb.createPattern(15, 15, null);
      pat.rectangle(5, 5, 5, 5);
      pat.fill();
      
      PdfSpotColor spc_cmyk = new PdfSpotColor("PANTONE 280 CV", 0.25f, new CMYKColor(0.9f, .2f, .3f, .1f));
      SpotColor spot = new SpotColor(spc_cmyk);
      
      tp.setPatternFill(pat, spot, .9f);
      tp.rectangle(0, 0, 40, 30);
      tp.fill();
      cb.addTemplate(tp, 50, 50);
    } 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.Pattern by PdfContentBytePattern by PdfContentByte
9.Image Pattern: ShapeImage Pattern: Shape