I have been working to add a date field to a PDF. In my research it looks like the best solution is to use AddTextToPDFFile function. After many hours I am ready to ask for expert help. I have tried different OS (XP -> WIN7) different versions (1.02 -> 1.2) vanilla systems, development systems, no matter; I have been unable to get this function to work properly. I found some issues and loaded the Microsoft® Visual Studio® 2005 Team Suite Service Pack 1 and Visual Studio 2005 Service Pack 1 Update for Windows Vista on one system. Nothing seems to help. I am hoping you can…..
I have a script located in C:\\TEMP called work.vbs that my PDFCreator profile action calls after saving.
Option Explicit
Dim objArgs, fname, fso, pdfText, pdfforge, tfname, WshShell
Set objArgs = WScript.Arguments
fname = objArgs(0)
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set pdfText = Wscript.CreateObject("pdfforge.pdf.PDFText")
pdfText.FillOpacity = 1
pdfText.FontColorBlue = 111
pdfText.FontColorRed = 111
pdfText.FontColorGreen = 111
pdfText.FontName = "Arial.ttf"
pdfText.FontPath = WshShell.SpecialFolders("Fonts")
pdfText.FontSize = 36
pdfText.Rotation = 0
pdfText.Text = "date will go here if I ever get this to work"
pdfText.XPosition = 100
pdfText.YPosition = 100
tfname = fso.GetTempName
WshShell.Popup "fname = " & fname & " tfname = " & tfname, 5, "TitleHere" , vbInformation
pdfforge.AddTextToPDFFile fname, tfname, 1, 2, (pdfText)
MsgBox "Done"
Now my problem is this only works on first two pages. Again, different machines, environments, etc. have this problem. It will not process pages 3 or more.
Where is the problem? Can you describe which error do you get?
I could find only a problem in your script. Please create a pdfforge object and use a full path for your result file.
...
tfname = fso.GetParentFolderName(WScript.ScriptFullName) & "\\" & fso.GetBaseName(fso.GetTempName) & ".pdf"
WshShell.Popup "fname = " & fname & " tfname = " & tfname, 5, "TitleHere" , vbInformation
Set pdfforge = WScript.CreateObject("pdfforge.pdf.pdf")
pdfforge.AddTextToPDFFile fname, tfname, 1, 2, (pdfText)
...
And I've updated the pdfforge.dll help file with a new vbscript sample for the function AddTextToPdfFile.
Apologies, I did not post any errors. I had so many different errors depending on which option I tried. Anyway, I was able to make it work perfectly using the below script. Hope this helps others get the pdfforge.dll functions to work.
Thanks so much for pointing me in the right direction!
Question: Where is this pdfforge.dll help with a new vbscript sample for the function AddTextToPdfFile and how can I get it? Perhaps a hyperlink?
Option Explicit
Dim objArgs, fname, fso, pdfText, pdfforge, tfname, WshShell, dtmToday
Set objArgs = WScript.Arguments
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set pdfText = Wscript.CreateObject("pdfforge.pdf.PDFText")
Set pdfforge = WScript.CreateObject("pdfforge.pdf.pdf")
dtmToday = Date()
fname = objArgs(0)
tfname = fso.GetParentFolderName(WScript.ScriptFullName) & "\\" & fso.GetBaseName(fso.GetTempName) & ".pdf"
'pdfText.FillOpacity = 1
'pdfText.FontColorBlue = 0
'pdfText.FontColorRed = 0
'pdfText.FontColorGreen = 0
'pdfText.FontName = "Arial.ttf"
'pdfText.FontPath = WshShell.SpecialFolders("Fonts")
'pdfText.FontSize = 12
'pdfText.Rotation = 0
pdfText.Text = dtmToday
pdfText.XPosition = 195 'Left and Right - Right hand side
pdfText.YPosition = 1 'Up and Down - Bottom of page
pdfforge.AddTextToPDFFile fname, tfname, 1, 2, (pdfText)
fso.DeleteFile(fname)
fso.MoveFile tfname, fname
Great that I could help. And thanks for your report.
I couldn't reproduce it again. It works fine here. Check the script. It adds text on the first 8 pages of a 10 pages doument.
Option Explicit
Dim pdf, pdfText, WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
Set pdf = WScript.CreateObject("pdfforge.pdf.pdf")
pdf.CreatePDFTestDocument "input.pdf", 10, "This is an example.", true
Set pdfText = Wscript.CreateObject("pdfforge.pdf.pdfText")
pdfText.FillOpacity = 1
pdfText.FontColorBlue = 255
pdfText.FontColorGreen = 127
pdfText.FontColorRed = 200
pdfText.FontName = "arial.ttf"
pdfText.FontPath = WshShell.SpecialFolders("Fonts")
pdfText.FontSize = 48
pdfText.Rotation = 90
pdfText.Text = "Hello world here is pdfforge."
pdfText.XPosition = 50
pdfText.YPosition = 90
pdf.AddTextToPDFFile "input.pdf", "output.pdf", 1, 8, (pdfText)
Set pdfText = Nothing
Set pdf = Nothing
Frank,
You do good work, I don't care what they say about you. You are correct, there is no problem.
My code:
pdfforge.AddTextToPDFFile fname, tfname, 1, 2, (pdfText)
Your code:
pdf.AddTextToPDFFile "input.pdf", "output.pdf", 1, 8, (pdfText)
Mine printed first 2 pages, yours printed first 8 pages. I was being an I-D-ten-T and did not notice the code specified the number of pages. You did it, you solved the problem! Hope you know what an I-D-ten-T is ;-]
Everything works as planned now....