setPDFTitle 7

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

setPDFTitle_7.

vbs 7/26/2007

' VBS file to add Title info to PDF


Set fso = CreateObject("Scripting.FileSystemObject")
xmlFile = ""
base = ""

if wscript.arguments.count > 0 then


xmlFile = wscript.arguments(0)
else
xmlFile = browseFile
end if

iBase = Replace(xmlFile, "\" & fso.GetFileName(xmlFile), "")


iBase = Replace(iBase, "/" & fso.GetFileName(xmlFile), "")
iBase = Replace(iBase, "/", "\")
'msgbox(fso.GetFileName(xmlFile))

Set pdfApp = CreateObject("AcroExch.App")


pdfApp.show
Set AcroAVDoc = CreateObject("AcroExch.AVDoc")
Set i = fso.OpenTextFile(xmlFile)
nBase = Replace(iBase, "scripts", "8.3SOTM")

Do While Not (i.atEndOfStream)


tStream = i.ReadLine

if (left(tStream, 5) = "<num>") then


sNum = Replace(Replace(tStream, "<num>", ""), "</num>", "")
end if

if (left(tStream, 5) = "<rev>") then


sRev = Replace(Replace(tStream, "<rev>", ""), "</rev>", "")
end if

if (left(tStream, 7) = "<title>") then


sTitle = Replace(Replace(tStream, "<title>", ""), "</title>", "")
end if

if (left(tStream, 10) = "<category>") then


sCategory = Replace(Replace(tStream, "<category>", ""), "</category>",
"")
end if

if (left(tStream, 6) = "<path>") then


sPath = Replace(Replace(Replace(tStream, "<path>../", ""), "</path>",
""), "/", "\")
end if

if (left(tStream, 7) = "</book>") then


if (right(lcase(sPath), 4) = ".pdf") then
'msgbox(nBase & "\" & sPath)
AcroAVDoc.Open nBase & "\" & sPath, ""
Set AVPageView = AcroAVDoc.GetAVPageView
set AcroPDDoc = AcroAVDoc.GetPDDoc
'msgbox nBase & "\" & sPath
sFileTitle = AcroPDDoc.GetInfo("Title")
sFileSubject = AcroPDDoc.GetInfo("Subject")
'if sFileTitle = "Untitled Document" then
'msgbox(nBase & "\" & sPath)
AcroPDDoc.setInfo "Title", "[" & sNum & "." & sRev & "] " &
sTitle
'end if
if sFileSubject = "" then
AcroPDDoc.setInfo "Subject", sCategory

1
setPDFTitle_7.vbs 7/26/2007

end if

b = AcroPDDoc.Save(1, nBase & "\" & sPath)


if b = 0 then
'Save Failed
msgbox("Save failed for " & nBase & "\" & sPath)
end if
AcroAVDoc.Close(1)
end if
end if
loop

i.close
pdfApp.Hide
pdfApp.Exit

function browseFile()
'* function to browse for files, only works in windows XP

set objDialog = CreateObject("UserAccounts.CommonDialog")


objDialog.Filter = "XML Files|*.xml|All Files|*.*"
objDialog.FilterIndex = 1
intResult = objDialog.ShowOpen

if intResult = "True" then


browseFile = objDialog.FileName
end if
end function

You might also like