Document Properties are handled by the DocInfo object that is part of the Document object. All the Document Properties can be set or retrieved using the DocInfo object.
Attribute |
Description |
Type |
Values |
Default Value |
---|---|---|---|---|
Author |
Document author |
String |
NULL |
|
Creator |
Document creator |
String |
Amyuni PDF Creator |
|
Keywords |
Document keywords |
String |
NULL |
|
Producer *ReadOnly |
Document producer |
String |
Amyuni PDF Creator 6.5 |
|
Subject |
Document subject |
String |
NULL |
|
Title |
Document title |
String |
NULL |
|
CustomPropertiesList |
List of Custom Properties |
String Array |
NULL |
The AddAddtribute method allows to create a new custom property for the DocInfo Object using IacAttributeType.String type.
To delete an existing custom document info property, we simply set its text value to an empty string "".
Public Sub Sample()
' Constants for Activation codes
Const strLicenseTo As String = "Amyuni PDF Creator .NET Evaluation"
Const strActivationCode As String = "07EFCDAB0100010025C3B7B351579FF94C49112EAF7368612744C7237C2F6A215A53E83A9ECCFFE54C52063CB05338BDE555773D7B1B"
' initialize library
' This should be done once
acPDFCreatorLib.Initialize()
' set license key This is needed only with licensed version
acPDFCreatorLib.SetLicenseKey(strLicenseTo, strActivationCode)
' Create new stream object
Dim fileRead As System.IO.Stream = System.IO.File.OpenRead("C:\temp\PDFDocument.pdf")
' Create a new PDF document
Dim doc As New Amyuni.PDFCreator.IacDocument()
' Open PDF file
Dim password As String = ""
doc.Open(fileRead, password)
' Getting DocInfo object
Dim docInfo = doc.ObjectByName("DocInfo")
' enumerate any current custom properties that might be in the document
For Each customPropName As String in docInfo.Attribute("CustomPropertiesList").Value
if customPropName Is Nothing Then
Console.WriteLine("{0} = {1}", customPropName, docInfo.Attribute(customPropName).Value)
End if
Next
' get and then change value of an existing document info standard property that is not read-only
Console.WriteLine("Title = {0}", docInfo.Attribute("Title").Value) ' show current value
docInfo.Attribute("Title").Value = "New Doc Title" ' set new value
Console.WriteLine("Title = {0}", docInfo.Attribute("Title").Value) ' show new value
' Add a new custom document info property CustomPropABC
docInfo.AddAttribute("CustomPropABC", Amyuni.PDFCreator.IacAttributeType.String) ' create the new property entry
docInfo.Attribute("CustomPropABC").Value = "Some text ABC..." ' set the new property text value
Console.WriteLine("CustomPropABC = {0}", docInfo.Attribute("CustomPropABC").Value) ' show new value
' Add a new custom document info property CustomPropDEF
docInfo.AddAttribute("CustomPropDEF", Amyuni.PDFCreator.IacAttributeType.String) ' create the new property entry
docInfo.Attribute("CustomPropDEF").Value = "Some text DEF..." ' set the new property text value
Console.WriteLine("CustomPropDEF = {0}", docInfo.Attribute("CustomPropDEF").Value) ' show new value
' To delete an existing custom document info property, we simply set its text value to an empty string ""
docInfo.Attribute("CustomPropABC").Value = ""
' at this point the custom property is still present, we can still change its value to something other than an empty string
' but at the time of saving the document, if it has an empty string it will not be written to the PDF file
' Create new stream object
Dim fileWrite As System.IO.Stream = System.IO.File.OpenWrite("C:\temp\CreatePDFDocument_resulting.pdf")
' Save PDF file
doc.Save(fileWrite, Amyuni.PDFCreator.IacFileSaveOption.acFileSaveView)
' Close the stream
fileRead.Close()
fileWrite.Close()
' terminate library to free resources
acPDFCreatorLib.Terminate()
' destroy objects
doc.Dispose()
End Sub
public void Sample()
{
// Constants for Activation codes
const string strLicenseTo = "Amyuni PDF Creator .NET Evaluation";
const string strActivationCode = "07EFCDAB0100010025C3B7B351579FF94C49112EAF7368612744C7237C2F6A215A53E83A9ECCFFE54C52063CB05338BDE555773D7B1B";
// initailize library
// This should be done once
acPDFCreatorLib.Initialize();
// set license key This is needed only with licensed version
acPDFCreatorLib.SetLicenseKey(strLicenseTo, strActivationCode);
// Create new stream object
System.IO.FileStream fileRead = new System.IO.FileStream(@"C:\temp\PDFDocument.pdf",
System.IO.FileMode.Open,
System.IO.FileAccess.Read,
System.IO.FileShare.Read);
// Create a new PDF document
Amyuni.PDFCreator.IacDocument doc = new Amyuni.PDFCreator.IacDocument();
// Open PDF file
String password = "";
doc.Open(fileRead, password);
// Getting DocInfo object
Amyuni.PDFCreator.IacObject docInfo = doc.ObjectByName("DocInfo");
// enumerate any current custom properties that might be in the document
foreach (string customPropName in (object[])docInfo.Attribute("CustomPropertiesList").Value)
{
if (customPropName != null)
{
Console.WriteLine("{0} = {1}", customPropName, docInfo.Attribute(customPropName).Value);
}
}
// get and then change value of an existing document info standard property that is not read-only
Console.WriteLine("Title = {0}", docInfo.Attribute("Title").Value); // show current value
docInfo.Attribute("Title").Value = "New Doc Title"; // set new value
Console.WriteLine("Title = {0}", docInfo.Attribute("Title").Value); // show new value
// Add a new custom document info property CustomPropABC
docInfo.AddAttribute("CustomPropABC", Amyuni.PDFCreator.IacAttributeType.String); // create the new property entry
docInfo.Attribute("CustomPropABC").Value = "Some text ABC..."; // set the new property text value
Console.WriteLine("CustomPropABC = {0}", docInfo.Attribute("CustomPropABC").Value); // show new value
// Add a new custom document info property CustomPropDEF
docInfo.AddAttribute("CustomPropDEF", Amyuni.PDFCreator.IacAttributeType.String); // create the new property entry
docInfo.Attribute("CustomPropDEF").Value = "Some text DEF..."; // set the new property text value
Console.WriteLine("CustomPropDEF = {0}", docInfo.Attribute("CustomPropDEF").Value); // show new value
// To delete an existing custom document info property, we simply set its text value to an empty string ""
docInfo.Attribute("CustomPropABC").Value = "";
// at this point the custom property is still present, we can still change its value to something other than an empty string
// but at the time of saving the document, if it has an empty string it will not be written to the PDF file
// Create new stream object
System.IO.FileStream fileWrite = new System.IO.FileStream(@"C:\temp\CreatePDFDocument_resulting.pdf",
System.IO.FileMode.Create,
System.IO.FileAccess.Write,
System.IO.FileShare.Read);
// Save PDF File
doc.Save(fileWrite, Amyuni.PDFCreator.IacFileSaveOption.acFileSaveView);
// Close the stream
fileRead.Close();
fileWrite.Close();
// terminate library to free resources
acPDFCreatorLib.Terminate();
// destroy objects
doc.Dispose();
}