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
(Visual FoxPro) 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.
LOCAL loPdf LOCAL lnSuccess LOCAL loXml LOCAL loSbExisting LOCAL lnHasMetadata LOCAL loDt LOCAL lcTs LOCAL loSbDocId LOCAL loSbInstanceId LOCAL loSb * 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') loPdf = CreateObject('Chilkat.Pdf') * Load a PDF file. * If the PDF file already has metadata, we'll update it. * Otherwise this example adds the metadata. lnSuccess = loPdf.LoadFile("qa_data/pdf/blank_with_metadata.pdf") IF (lnSuccess = 0) THEN ? loPdf.LastErrorText RELEASE loPdf CANCEL ENDIF * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Xml') loXml = CreateObject('Chilkat.Xml') * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder') loSbExisting = CreateObject('Chilkat.StringBuilder') lnHasMetadata = loPdf.GetMetadata(loSbExisting) IF (lnHasMetadata = 1) THEN loXml.LoadSb(loSbExisting,1) ELSE * Otherwise create the bare minimum XMP metadata. loXml.Tag = "x:xmpmeta" loXml.AddAttribute("xmlns:x","adobe:ns:meta/") loXml.AddAttribute("x:xmptk","Adobe XMP Core 9.1-c001 79.675d0f7, 2023/06/11-19:21:16 ") loXml.UpdateAttrAt("rdf:RDF",1,"xmlns:rdf","http://www.w3.org/1999/02/22-rdf-syntax-ns#") loXml.UpdateAttrAt("rdf:RDF|rdf:Description",1,"rdf:about","") loXml.UpdateAttrAt("rdf:RDF|rdf:Description",1,"xmlns:xmp","http://ns.adobe.com/xap/1.0/") loXml.UpdateAttrAt("rdf:RDF|rdf:Description",1,"xmlns:dc","http://purl.org/dc/elements/1.1/") loXml.UpdateAttrAt("rdf:RDF|rdf:Description",1,"xmlns:xmpMM","http://ns.adobe.com/xap/1.0/mm/") loXml.UpdateAttrAt("rdf:RDF|rdf:Description",1,"xmlns:pdf","http://ns.adobe.com/pdf/1.3/") loXml.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') loDt = CreateObject('Chilkat.CkDateTime') loDt.SetFromCurrentSystemTime() lcTs = loDt.GetAsTimestamp(1) loXml.UpdateChildContent("rdf:RDF|rdf:Description|xmp:ModifyDate",lcTs) loXml.UpdateChildContent("rdf:RDF|rdf:Description|xmp:CreateDate",lcTs) loXml.UpdateChildContent("rdf:RDF|rdf:Description|xmp:MetadataDate",lcTs) loXml.UpdateChildContent("rdf:RDF|rdf:Description|xmp:CreatorTool","My Custom Application") loXml.UpdateChildContent("rdf:RDF|rdf:Description|dc:format","application/pdf") * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder') loSbDocId = CreateObject('Chilkat.StringBuilder') loSbDocId.Append("uuid:") loSbDocId.AppendUuid(1) loXml.UpdateChildContent("rdf:RDF|rdf:Description|xmpMM:DocumentID",loSbDocId.GetAsString()) * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder') loSbInstanceId = CreateObject('Chilkat.StringBuilder') loSbInstanceId.Append("uuid:") loSbInstanceId.AppendUuid(1) loXml.UpdateChildContent("rdf:RDF|rdf:Description|xmpMM:InstanceID",loSbInstanceId.GetAsString()) ENDIF * Add our custom metadata tags to either the existing XML metdata, or the newly created metadata. loXml.UpdateAttrAt("rdf:RDF|rdf:Description",1,"xmlns:zf","urn:ferd:pdfa:CrossIndustryDocument:invoice:1p0#") loXml.UpdateAttrAt("rdf:RDF|rdf:Description",1,"rdf:about"," ") loXml.UpdateChildContent("rdf:RDF|rdf:Description|zf:ConformanceLevel","BASIC") loXml.UpdateChildContent("rdf:RDF|rdf:Description|zf:DocumentFileName","ZZZZZZ-invoice.xml") loXml.UpdateChildContent("rdf:RDF|rdf:Description|zf:DocumentType","INVOICE") loXml.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') loSb = CreateObject('Chilkat.StringBuilder') loXml.GetXmlSb(loSb) lnSuccess = loPdf.UpdateMetadata(loSb,"c:/temp/qa_output/out.pdf") IF (lnSuccess = 1) THEN ? "Success" ELSE ? loPdf.LastErrorText ENDIF * 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. ? "OK" RELEASE loPdf RELEASE loXml RELEASE loSbExisting RELEASE loDt RELEASE loSbDocId RELEASE loSbInstanceId RELEASE loSb |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.