Paragraph Alignment: ALIGN_JUSTIFIED : Paragraph « PDF « Java Tutorial






import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;

public class MainClass {
  public static void main(String[] args) throws Exception {
    Document document = new Document(PageSize.A8.rotate());
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();
    String text = "this is a test";
    Paragraph paragraph = new Paragraph(text);
    paragraph.setAlignment(Element.ALIGN_JUSTIFIED);
    document.add(paragraph);
    document.newPage();
    writer.setSpaceCharRatio(PdfWriter.NO_SPACE_CHAR_RATIO);
    document.add(paragraph);
    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