Shading Pattern Text : Pattern « PDF RTF « Java






Shading Pattern Text

Shading Pattern Text
import java.awt.Color;
import java.io.FileOutputStream;

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

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

      PdfShading shading = PdfShading.simpleAxial(writer, 100, 100, 400, 100, Color.red, Color.cyan);
      PdfShadingPattern shadingPattern = new PdfShadingPattern(shading);
      
      PdfContentByte cb = writer.getDirectContent();

      BaseFont bf = BaseFont.createFont(BaseFont.TIMES_BOLD, BaseFont.WINANSI, false);
      
      cb.setShadingFill(shadingPattern);
      cb.beginText();
      cb.setTextMatrix(100, 100);
      cb.setFontAndSize(bf, 40);
      cb.showText("Look at this text!");
      cb.endText();

      document.close();
    } catch (Exception de) {
      de.printStackTrace();
    }
  }
}
           
       








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.PdfPatternPainter DemoPdfPatternPainter Demo
5.Set Pattern colorSet Pattern color
6.Setting PdfContentByte for PdfPatternPainterSetting PdfContentByte for PdfPatternPainter
7.PdfSpotColor for PatternPdfSpotColor for Pattern
8.Pattern by PdfContentBytePattern by PdfContentByte
9.Image Pattern: ShapeImage Pattern: Shape