Sample code for 30+ languages & platforms
PowerBuilder

Extract Metadata XML from PDF

See more PDF Signatures Examples

Demonstrates how to extract the metadata XML from a PDF.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Pdf
oleobject loo_SbXml
oleobject loo_Xml
string ls_X_xmpmeta_xmlns_x
string ls_X_xmpmeta_x_xmptk
string ls_Rdf_RDF_xmlns_rdf
string ls_Rdf_Description_rdf_about
string ls_Rdf_Description_xmlns_xmp
string ls_Rdf_Description_xmlns_dc
string ls_Rdf_Description_xmlns_xmpMM
string ls_Rdf_Description_xmlns_pdf
string ls_Rdf_Description_xmlns_xmpRights
string ls_Xmp_ModifyDate
string ls_Xmp_CreateDate
string ls_Xmp_MetadataDate
string ls_Xmp_CreatorTool
string ls_Dc_format
string ls_Rdf_li_xml_lang
string ls_Rdf_li
integer i
integer li_Count_i
string ls_XmpMM_DocumentID
string ls_XmpMM_InstanceID
string ls_Pdf_Producer
string ls_Pdf_Keywords
string ls_XmpRights_WebStatement

li_Success = 0

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

loo_Pdf = create oleobject
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

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_SbXml = create oleobject
li_rc = loo_SbXml.ConnectToNewObject("Chilkat.StringBuilder")

// Note: Not all PDF files have metadata.  Metadata is optional.
li_Success = loo_Pdf.GetMetadata(loo_SbXml)
if li_Success = 0 then
    Write-Debug loo_Pdf.LastErrorText
    destroy loo_Pdf
    destroy loo_SbXml
    return
end if

loo_Xml = create oleobject
li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml")

loo_Xml.LoadSb(loo_SbXml,1)

Write-Debug loo_Xml.GetXml()

// Sample PDF metadata XML:
// (Code for parsing follows)

// Use this online tool to generate parsing code from sample XML: 
// Generate Parsing Code from XML

// <?xml version="1.0" encoding="utf-8"?>
// <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 9.1-c001 79.675d0f7, 2023/06/11-19:21:16        ">
//     <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
//         <rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/" xmlns:pdf="http://ns.adobe.com/pdf/1.3/" xmlns:xmpRights="http://ns.adobe.com/xap/1.0/rights/">
//             <xmp:ModifyDate>2024-11-27T11:33:12-06:00</xmp:ModifyDate>
//             <xmp:CreateDate>2024-11-27T11:28:23-06:00</xmp:CreateDate>
//             <xmp:MetadataDate>2024-11-27T11:33:12-06:00</xmp:MetadataDate>
//             <xmp:CreatorTool>Adobe Acrobat Pro (32-bit) 24.3.20112</xmp:CreatorTool>
//             <dc:format>application/pdf</dc:format>
//             <dc:title>
//                 <rdf:Alt>
//                     <rdf:li xml:lang="x-default">Blank</rdf:li>
//                 </rdf:Alt>
//             </dc:title>
//             <dc:creator>
//                 <rdf:Bag>
//                     <rdf:li>Chilkat Software</rdf:li>
//                 </rdf:Bag>
//             </dc:creator>
//             <dc:description>
//                 <rdf:Alt>
//                     <rdf:li xml:lang="x-default">Blank Document</rdf:li>
//                 </rdf:Alt>
//             </dc:description>
//             <dc:subject>
//                 <rdf:Bag>
//                     <rdf:li>blank</rdf:li>
//                     <rdf:li>metadata</rdf:li>
//                     <rdf:li>document</rdf:li>
//                 </rdf:Bag>
//             </dc:subject>
//             <xmpMM:DocumentID>uuid:34535ffa-b632-43f1-b1fd-80cea6fdc351</xmpMM:DocumentID>
//             <xmpMM:InstanceID>uuid:69ace620-4c54-407f-8d45-6eebc90f34c2</xmpMM:InstanceID>
//             <pdf:Producer>Adobe Acrobat Pro (32-bit) 24.3.20112</pdf:Producer>
//             <pdf:Keywords>blank; metadata; document</pdf:Keywords>
//             <xmpRights:WebStatement>https://www.chilkatsoft.com/</xmpRights:WebStatement>
//         </rdf:Description>
//     </rdf:RDF>
// </x:xmpmeta>

ls_X_xmpmeta_xmlns_x = loo_Xml.GetAttrValue("xmlns:x")
ls_X_xmpmeta_x_xmptk = loo_Xml.GetAttrValue("x:xmptk")
ls_Rdf_RDF_xmlns_rdf = loo_Xml.ChilkatPath("rdf:RDF|(xmlns:rdf)")
ls_Rdf_Description_rdf_about = loo_Xml.ChilkatPath("rdf:RDF|rdf:Description|(rdf:about)")
ls_Rdf_Description_xmlns_xmp = loo_Xml.ChilkatPath("rdf:RDF|rdf:Description|(xmlns:xmp)")
ls_Rdf_Description_xmlns_dc = loo_Xml.ChilkatPath("rdf:RDF|rdf:Description|(xmlns:dc)")
ls_Rdf_Description_xmlns_xmpMM = loo_Xml.ChilkatPath("rdf:RDF|rdf:Description|(xmlns:xmpMM)")
ls_Rdf_Description_xmlns_pdf = loo_Xml.ChilkatPath("rdf:RDF|rdf:Description|(xmlns:pdf)")
ls_Rdf_Description_xmlns_xmpRights = loo_Xml.ChilkatPath("rdf:RDF|rdf:Description|(xmlns:xmpRights)")
ls_Xmp_ModifyDate = loo_Xml.GetChildContent("rdf:RDF|rdf:Description|xmp:ModifyDate")
ls_Xmp_CreateDate = loo_Xml.GetChildContent("rdf:RDF|rdf:Description|xmp:CreateDate")
ls_Xmp_MetadataDate = loo_Xml.GetChildContent("rdf:RDF|rdf:Description|xmp:MetadataDate")
ls_Xmp_CreatorTool = loo_Xml.GetChildContent("rdf:RDF|rdf:Description|xmp:CreatorTool")
ls_Dc_format = loo_Xml.GetChildContent("rdf:RDF|rdf:Description|dc:format")
ls_Rdf_li_xml_lang = loo_Xml.ChilkatPath("rdf:RDF|rdf:Description|dc:title|rdf:Alt|rdf:li|(xml:lang)")
ls_Rdf_li = loo_Xml.GetChildContent("rdf:RDF|rdf:Description|dc:title|rdf:Alt|rdf:li")
ls_Rdf_li = loo_Xml.GetChildContent("rdf:RDF|rdf:Description|dc:creator|rdf:Bag|rdf:li")
ls_Rdf_li_xml_lang = loo_Xml.ChilkatPath("rdf:RDF|rdf:Description|dc:description|rdf:Alt|rdf:li|(xml:lang)")
ls_Rdf_li = loo_Xml.GetChildContent("rdf:RDF|rdf:Description|dc:description|rdf:Alt|rdf:li")
i = 0
li_Count_i = loo_Xml.NumChildrenHavingTag("rdf:RDF|rdf:Description|dc:subject|rdf:Bag|rdf:li")
do while i < li_Count_i
    loo_Xml.I = i
    ls_Rdf_li = loo_Xml.GetChildContent("rdf:RDF|rdf:Description|dc:subject|rdf:Bag|rdf:li[i]")
    i = i + 1
loop
ls_XmpMM_DocumentID = loo_Xml.GetChildContent("rdf:RDF|rdf:Description|xmpMM:DocumentID")
ls_XmpMM_InstanceID = loo_Xml.GetChildContent("rdf:RDF|rdf:Description|xmpMM:InstanceID")
ls_Pdf_Producer = loo_Xml.GetChildContent("rdf:RDF|rdf:Description|pdf:Producer")
ls_Pdf_Keywords = loo_Xml.GetChildContent("rdf:RDF|rdf:Description|pdf:Keywords")
ls_XmpRights_WebStatement = loo_Xml.GetChildContent("rdf:RDF|rdf:Description|xmpRights:WebStatement")


destroy loo_Pdf
destroy loo_SbXml
destroy loo_Xml