Every PDF document has some Meta Information like Title, Author Name, Creation Date etc. Aspose.Pdf.Kit (Java Version ) allows developers to control this meta information.
To change meta information of the PDF documents, we use PdfFileInfo (Java Version ) class by calling its constructor that takes the input PDF file name as string argument. Then developers can modify the meta information through properties ( Title (Java Version ) Author (Java Version ) CreationDate (Java Version ) Creator (Java Version ) Keywords (Java Version ) ModDate (Java Version ) Producer (Java Version ) Header (Java Version ) NumberOfPages (Java Version ) and Subject (Java Version ) ) of PdfFileInfo (Java Version ) class.
Once the meta information is modified, don't forget to call SaveNewInfo (saveNewInfo in Java Version ) method to save the changes to meta information of PDF document.
Code Snippet
[C#]
//Variable to hold input PDF file name and path
string inFile = ".\\example.pdf";
//Variable to hold output PDF file name and path
string outFile = ".\\output.pdf";
//Instantiating PdfFileInfo object and passing input PDF file to its constructor
PdfFileInfo fileInfo = new PdfFileInfo(inFile);
//Instantiating a Hashtable object
System.Collections.Hashtable additionalInfo = new System.Collections.Hashtable();
//Adding comment in Hashtable object used as header of PDF document
additionalInfo.Add("Comment","terrorism challenges the peace of world.");
//Change the Title of the input PDF file
fileInfo.Title = "Hello World!";
//Change the Author of the input PDF file
fileInfo.Author = "William";
//Change the Creator of the input PDF file
fileInfo.Creator = "Aspose";
//Change the Keywords of the input PDF file
fileInfo.Keywords = "peace and development";
//Change the Header of the input PDF file by assigning the above Hashtable object
fileInfo.Header = additionalInfo;
//Call SaveNewInfo method to change the properties specified explicitly
fileInfo.SaveNewInfo(outFile);
[VB.NET]
'Variable to hold input PDF file name and path
Dim inFile As String = ".\\example1.pdf"
'Variable to hold output PDF file name and path
Dim outFile As String = ".\\output.pdf"
'Instantiating PdfFileInfo object and passing input PDF file to its constructor
Dim fileInfo As PdfFileInfo = New PdfFileInfo(inFile)
'Instantiating a Hashtable object
Dim additionalInfo As System.Collections.Hashtable = New System.Collections.Hashtable()
'Adding comment in Hashtable object used as header of PDF document
additionalInfo.Add("Comment","terrorism challenges the peace of world.")
'Change the Title of the input PDF file
fileInfo.Title = "Hello World!"
'Change the Author of the input PDF file
fileInfo.Author = "William"
'Change the Creator of the input PDF file
fileInfo.Creator = "Aspose"
'Change the Keywords of the input PDF file
fileInfo.Keywords = "peace and development"
'Change the Header of the input PDF file by assigning the above Hashtable object
fileInfo.Header = additionalInfo
'Call SaveNewInfo method to change the properties specified explicitly
fileInfo.SaveNewInfo(outFile)
[Java]
String path = "./examples/resources/";
String inFile = path + "example1.pdf";
String outFile = path + "PdfInfoOut1.pdf";
HashMap header = new HashMap();
header.put("Zone", "+800");
PdfFileInfo fileInfo = null;
fileInfo = new PdfFileInfo(inFile);
fileInfo.setAuthor("William");
fileInfo.setTitle("Hello");
fileInfo.setSubject("Peace");
fileInfo.setKeywords("A,B");
fileInfo.setHeader(null);
fileInfo.saveNewInfo(outFile);