In this core java tutorial we will learn how to Create Left, center and right aligned Paragraph In Pdf in java - using iText library - core java tutorial in Java with program and examples.
how to Create Paragraph In Pdf - iText java tutorial program
Create Phrase In Pdf (with lead) Using Itext - iText java tutorial example
How to Set the Font Name, Size, Style and Colour In Pdf using itext in java
How To Set HyperLink (Anchor - a tag) In Pdf in java - iText java tutorial
Convert Html To Pdf in java using iText - iText java tutorial
How To Set Header and Footer in pdf in java using Itext Example - iText java tutorial
Download all jars required to execute program >
Or, you may download jars from here
Program/Example to how to Create Left, center and right aligned Paragraph In Pdf - Using iText library - core java tutorial
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
/**
*
* Create Left, center and right aligned Paragraph In Pdf Using Itext Example -
* Using iText library - core java tutorial
*
*/
public class ParagraphAlignmentInPdfUsingItextExample {
public static void main(String[] args) {
try {
String pdfFilePath = "e:/Paragraph Alignment in Pdf Using Itext Example.pdf";
OutputStream fos = new FileOutputStream(new File(pdfFilePath));
Document document = new Document();
PdfWriter.getInstance(document, fos);
document.open();
//create left Aligned Paragraph
Paragraph leftAlignedParagraph= new Paragraph("This paragraph is left aligned in PDF.");
leftAlignedParagraph.setAlignment(Element.ALIGN_LEFT);
//create center Aligned Paragraph
Paragraph centerAlignedParagraph= new Paragraph("This paragraph is center aligned in PDF.");
centerAlignedParagraph.setAlignment(Element.ALIGN_CENTER);
//create right Aligned Paragraph
Paragraph rightAlignedParagraph= new Paragraph("This paragraph is right aligned in PDF.");
rightAlignedParagraph.setAlignment(Element.ALIGN_RIGHT);
document.add(leftAlignedParagraph);
document.add(centerAlignedParagraph);
document.add(rightAlignedParagraph);
document.close();
fos.close();
System.out.println("PDF created in >> "+ pdfFilePath);
} catch (Exception e) {
e.printStackTrace();
}
}
}
/* Output of above program
PDF created in >> e:/Paragraph Alignment in Pdf Using Itext Example.pdf
*/
|
PDF formed after executing above java program (how to Create Left, center and right aligned Paragraph In Pdf in java) will look like this >
Summary -
So in this core java tutorial we learned how to Create Left, center and right aligned Paragraph In Pdf in java - using iText library - core java tutorial in Java with program and examples.
Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.
References >
RELATED LINKS>
iText library tutorial in java - How to Create and work with PDF files in java
Creating first pdf and setting attributes using itext in java - iText tutorial >
Create the first Pdf Example Using iText library in java - iText java tutorial example
Setting Pdf Attributes like Title, Author, Creator, subject, Keywords, Header and CreationDate in java
Labels:
Core Java
iText Pdf tutorial