Java PDF Formatting Using iText

Chapter: iText Last Updated: 14-08-2016 18:37:43 UTC

Program:

            /* ............... START ............... */
                
import java.io.FileOutputStream;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;

public class JavaPDFFormatting {

	private static String FILE = "JavaFormattedPDF.pdf";

	public static void main(String[] args) {
		try {
			Document document = new Document();
			PdfWriter.getInstance(document, new FileOutputStream(FILE));
			document.open();
			// Left
			Paragraph paragraph = new Paragraph("This is right aligned text");
			paragraph.setAlignment(Element.ALIGN_RIGHT);
			document.add(paragraph);
			// Centered
			paragraph = new Paragraph("This is centered text");
			paragraph.setAlignment(Element.ALIGN_CENTER);
			document.add(paragraph);
			// Left
			paragraph = new Paragraph("This is left aligned text");
			paragraph.setAlignment(Element.ALIGN_LEFT);
			document.add(paragraph);
			// Left with indentation
			paragraph = new Paragraph("This is left aligned text with indentation");
			paragraph.setAlignment(Element.ALIGN_LEFT);
			paragraph.setIndentationLeft(50);
			document.add(paragraph);

			document.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
                /* ............... END ............... */
        

Output


Java PDF Formatting Using iText

Tags

Java PDF Formatting , iText, Java

Similar Programs Chapter Last Updated
Java Set Background To Table Example iText 22-07-2017
Java PDF Hello World Example iText 14-08-2016
Read Existing PDF In Java iText 14-08-2016
Read OR Modify PDF File In Java Using iText iText 12-08-2016
PDF With Limited Permissions In Java Using iText iText 12-08-2016
Password Protected PDF Files Using Java iText iText 12-08-2016
Styling Or Formatting PDF In Java Using iText iText 11-08-2016
Create Lists In PDF Using Java iText iText 10-08-2016
Create Tables In PDF Using Java iText iText 10-08-2016
Add Images To PDF In Java Using iText iText 10-08-2016
File Attributes To PDF In Java Using iText iText 10-08-2016
PDF Creation In Java Using iText iText 10-08-2016

1