Vbscript action after saving

Hi.

Scenario: running vbscript in "action after saving", but cannot manipulate file as it is locked by PDFCreator!

I am attempting to add page x of y to a doc, using a vbscript I've written containing the AddPageNumberToPDFFile function (script copied below). Whenever I attempt the write, it returns "the program cannot access the file because it is being used by another process" - which makes sense if you think about it.

Does anyone know a way round this? Thanks in advance,

Paul G


 

Option Explicit

Dim pdf, pdfText, WshShell, objArgs, fname, pages

Set objArgs = WScript.Arguments
fname = objArgs(0)
pages = GetCountOfPagesFromPostscriptfile(fname)

MsgBox fname, vbExclamation, "Doc Name"

Set WshShell = WScript.CreateObject("WScript.Shell")
Set pdf = WScript.CreateObject("pdfforge.pdf.pdf")

Set pdfText  = Wscript.CreateObject("pdfforge.pdf.pdfText")

pdfText.Text = "[PAGE]/[PAGES]"
pdf.AddPageNumberToPDFFile fname, fname, 1, pages, 1, pages, 6, 15, 15, (pdfText)

Set pdfText = Nothing
Set pdf = Nothing


Private Function GetCountOfPagesFromPostscriptfile(PostscriptFile)
 Dim fso, f, fstr, pp
 Set fso = CreateObject("Scripting.FileSystemObject")
 Set f = fso.OpenTextFile(PostscriptFile, 1, True)
 fstr = f.ReadAll
 f.Close
 pp = InstrRev(fstr, "%%Pages:", -1, 1)
 If pp <= 0 Then
  GetCountOfPagesFromPostscriptfile = 1
  Exit Function
 End If
 pp = Instr(pp, fstr," ", 1)
 If pp <= 0 Then
  GetCountOfPagesFromPostscriptfile = 1
  Exit Function
 End If
 fstr = Trim(Mid(fstr,pp))
 fstr = Replace(fstr, chr(10), " ", 1, -1, 1)
 fstr = Replace(fstr, chr(13), " ", 1, -1, 1)
 pp = Instr(1, fstr," ", 1)
 If pp <= 0 Then
  GetCountOfPagesFromPostscriptfile = 1
  Exit Function
 End If
 fstr=mid(fstr,1,pp-1)
 If Not IsNumeric(fstr) Then
  fstr = 1
 End If
 GetCountOfPagesFromPostscriptfile = fstr
End Function

 

 

Sorry: Stupid mistake. I was setting the input and output file as the same thing.

As an extra, no need to use that function to find the page total, as using parameters of 0 does the hard work for you.

Paul G