Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Itext: Set alignment to paragraph

Paragraph class provides ‘setAlignment’ method to set the alignment of a Paragraph.

public void setAlignment(int alignment)


Following is the complete working application.

import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfWriter;

public class ParagraphEx {
private static Font fontNormal = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL, BaseColor.BLACK);
private static Font fontHeading = FontFactory.getFont(FontFactory.HELVETICA, 25, Font.BOLD,
new BaseColor(255, 0, 0));

private static String data = "We Are Living In An Environment, Where Multiple Hardware Architectures And Multiple Platforms Presents. So It Is Very Difficult To Write, Compile And Link The Same Application, For Each Platform And Each Architecture Separately. The Java Programming Language Solves All The Above Problems. The Java Programming Language Platform Provides A Portable, Interpreted, High-Performance, Simple, Object-Oriented Programming Language And Supporting Run-Time Environment. Java Design And Architecture Decisions Drew From A Variety Of Languages Such As Eiffel, SmallTalk, Objective C, And Cedar/Mesa. Closely Observed The Problems In The Other Languages Like Platform Dependent, Pointers Complexity, Manual Garbage De Allocation Etc., Java Removes The Basic Problems In Other Languages. ";

public static void main(String args[]) throws FileNotFoundException, DocumentException {
Document document = new Document();

PdfWriter.getInstance(document, new FileOutputStream("java_features.pdf"));;

Paragraph paragraph = new Paragraph();
Phrase heading = new Phrase("Features Of Java", fontHeading);
Chunk chunk = new Chunk(data, fontNormal);




What is the default alignment?

Default is left alignment.

Previous                                                 Next                                                 Home

This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

Itext: Set alignment to paragraph


Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription