PDA

View Full Version : Add the file name in the header of the PDF



hart88
05-17-2012, 05:01 AM
Hi all,

I have many pdf saved in different folders.
Each day I have to print them and write down (by hand) the file name in the header of each printed paper.

I would like to know if it is possible to have a macro that do it for me: it has to detect the file name (ex. 201908), open the pdf file and write down the name in the top part, then print the document.

Do you think is it possibile?

Many thanks!

Ps. each day the file are new

mperrah
05-17-2012, 02:23 PM
I found this its .vbs it list the contents of all folders in a specified folder, then outputs to xml. this can be imported to xl and parsed...
at least its a start.


Option Explicit
Const strFolderDefault = "pick a folder" ' folder location can go here for default
Const blnGetFilesTooDefault = False
Dim strFolder, blnGetFilesToo
strFolder = InputBox("Enter the folder to index", "Folder", strFolderDefault)
blnGetFilesToo = (MsgBox("Would you like to index files in addition to folders?", vbYesNo) = vbYes)
Dim gobjDoc, gobjFso
Dim objRootFolderNode
Set gobjFso = CreateObject("Scripting.FileSystemObject")
Set gobjDoc = CreateObject("Microsoft.XMLDOM")
Set gobjDoc.DocumentElement = GetFolderElement(strFolder, strFolder, blnGetFilesToo)
gobjDoc.Save "newfile.xml" ' you can name file to be created here
Set gobjFso = Nothing
Set gobjDoc = Nothing
MsgBox "Done"

Function GetFolderElement(vstrFolderRoot, vstrName, vblnGetFilesToo)

Dim objFolderRoot, objFolderCur, objFolderElement, objAttribute
Dim objFileCur, objFileElement
Set objFolderRoot = gobjFso.GetFolder(vstrFolderRoot)
Set objFolderElement = gobjDoc.createElement("folder")
Set objAttribute = gobjDoc.createAttribute("name")
objAttribute.Value = vstrName
objFolderElement.Attributes.setNamedItem objAttribute
On Error Resume Next
For Each objFolderCur In objFolderRoot.SubFolders
objFolderElement.appendChild GetFolderElement(objFolderCur.Path, objFolderCur.Name, vblnGetFilesToo)
Next
If vblnGetFilesToo Then
For Each objFileCur In objFolderRoot.Files
Set objFileElement = gobjDoc.createElement("file")
objFileElement.setAttribute "name", objFileCur.Name
objFileElement.setAttribute "type", objFileCur.Type
objFileElement.setAttribute "path", objFileCur.Path
objFolderElement.appendChild objFileElement
Next
End If
Set GetFolderElement = objFolderElement
Set objAttribute = Nothing
Set objFolderRoot = Nothing
Set objFolderCur = Nothing
Set objFolderElement = Nothing
Set objFileCur = Nothing
Set objFileElement = Nothing
End Function



save it as a .vbs file and double click in windows explorer a message box pops up asking the folder you want to search then pop up says done.

Kenneth Hobs
05-17-2012, 03:35 PM
If you had Adobe Acrobat, not just the reader, then a watermark method could be used.