Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

PowerBuilder Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(PowerBuilder) PDF Update or Add XML Metadata

Demonstrates how to add or update the XML metadata stored in a PDF.

Note: This example requires Chilkat v10.1.0 or later.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
oleobject loo_Pdf
integer li_Success
oleobject loo_Xml
oleobject loo_SbExisting
integer li_HasMetadata
oleobject loo_Dt
string ls_Ts
oleobject loo_SbDocId
oleobject loo_SbInstanceId
oleobject loo_Sb

// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loo_Pdf = create oleobject
// Use "Chilkat_9_5_0.Pdf" for versions of Chilkat < 10.0.0
li_rc = loo_Pdf.ConnectToNewObject("Chilkat.Pdf")
if li_rc < 0 then
    destroy loo_Pdf
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// Load a PDF file.
// If the PDF file already has metadata, we'll update it.
// Otherwise this example adds the metadata.
li_Success = loo_Pdf.LoadFile("qa_data/pdf/blank_with_metadata.pdf")
if li_Success = 0 then
    Write-Debug loo_Pdf.LastErrorText
    destroy loo_Pdf
    return
end if

loo_Xml = create oleobject
// Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0
li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml")

loo_SbExisting = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbExisting.ConnectToNewObject("Chilkat.StringBuilder")

li_HasMetadata = loo_Pdf.GetMetadata(loo_SbExisting)
if li_HasMetadata = 1 then
    loo_Xml.LoadSb(loo_SbExisting,1)
else

    // Otherwise create the bare minimum XMP metadata.
    loo_Xml.Tag = "x:xmpmeta"
    loo_Xml.AddAttribute("xmlns:x","adobe:ns:meta/")
    loo_Xml.AddAttribute("x:xmptk","Adobe XMP Core 9.1-c001 79.675d0f7, 2023/06/11-19:21:16 ")
    loo_Xml.UpdateAttrAt("rdf:RDF",1,"xmlns:rdf","http://www.w3.org/1999/02/22-rdf-syntax-ns#")
    loo_Xml.UpdateAttrAt("rdf:RDF|rdf:Description",1,"rdf:about","")
    loo_Xml.UpdateAttrAt("rdf:RDF|rdf:Description",1,"xmlns:xmp","http://ns.adobe.com/xap/1.0/")
    loo_Xml.UpdateAttrAt("rdf:RDF|rdf:Description",1,"xmlns:dc","http://purl.org/dc/elements/1.1/")
    loo_Xml.UpdateAttrAt("rdf:RDF|rdf:Description",1,"xmlns:xmpMM","http://ns.adobe.com/xap/1.0/mm/")
    loo_Xml.UpdateAttrAt("rdf:RDF|rdf:Description",1,"xmlns:pdf","http://ns.adobe.com/pdf/1.3/")
    loo_Xml.UpdateAttrAt("rdf:RDF|rdf:Description",1,"xmlns:xmpRights","http://ns.adobe.com/xap/1.0/rights/")

    loo_Dt = create oleobject
    // Use "Chilkat_9_5_0.CkDateTime" for versions of Chilkat < 10.0.0
    li_rc = loo_Dt.ConnectToNewObject("Chilkat.CkDateTime")

    loo_Dt.SetFromCurrentSystemTime()
    ls_Ts = loo_Dt.GetAsTimestamp(1)

    loo_Xml.UpdateChildContent("rdf:RDF|rdf:Description|xmp:ModifyDate",ls_Ts)
    loo_Xml.UpdateChildContent("rdf:RDF|rdf:Description|xmp:CreateDate",ls_Ts)
    loo_Xml.UpdateChildContent("rdf:RDF|rdf:Description|xmp:MetadataDate",ls_Ts)

    loo_Xml.UpdateChildContent("rdf:RDF|rdf:Description|xmp:CreatorTool","My Custom Application")
    loo_Xml.UpdateChildContent("rdf:RDF|rdf:Description|dc:format","application/pdf")

    loo_SbDocId = create oleobject
    // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
    li_rc = loo_SbDocId.ConnectToNewObject("Chilkat.StringBuilder")

    loo_SbDocId.Append("uuid:")
    loo_SbDocId.AppendUuid(1)
    loo_Xml.UpdateChildContent("rdf:RDF|rdf:Description|xmpMM:DocumentID",loo_SbDocId.GetAsString())

    loo_SbInstanceId = create oleobject
    // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
    li_rc = loo_SbInstanceId.ConnectToNewObject("Chilkat.StringBuilder")

    loo_SbInstanceId.Append("uuid:")
    loo_SbInstanceId.AppendUuid(1)
    loo_Xml.UpdateChildContent("rdf:RDF|rdf:Description|xmpMM:InstanceID",loo_SbInstanceId.GetAsString())

end if

// Add our custom metadata tags to either the existing XML metdata, or the newly created metadata.
loo_Xml.UpdateAttrAt("rdf:RDF|rdf:Description",1,"xmlns:zf","urn:ferd:pdfa:CrossIndustryDocument:invoice:1p0#")
loo_Xml.UpdateAttrAt("rdf:RDF|rdf:Description",1,"rdf:about"," ")
loo_Xml.UpdateChildContent("rdf:RDF|rdf:Description|zf:ConformanceLevel","BASIC")
loo_Xml.UpdateChildContent("rdf:RDF|rdf:Description|zf:DocumentFileName","ZZZZZZ-invoice.xml")
loo_Xml.UpdateChildContent("rdf:RDF|rdf:Description|zf:DocumentType","INVOICE")
loo_Xml.UpdateChildContent("rdf:RDF|rdf:Description|zf:Version","1.0")

// Create a new PDF with the updated metadata.
loo_Sb = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_Sb.ConnectToNewObject("Chilkat.StringBuilder")

loo_Xml.GetXmlSb(loo_Sb)
li_Success = loo_Pdf.UpdateMetadata(loo_Sb,"c:/temp/qa_output/out.pdf")
if li_Success = 1 then
    Write-Debug "Success"
else
    Write-Debug loo_Pdf.LastErrorText
end if

// To see the metadata in Adobe Acrobat DC,
// 1) Open the PDF.
// 2) CTRL-D to show the Document Properties dialog.
// 3) In the dialog, click on the "Additional Metadata" button.
// 4) In the Additional Data dialog, click on "Advanced"
// 5) Expand the namespace tree for the metadata you added.

Write-Debug "OK"


destroy loo_Pdf
destroy loo_Xml
destroy loo_SbExisting
destroy loo_Dt
destroy loo_SbDocId
destroy loo_SbInstanceId
destroy loo_Sb

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.