Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(VBScript) PDF Update or Add XML MetadataDemonstrates how to add or update the XML metadata stored in a PDF. Note: This example requires Chilkat v10.1.0 or later.
Dim fso, outFile Set fso = CreateObject("Scripting.FileSystemObject") 'Create a Unicode (utf-16) output text file. Set outFile = fso.CreateTextFile("output.txt", True, True) ' This requires the Chilkat API to have been previously unlocked. ' See Global Unlock Sample for sample code. ' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.Pdf") set pdf = CreateObject("Chilkat.Pdf") ' Load a PDF file. ' If the PDF file already has metadata, we'll update it. ' Otherwise this example adds the metadata. success = pdf.LoadFile("qa_data/pdf/blank_with_metadata.pdf") If (success = 0) Then outFile.WriteLine(pdf.LastErrorText) WScript.Quit End If ' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.Xml") set xml = CreateObject("Chilkat.Xml") ' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.StringBuilder") set sbExisting = CreateObject("Chilkat.StringBuilder") hasMetadata = pdf.GetMetadata(sbExisting) If (hasMetadata = 1) Then success = xml.LoadSb(sbExisting,1) Else ' Otherwise create the bare minimum XMP metadata. xml.Tag = "x:xmpmeta" success = xml.AddAttribute("xmlns:x","adobe:ns:meta/") success = xml.AddAttribute("x:xmptk","Adobe XMP Core 9.1-c001 79.675d0f7, 2023/06/11-19:21:16 ") success = xml.UpdateAttrAt("rdf:RDF",1,"xmlns:rdf","http://www.w3.org/1999/02/22-rdf-syntax-ns#") success = xml.UpdateAttrAt("rdf:RDF|rdf:Description",1,"rdf:about","") success = xml.UpdateAttrAt("rdf:RDF|rdf:Description",1,"xmlns:xmp","http://ns.adobe.com/xap/1.0/") success = xml.UpdateAttrAt("rdf:RDF|rdf:Description",1,"xmlns:dc","http://purl.org/dc/elements/1.1/") success = xml.UpdateAttrAt("rdf:RDF|rdf:Description",1,"xmlns:xmpMM","http://ns.adobe.com/xap/1.0/mm/") success = xml.UpdateAttrAt("rdf:RDF|rdf:Description",1,"xmlns:pdf","http://ns.adobe.com/pdf/1.3/") success = xml.UpdateAttrAt("rdf:RDF|rdf:Description",1,"xmlns:xmpRights","http://ns.adobe.com/xap/1.0/rights/") ' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.CkDateTime") set dt = CreateObject("Chilkat.CkDateTime") success = dt.SetFromCurrentSystemTime() ts = dt.GetAsTimestamp(1) 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" ' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.StringBuilder") set sbDocId = CreateObject("Chilkat.StringBuilder") success = sbDocId.Append("uuid:") success = sbDocId.AppendUuid(1) xml.UpdateChildContent "rdf:RDF|rdf:Description|xmpMM:DocumentID",sbDocId.GetAsString() ' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.StringBuilder") set sbInstanceId = CreateObject("Chilkat.StringBuilder") success = sbInstanceId.Append("uuid:") success = sbInstanceId.AppendUuid(1) 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. success = xml.UpdateAttrAt("rdf:RDF|rdf:Description",1,"xmlns:zf","urn:ferd:pdfa:CrossIndustryDocument:invoice:1p0#") success = xml.UpdateAttrAt("rdf:RDF|rdf:Description",1,"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. ' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.StringBuilder") set sb = CreateObject("Chilkat.StringBuilder") success = xml.GetXmlSb(sb) success = pdf.UpdateMetadata(sb,"c:/temp/qa_output/out.pdf") If (success = 1) Then outFile.WriteLine("Success") Else outFile.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. outFile.WriteLine("OK") outFile.Close |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.