Colored Paragraphs : Paragraph « PDF « Java Tutorial






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

import com.lowagie.text.Document;
import com.lowagie.text.Font;
import com.lowagie.text.Image;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.CMYKColor;
import com.lowagie.text.pdf.PatternColor;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfPatternPainter;
import com.lowagie.text.pdf.PdfShading;
import com.lowagie.text.pdf.PdfShadingPattern;
import com.lowagie.text.pdf.PdfSpotColor;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.ShadingColor;
import com.lowagie.text.pdf.SpotColor;

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();

    PdfSpotColor psc_cmyk = new PdfSpotColor("iTextSpotColorCMYK", 0.25f, new CMYKColor(0.3f, .9f,
        .3f, .1f));
    SpotColor sc_cmyk = new SpotColor(psc_cmyk);

    Image img = Image.getInstance("dog.jpg");
    PdfPatternPainter img_pattern = cb.createPattern(img.scaledWidth(), img.scaledHeight(), img
        .scaledWidth(), img.scaledHeight());
    img_pattern.addImage(img, img.scaledWidth(), 0f, 0f, img.scaledHeight(), 0f, 0f);
    img_pattern.setPatternMatrix(1f, 0f, 0f, 1f, 60f, 60f);

    document.add(new Paragraph("This is a paragraph painted using a SpotColor", new Font(
        Font.HELVETICA, 24, Font.BOLD, sc_cmyk)));
    document.close();
  }
}








29.20.Paragraph
29.20.1.Add a Paragraph to a document
29.20.2.Paragraph Alignment: ALIGN_JUSTIFIED
29.20.3.Paragraph Alignment: Element.ALIGN_RIGHT
29.20.4.Element.ALIGN_JUSTIFIED
29.20.5.Paragraph Spacing Before
29.20.6.Paragraph Indentation Left
29.20.7.Paragraph Indentation Right
29.20.8.Paragraph Spacing After
29.20.9.Paragraph text
29.20.10.Paragraph Positions
29.20.11.Colored Paragraphs