In this core java tutorial we will learn how to set Pdf Attributes like Title, Author, Creator, subject, Keywords, Header and CreationDate using iText library - core java tutorial in Java with program and examples.
We will generate PDF files in java using iText library. PDF files can be generated dynamically in java using iText library.
Download all jars required to execute program >
Or, you may download jars from here
Program/Example for Setting Pdf Attributes like Title, Author, Creator, subject, Keywords, Header and CreationDate - Using iText library - core java tutorial in Java
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
/**
*
* Setting Pdf Attributes Example Using iText library - core java tutorial
*
*/
public class SettingPdfAttributesExample {
public static void main(String[] args) {
try {
String pdfFilePath = "e:/Setting Pdf Attributes Example.pdf";
OutputStream fos = new FileOutputStream(new File(pdfFilePath));
Document document = new Document();
PdfWriter.getInstance(document, fos);
document.open();
document.add(new Paragraph("This is SettingPdfAttributesExample.pdf"));
/**
* Now, we will set PDF file attributes
*/
//Add PDF Title and creation date
document.addTitle("SettingPdfAttributesExample");
document.addCreationDate(); //It will set current date as creation date.
//Add PDF author and creator
document.addAuthor("Ankit Mittal");
document.addCreator("JavaMadeSoEasy.com");
//PDF Subject and language
document.addSubject("How can you Set Pdf file Attributes using iText.");
document.addLanguage("");
//add PDF header
document.addHeader("1", "myPDF");
document.addKeywords("coreJava, pdf, itext");
document.close();
fos.close();
System.out.println("PDF created in >> "+ pdfFilePath);
} catch (Exception e) {
e.printStackTrace();
}
}
}
/* Output of above program
PDF created in >> e:/Setting Pdf Attributes Example.pdf
*/
|
PDF formed after executing above java program(Setting Pdf Attributes like Title, Author, Creator, subject, Keywords, Header and CreationDate in java) will look like this >
Go to Document properties >
Title, Author, Creator, subject, Keywords and CreationDate can be seen here >
PDF Header can be seen here -
Summary -
So in this core java tutorial we learned how to set Pdf Attributes like Title, Author, Creator, subject, Keywords, Header and CreationDate using iText library - core java tutorial in Java with program and example.
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
Creating TABLES in pdf in java - iText tutorial >
How to Create the Table In Pdf in java - iText java tutorial
How to do the Cell Alignment In Pdf generated table in Java program
How to Set Cell Background Colour In Pdf Table in java example
How to Set Cell Background Colour In Pdf Table in java - iText java tutorial
How to Create Images In Pdf generated Table in java itext
How to Create Nested Tables in Pdf in java - iText java tutorial
How to Create the Table With Multiple Rows In Pdf in java program
Creating the Table and set the Column Width And Spacing In Pdf in java
Rotate cells, cell padding, horizontal and vertical alignment of Cell in table in Pdf in java itext - iText java tutorial example
Creating LIST in pdf in java - iText tutorial >
Create Greek List In pdf in java using iText - iText java tutorial
How to Create Roman List In pdf in java - iText java tutorial
Create ZapfDingbats List In pdf in java - iText java tutorial program
How to Create Ordered List In pdf in java using iText - iText java tutorial
Creating the UnOrdered List In pdf in java - iText java tutorial example
How to Create Lists And SubLists In Pdf in java - iText java tutorial
Creating PASSWORD PROTECTED PDF in java - iText tutorial >
How to Create Password Protected Pdf in java - iText Example
Labels:
Core Java
iText Pdf tutorial