Cannot get XMP metadata for PDF version 1.5 via Powershell
Copy link to clipboard
Copied
I am trying to get XMP metadata from pdf via Powershell, which i am able to get from some docs and not from some.
The only difference is the version .ie 1.6 for which i can get the XMP metadata and 1.5 for which i cannot .The bold text is where it gives me null value.
Any help appreciated.
Attached is the code
$Directory = "C:\safety_pdf\"
$items = Get-ChildItem -Path $Directory -Recurse -Force
$itemDataCol = @()
ForEach($item in $items){
$a =(Select-String "ModifyDate\>(.*)\<" $($item.FullName)).Matches.Groups
ForEach($group in $a)
{
$itemData = [PSCustomObject]@{
PageID=$item.Name.Split("_")[0]
FileID= $item.Name.Split("_")[1]
Name = $item.Name.Split("_")[2]
CustomisedName = $item.Name
FullName = $item.FullName
SystemModifiedDate = $item.LastWriteTime
#LastsavedDate = (Select-String "ModifyDate\>(.*)\<" $($item.FullName)).Matches.Groups[((Select-String "ModifyDate\>(.*)\<" $($item.FullName)).Matches.Groups).Count-1]
#LastsavedDate = (Select-String "ModifyDate\>(.*)\<" $($item.FullName)).Matches.Groups[0]
LastsavedDate = $group.Value
}
if(-not($itemData.LastsavedDate.Contains("ModifyDate>")))
{
$sub = $itemData.LastsavedDate.Split('T')[0]
$dateformat= $sub.Split('-')
$dd = $dateformat[2] + '/'+ $dateformat[1] + '/' + $dateformat[0]
$itemData.LastsavedDate = [datetime]::parseexact($dd, 'dd/mm/yyyy', $null).ToString('mm/dd/yyyy')
$itemDataCol += $itemData
}
}
}
$itemDataCol| Export-Csv -Path "C:\safety_pdf.csv" -NoTypeInformation -Encoding UTF8
Copy link to clipboard
Copied
Does you see the metadata when you open a file in a text editor?
Copy link to clipboard
Copied
Yes.I do see the date last saved from the document properties but i get
the object in powershell as empty
Copy link to clipboard
Copied
May be a issue with the content of the files.

