Meta Headers
iText is a free and open source library for creating and manipulating
PDF documents in Java. The following example shows setting various meta headers for PDF document.
package com.bethecoder.tutorials.itext.tests;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
public class MetaHeaders {
/**
* @param args
* @throws DocumentException
* @throws FileNotFoundException
*/
public static void main ( String [] args ) throws FileNotFoundException, DocumentException {
Document document = new Document ( PageSize.A4 ) ;
PdfWriter.getInstance ( document, new FileOutputStream ( "test2.pdf" )) ;
//Add document Headers
document.addAuthor ( "Sriram Kasireddi" ) ;
document.addTitle ( "PDF Headers" ) ;
document.addSubject ( "PDF Header Generation Tests" ) ;
document.addKeywords ( "Java, PDF, iText, BE THE CODER" ) ;
//Open the document before adding any content
document.open () ;
Paragraph paragraph = new Paragraph ( "BE THE CODER" ) ;
document.add ( paragraph ) ;
//Close the document
document.close () ;
}
}
It gives the following output,