Paragraph text : Paragraph « PDF « Java Tutorial






import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileReader;

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.A4);
    PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();
    BufferedReader reader = new BufferedReader(new FileReader("a.txt"));
    String line;
    Paragraph p;
    while ((line = reader.readLine()) != null) {
      p = new Paragraph("    " + line);
      p.setAlignment(Element.ALIGN_JUSTIFIED);
      document.add(p);
    }
    reader.close();
    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