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

VB.NET 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

 

 

 

(VB.NET) 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 .NET Downloads

Chilkat .NET Framework

Chilkat for .NET Core

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

Dim pdf As New Chilkat.Pdf

' Load a PDF file.
' If the PDF file already has metadata, we'll update it.
' Otherwise this example adds the metadata.
Dim success As Boolean = pdf.LoadFile("qa_data/pdf/blank_with_metadata.pdf")
If (success = False) Then
    Debug.WriteLine(pdf.LastErrorText)
    Exit Sub
End If


Dim xml As New Chilkat.Xml
Dim sbExisting As New Chilkat.StringBuilder

Dim hasMetadata As Boolean = pdf.GetMetadata(sbExisting)
If (hasMetadata = True) Then
    xml.LoadSb(sbExisting,True)
Else

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

    Dim dt As New Chilkat.CkDateTime
    dt.SetFromCurrentSystemTime()
    Dim ts As String = dt.GetAsTimestamp(True)

    xml.UpdateChildContent("rdf:RDF|rdf:Description|xmp:ModifyDate",ts)
    xml.UpdateChildContent("rdf:RDF|rdf:Description|xmp:CreateDate",ts)
    xml.UpdateChildContent("rdf:RDF|rdf:Description|xmp:MetadataDate",ts)

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

    Dim sbDocId As New Chilkat.StringBuilder
    sbDocId.Append("uuid:")
    sbDocId.AppendUuid(True)
    xml.UpdateChildContent("rdf:RDF|rdf:Description|xmpMM:DocumentID",sbDocId.GetAsString())

    Dim sbInstanceId As New Chilkat.StringBuilder
    sbInstanceId.Append("uuid:")
    sbInstanceId.AppendUuid(True)
    xml.UpdateChildContent("rdf:RDF|rdf:Description|xmpMM:InstanceID",sbInstanceId.GetAsString())

End If


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

' Create a new PDF with the updated metadata.
Dim sb As New Chilkat.StringBuilder
xml.GetXmlSb(sb)
success = pdf.UpdateMetadata(sb,"c:/temp/qa_output/out.pdf")
If (success = True) Then
    Debug.WriteLine("Success")
Else
    Debug.WriteLine(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.


Debug.WriteLine("OK")

 

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