How to Add Title, Author, Subject and keywords to the Pdf document using iText

We can extend itext to add Title for the Pdf document, we can add Author name, subject and also keywords to the pdf document.

You can view these details in Pdf File -> Properties.

We will extend the basic example and demonstrate this example:

We can see the different options that are available to extend the use of iText pdf.

Enter document. and press space bar, where it will show you the options like below :
itext document proposal options

Please find the below example program:


import java.io.FileOutputStream;
import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;

public class iTextPDFTutorial {
	public void iTextPDF() throws Exception{
		String FILE = "D:/sampleiTextexample.pdf";
		Document document = new Document();
		PdfWriter.getInstance(document, 
			new FileOutputStream(FILE));
		document.open();
		//To add the title to PDF
		document.addTitle("iText Pdf");//
		//To add the Author for the PDF
		document.addAuthor("Selenium Easy");
		//To add the subject to the PDF document
		document.addSubject("iText Tutorial");
		//To add the Keywords for the document
		document.addKeywords("keyword1,keyword2,keyword3....etc");
		document.add(new Paragraph("Hello iText advanced example "));
		document.add(new Paragraph("Please check the properties of the PDF"));
		document.close();	
	}
	public static void main(String args[]){
		iTextPDFTutorial get = new iTextPDFTutorial();
		try {
			get.iTextPDF();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

The below is the output report generated:
itext document proposal options

Reporting Tools: 

Add new comment

Image CAPTCHA