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
(PowerBuilder) 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.
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.