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 "".
Sub Sample()
' Constants for Activation codes
Const strLicenseTo As String = "Amyuni PDF Creator Evaluation"
Const strActivationCode As String =
"07EFCDAB010001004282943F2AF19A88F332D9E781E40460727DF8A42847A1BDE06DB61C71E94E2D90424BF8762385335F9D6884E9FC"
' Initializing PDFCreativeX Object
Dim pdf As ACPDFCREACTIVEX.PDFCreactiveX = New ACPDFCREACTIVEX.PDFCreactiveX()
' Set license key
pdf.SetLicenseKey(strLicenseTo, strActivationCode)
' Open an existent PDF file
Dim fileName As String = "c:\temp\PDFdocument.pdf"
Dim password As String = ""
pdf.Open(fileName, password)
' Set CurrentPage
pdf.CurrentPage = 1
' Getting DocInfo object
Dim docInfo = pdf.GetObjectByName("DocInfo")
' enumerate any current custom properties that might be in the document
For Each customPropName As String in docInfo.Attribute("CustomPropertiesList")
if customPropName Is Nothing Then
Console.WriteLine("{0} = {1}", customPropName, docInfo.Attribute(customPropName))
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")) ' show current value
docInfo.Attribute("Title") = "New Doc Title" ' set new value
Console.WriteLine("Title = {0}", docInfo.Attribute("Title")) ' show new value
' Add a new custom document info property CustomPropABC
docInfo.AddAttribute("CustomPropABC", 14) ' create the new property entry
docInfo.Attribute("CustomPropABC") = "Some text ABC..." ' set the new property text value
Console.WriteLine("CustomPropABC = {0}", docInfo.Attribute("CustomPropABC")) ' show new value
' Add a new custom document info property CustomPropDEF
docInfo.AddAttribute("CustomPropDEF", 14) ' create the new property entry
docInfo.Attribute("CustomPropDEF") = "Some text DEF..." ' set the new property text value
Console.WriteLine("CustomPropDEF = {0}", docInfo.Attribute("CustomPropDEF")) ' show new value
' To delete an existing custom document info property, we simply set its text value to an empty string ""
docInfo.Attribute("CustomPropABC") = ""
' 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
' Save PDF
pdf.Save("c:\temp\CreatePDFDocument_resulting.pdf", ACPDFCREACTIVEX.FileSaveOptionConstants.acFileSaveView)
End Sub
static void Sample()
{
// Constants for Activation codes
const string strLicenseTo = "Amyuni PDF Creator Evaluation";
const string strActivationCode = "07EFCDAB010001004282943F2AF19A88F332D9E781E40460727DF8A42847A1BDE06DB61C71E94E2D90424BF8762385335F9D6884E9FC";
// Initializing PDFCreativeX Object
ACPDFCREACTIVEX.PDFCreactiveX pdf = new ACPDFCREACTIVEX.PDFCreactiveX();
// Set license key
pdf.SetLicenseKey(strLicenseTo, strActivationCode);
// Open an existent PDF file
string fileName = @"c:\temp\PDFdocument.pdf";
string password = "";
pdf.Open(fileName, password);
// Getting DocInfo object
ACPDFCREACTIVEX.IacObject docInfo = pdf.GetObjectByName("DocInfo");
// enumerate any current custom properties that might be in the document
foreach (string customPropName in (object[]) docInfo["CustomPropertiesList"])
{
if (customPropName != null)
{
Console.WriteLine("{0} = {1}", customPropName, docInfo[customPropName]);
}
}
// get and then change value of an existing document info standard property that is not read-only
Console.WriteLine("Title = {0}", docInfo["Title"]); // show current value
docInfo["Title"] = "New Doc Title"; // set new value
Console.WriteLine("Title = {0}", docInfo["Title"]); // show new value
// Add a new custom document info property CustomPropABC
docInfo.AddAttribute("CustomPropABC",14); // create the new property entry
docInfo["CustomPropABC"] = "Some text ABC..."; // set the new property text value
Console.WriteLine("CustomPropABC = {0}", docInfo["CustomPropABC"]); // show new value
// Add a new custom document info property CustomPropDEF
docInfo.AddAttribute("CustomPropDEF", 14); // create the new property entry
docInfo["CustomPropDEF"] = "Some text DEF..."; // set the new property text value
Console.WriteLine("CustomPropDEF = {0}", docInfo["CustomPropDEF"]); // show new value
// To delete an existing custom document info property, we simply set its text value to an empty string ""
docInfo["CustomPropABC"] = "";
// 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
// Save PDF
pdf.Save(@"c:\temp\CreatePDFDocument_resulting.pdf", ACPDFCREACTIVEX.FileSaveOptionConstants.acFileSaveView);
}
#include <iostream>
#import "c:\users\amyuni\pdfcreactivex.dll" no_namespace
using namespace std;
int main()
{
// OptimizeDocument level Values
const int NO_OPTIMIZATION = 0;
const int LINE_OPTIMIZATION = 1;
const int PARAGRAPH_OPTIMIZATION = 2;
const int TABLE_OPTIMIZATION = 3;
// Constants for Activation codes
bstr_t strLicenseTo = "Amyuni PDF Creator Evaluation";
bstr_t strActivationCode =
"07EFCDAB010001004282943F2AF19A88F332D9E781E40460727DF8A42847A1BDE06DB61C71E94E2D90424BF8762385335F9D6884E9FC";
// Initialize the COM subsystem
CoInitialize(0);
// IPDFCreactiveXPtr is a smart pointer type defined in pdfcreactivex.tlh,
// the type library header file generated by the #import instruction above
IPDFCreactiveXPtr pdf;
// Create the PDFCreactiveX instance
pdf.CreateInstance(__uuidof(PDFCreactiveX));
// set license key
pdf->SetLicenseKey(_bstr_t(strLicenseTo), _bstr_t(strActivationCode));
// Open an existent PDF file
_bstr_t fileName = "c:\\temp\\PDFdocument.pdf";
_bstr_t password = "";
pdf->Open(fileName, password);
// Using Document Object
IacObjectPtr docInfo = pdf->GetObjectByName("DocInfo");
// DocInfo Object
auto customPropertiesList = docInfo->GetAttribute("CustomPropertiesList");
SAFEARRAY* psa = customPropertiesList.parray;
long lowerBound, upperBound;
SafeArrayGetLBound(psa, 1, &lowerBound);
SafeArrayGetUBound(psa, 1, &upperBound);
long cnt_elements = upperBound - lowerBound + 1;
for (long i = 0; i < cnt_elements; i++)
{
BSTR customPropName;
SafeArrayGetElement(psa, &i, &customPropName);
if (customPropName != nullptr)
{
cout << _bstr_t(customPropName) << endl;
cout << _bstr_t(docInfo->GetAttribute(customPropName)) << endl;
}
}
SafeArrayUnlock(psa);
// get and then change value of an existing document info standard property that is not read-only
cout << _bstr_t("Title = ") << _bstr_t(docInfo->GetAttribute("Title")) << endl; // show current value
docInfo->put_Attribute(_bstr_t("Title"), _variant_t("New Doc Title"));
cout << _bstr_t("Title = ") << _bstr_t(docInfo->GetAttribute("Title")) << endl; // show new value
// Add a new custom document info property CustomPropABC
docInfo->AddAttribute("CustomPropABC",14); // create the new property entry
docInfo->put_Attribute(_bstr_t("CustomPropABC"), _variant_t("Some text ABC...")); // set the new property text value
cout << _bstr_t("CustomPropABC = ") << _bstr_t(docInfo->GetAttribute("CustomPropABC")) << endl; // show new value
// Add a new custom document info property CustomPropDEF
docInfo->AddAttribute("CustomPropDEF",14); // create the new property entry
docInfo->put_Attribute(_bstr_t("CustomPropDEF"), _variant_t("Some text DEF...")); // set the new property text value
cout << _bstr_t("CustomPropDEF = ") << _bstr_t(docInfo->GetAttribute("CustomPropDEF")) << endl; // show new value
// To delete an existing custom document info property, we simply set its text value to an empty string ""
docInfo->put_Attribute(_bstr_t("CustomPropABC"), _variant_t(""));
// 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
// Save PDF
pdf->Save("c:\\temp\\CreatePDFDocument_resulting.pdf", acFileSaveView);
// destroy Objects
pdf = nullptr;
docInfo = nullptr;
return 0;
}