PDF RTF Java

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)