kes3
asked on
Batch process 200 TXT files in one go with PDF creator using the supplied convert2pdf.vbs script
I am using source forge PDFCreator to batch process 200 TXT files to PDF.
I am using W2000 and can drag and drop up to about 8 files on the file convert2pdf.vbs which is a script included with the installation of PDFCreator. If I Drag and drop the whole 200 the popup message complains as follows
"Unable to process - arguments list is too long"
I need to be able to process all 200 at once so I am not sitting there all day.
Can anyone provide a simple batch file that I can use to feed the TXT files ( which are all in one directory ) to the convert2pdf.vbs script.
****************
' Convert2PDF script
' Part of PDFCreator
' License: GPL
' Homepage: http://www.sf.net/projects/pdfcreator
' Version: 1.0.0.0
' Date: September, 1. 2005
' Author: Frank Heindörfer
' Comments: This script convert a printable file in a pdf-file using
' the com interface of PDFCreator.
Option Explicit
Const maxTime = 30 ' in seconds
Const sleepTime = 250 ' in milliseconds
Dim objArgs, ifname, fso, PDFCreator, DefaultPrinter, ReadyState, _
i, c, AppTitle, Scriptname, ScriptBasename
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
Scriptname = fso.GetFileName(Wscript.Sc riptFullna me)
ScriptBasename = fso.GetFileName(Wscript.Sc riptFullna me)
AppTitle = "PDFCreator - " & ScriptBaseName
If CDbl(Replace(WScript.Versi on,".","," )) < 5.1 then
MsgBox "You need the ""Windows Scripting Host version 5.1"" or greater!", vbCritical + vbSystemModal, AppTitle
Wscript.Quit
End if
Set objArgs = WScript.Arguments
If objArgs.Count = 0 Then
MsgBox "Syntax: " & vbtab & Scriptname & " <Filename>" & vbcrlf & vbtab & "or use ""Drag and Drop""!", vbExclamation + vbSystemModal, AppTitle
WScript.Quit
End If
Set PDFCreator = Wscript.CreateObject("PDFC reator.cls PDFCreator ", "PDFCreator_")
PDFCreator.cStart "/NoProcessingAtStartup"
With PDFCreator
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirec tory") = 1
.cOption("AutosaveFormat") = 0 ' 0 = PDF
'The following are required to set security of any kind
.cOption("PDFUseSecurity") = 1
.cOption("PDFOwnerPass") = 1
.cOption("PDFOwnerPassword String") = "password"
'Set document Information
.cOption("UseStandardAutho r") = 1
.cOption("StandardAuthor") = ""
.cOption("UseCreationDateN ow") = 1
.cOption("StandardCreation date") = ""
.cOption("StandardModifyda te") = ""
.cOption("StandardSubject" ) = ""
.cOption("StandardTitle") = ""
DefaultPrinter = .cDefaultprinter
.cDefaultprinter = "PDFCreator"
.cClearcache
End With
For i = 0 to objArgs.Count - 1
With PDFCreator
ifname = objArgs(i)
If Not fso.FileExists(ifname) Then
MsgBox "Can't find the file: " & ifname, vbExclamation + vbSystemModal, AppTitle
Exit For
End If
if Not .cIsPrintable(CStr(ifname) ) Then
MsgBox "Converting: " & ifname & vbcrlf & vbcrlf & _
"An error is occured: File is not printable!", vbExclamation + vbSystemModal, AppTitle
WScript.Quit
End if
ReadyState = 0
.cOption("AutosaveDirector y") = fso.GetParentFolderName(if name)
.cOption("AutosaveFilename ") = fso.GetBaseName(ifname)
.cPrintfile cStr(ifname)
.cPrinterStop = false
c = 0
Do While (ReadyState = 0) and (c < (maxTime * 1000 / sleepTime))
c = c + 1
Wscript.Sleep sleepTime
Loop
If ReadyState = 0 then
MsgBox "Converting: " & ifname & vbcrlf & vbcrlf & _
"An error is occured: Time is up!", vbExclamation + vbSystemModal, AppTitle
Exit For
End If
End With
Next
With PDFCreator
.cDefaultprinter = DefaultPrinter
.cClearcache
WScript.Sleep 200
.cClose
End With
'--- PDFCreator events ---
Public Sub PDFCreator_eReady()
ReadyState = 1
End Sub
Public Sub PDFCreator_eError()
MsgBox "An error is occured!" & vbcrlf & vbcrlf & _
"Error [" & PDFCreator.cErrorDetail("N umber") & "]: " & PDFcreator.cErrorDetail("D escription "), vbCritical + vbSystemModal, AppTitle
Wscript.Quit
End Sub
I am using W2000 and can drag and drop up to about 8 files on the file convert2pdf.vbs which is a script included with the installation of PDFCreator. If I Drag and drop the whole 200 the popup message complains as follows
"Unable to process - arguments list is too long"
I need to be able to process all 200 at once so I am not sitting there all day.
Can anyone provide a simple batch file that I can use to feed the TXT files ( which are all in one directory ) to the convert2pdf.vbs script.
****************
' Convert2PDF script
' Part of PDFCreator
' License: GPL
' Homepage: http://www.sf.net/projects/pdfcreator
' Version: 1.0.0.0
' Date: September, 1. 2005
' Author: Frank Heindörfer
' Comments: This script convert a printable file in a pdf-file using
' the com interface of PDFCreator.
Option Explicit
Const maxTime = 30 ' in seconds
Const sleepTime = 250 ' in milliseconds
Dim objArgs, ifname, fso, PDFCreator, DefaultPrinter, ReadyState, _
i, c, AppTitle, Scriptname, ScriptBasename
Set fso = CreateObject("Scripting.Fi
Scriptname = fso.GetFileName(Wscript.Sc
ScriptBasename = fso.GetFileName(Wscript.Sc
AppTitle = "PDFCreator - " & ScriptBaseName
If CDbl(Replace(WScript.Versi
MsgBox "You need the ""Windows Scripting Host version 5.1"" or greater!", vbCritical + vbSystemModal, AppTitle
Wscript.Quit
End if
Set objArgs = WScript.Arguments
If objArgs.Count = 0 Then
MsgBox "Syntax: " & vbtab & Scriptname & " <Filename>" & vbcrlf & vbtab & "or use ""Drag and Drop""!", vbExclamation + vbSystemModal, AppTitle
WScript.Quit
End If
Set PDFCreator = Wscript.CreateObject("PDFC
PDFCreator.cStart "/NoProcessingAtStartup"
With PDFCreator
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirec
.cOption("AutosaveFormat")
'The following are required to set security of any kind
.cOption("PDFUseSecurity")
.cOption("PDFOwnerPass") = 1
.cOption("PDFOwnerPassword
'Set document Information
.cOption("UseStandardAutho
.cOption("StandardAuthor")
.cOption("UseCreationDateN
.cOption("StandardCreation
.cOption("StandardModifyda
.cOption("StandardSubject"
.cOption("StandardTitle") = ""
DefaultPrinter = .cDefaultprinter
.cDefaultprinter = "PDFCreator"
.cClearcache
End With
For i = 0 to objArgs.Count - 1
With PDFCreator
ifname = objArgs(i)
If Not fso.FileExists(ifname) Then
MsgBox "Can't find the file: " & ifname, vbExclamation + vbSystemModal, AppTitle
Exit For
End If
if Not .cIsPrintable(CStr(ifname)
MsgBox "Converting: " & ifname & vbcrlf & vbcrlf & _
"An error is occured: File is not printable!", vbExclamation + vbSystemModal, AppTitle
WScript.Quit
End if
ReadyState = 0
.cOption("AutosaveDirector
.cOption("AutosaveFilename
.cPrintfile cStr(ifname)
.cPrinterStop = false
c = 0
Do While (ReadyState = 0) and (c < (maxTime * 1000 / sleepTime))
c = c + 1
Wscript.Sleep sleepTime
Loop
If ReadyState = 0 then
MsgBox "Converting: " & ifname & vbcrlf & vbcrlf & _
"An error is occured: Time is up!", vbExclamation + vbSystemModal, AppTitle
Exit For
End If
End With
Next
With PDFCreator
.cDefaultprinter = DefaultPrinter
.cClearcache
WScript.Sleep 200
.cClose
End With
'--- PDFCreator events ---
Public Sub PDFCreator_eReady()
ReadyState = 1
End Sub
Public Sub PDFCreator_eError()
MsgBox "An error is occured!" & vbcrlf & vbcrlf & _
"Error [" & PDFCreator.cErrorDetail("N
Wscript.Quit
End Sub
i just threw this together. name it findnrun.vbs and throw it in the same directory as the Convert2PDF.vbs.
haven't tested it, but it looks like it should do what you need.
double click on it and it will tell you what to do.
On Error Resume Next
Dim fso, folder, files, NewsFile,sFolder
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
sFolder = Wscript.Arguments.Item(0)
If sFolder = "" Then
Wscript.Echo "No Folder parameter was passed"
Wscript.Echo "findnrun.vbs <folder location With all the pdf files>"
Wscript.Echo "example:"
Wscript.Echo "cscript findnrun.vbs c:\temp\pdf"
Wscript.Quit
End If
Set NewFile = fso.CreateTextFile(sFolder &"\FileLis t.txt", True)
Set folder = fso.GetFolder(sFolder)
Set files = folder.Files
For each folderIdx In files
NewFile.WriteLine(folderId x.Name)
Next
NewFile.Close
Const ForReading = 1
Set objDictionary = CreateObject("Scripting.Di ctionary")
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Set objTextFile = objFSO.OpenTextFile(sFolde r&"\FileLi st.txt", ForReading)
i = 0
Do While objTextFile.AtEndOfStream <> True
strNextLine = objTextFile.Readline
objDictionary.Add i, strNextLine
i = i + 1
Loop
Set objShell=CreateObject("WSc ript.Shell ")
For Each objItem in objDictionary
objShell.Run("cscript Convert2PDF.vbs " & objitem )
Next
haven't tested it, but it looks like it should do what you need.
double click on it and it will tell you what to do.
On Error Resume Next
Dim fso, folder, files, NewsFile,sFolder
Set fso = CreateObject("Scripting.Fi
sFolder = Wscript.Arguments.Item(0)
If sFolder = "" Then
Wscript.Echo "No Folder parameter was passed"
Wscript.Echo "findnrun.vbs <folder location With all the pdf files>"
Wscript.Echo "example:"
Wscript.Echo "cscript findnrun.vbs c:\temp\pdf"
Wscript.Quit
End If
Set NewFile = fso.CreateTextFile(sFolder
Set folder = fso.GetFolder(sFolder)
Set files = folder.Files
For each folderIdx In files
NewFile.WriteLine(folderId
Next
NewFile.Close
Const ForReading = 1
Set objDictionary = CreateObject("Scripting.Di
Set objFSO = CreateObject("Scripting.Fi
Set objTextFile = objFSO.OpenTextFile(sFolde
i = 0
Do While objTextFile.AtEndOfStream <> True
strNextLine = objTextFile.Readline
objDictionary.Add i, strNextLine
i = i + 1
Loop
Set objShell=CreateObject("WSc
For Each objItem in objDictionary
objShell.Run("cscript Convert2PDF.vbs " & objitem )
Next
ASKER
Rob, Weeilo - thanks.
Rob : I want a script where I don't have to name the TXT files in the batch file.
Weellio : PDFCreator does not like more than one copy of itself running at once. What is needed is a window then a delay say of 1.5 mins before a new window is called to give PDF creator enough time to finish the previous file run ( some of the TXT files are huge ).
Thanks ...
Rob : I want a script where I don't have to name the TXT files in the batch file.
Weellio : PDFCreator does not like more than one copy of itself running at once. What is needed is a window then a delay say of 1.5 mins before a new window is called to give PDF creator enough time to finish the previous file run ( some of the TXT files are huge ).
Thanks ...
kes3, that's fine. What I meant by sample was, if all of your files are in one folder, it's easy to set up a VBS that can read all of the file names, and start the Convert2PDF.vbs file for you.
Regards,
Rob.
Regards,
Rob.
ASKER
Rob, Yes they are all in one folder. Thanks.
Hi try this, but make sure to test it. I'm not sure if your Convert2PDF.vbs will wait for it to finish its processes before it will go back to this script. As you said it doesn't like running itself more than once at a time, this could be a problem,......
'===================
strFolderPath = "C:\Temp\"
intMaxFiles = 10
strExtension = ".txt"
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Set objFolder = objFSO.GetFolder(strFolder Path)
Set objShell = CreateObject("WScript.Shel l")
intFiles = 0
strArgs = ""
For Each objFile In objFolder.Files
strFileName = Mid(objFile.Name, InStrRev(objFile.Name, "\") + 1)
If LCase(Right(strFileName, 4)) = strExtension Then
intFiles = intFiles + 1
strArgs = strArgs & " """ & strFileName & """"
If intFiles = intMaxFiles Then
strCommand = "wscript.exe """ & Replace(WScript.ScriptFull Name, WScript.ScriptName, "") & "Convert2PDF.vbs""" & strArgs
Set objExec = objShell.Exec(strCommand)
While objExec.Status
' wait until the script finishes
Wend
intFiles = 0
strArgs = ""
End If
End If
Next
MsgBox "Done"
'================
Regards,
Rob.
'===================
strFolderPath = "C:\Temp\"
intMaxFiles = 10
strExtension = ".txt"
Set objFSO = CreateObject("Scripting.Fi
Set objFolder = objFSO.GetFolder(strFolder
Set objShell = CreateObject("WScript.Shel
intFiles = 0
strArgs = ""
For Each objFile In objFolder.Files
strFileName = Mid(objFile.Name, InStrRev(objFile.Name, "\") + 1)
If LCase(Right(strFileName, 4)) = strExtension Then
intFiles = intFiles + 1
strArgs = strArgs & " """ & strFileName & """"
If intFiles = intMaxFiles Then
strCommand = "wscript.exe """ & Replace(WScript.ScriptFull
Set objExec = objShell.Exec(strCommand)
While objExec.Status
' wait until the script finishes
Wend
intFiles = 0
strArgs = ""
End If
End If
Next
MsgBox "Done"
'================
Regards,
Rob.
ASKER
Thanks Rob.
It produces the same error as when I try to process more than 8 or so files with Convert2PDF.vbs by dragging them onto that file. The error is given in a pop up box : "Unable to execute - arguments list is too long". I think this means the command line cannot accept all the file names on the same line. Can we have a batch file / vbs file that has all 200 dragged onto it but only passes one at a time to convert2pdf.vbs.
It produces the same error as when I try to process more than 8 or so files with Convert2PDF.vbs by dragging them onto that file. The error is given in a pop up box : "Unable to execute - arguments list is too long". I think this means the command line cannot accept all the file names on the same line. Can we have a batch file / vbs file that has all 200 dragged onto it but only passes one at a time to convert2pdf.vbs.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Folks,
I got them both working after a fashion so I'll distribute points evenly : I discovered that I can open PDFCreator and drag all 200 TXT files into there and it does the lot.
Many Thanks
Kez3
I got them both working after a fashion so I'll distribute points evenly : I discovered that I can open PDFCreator and drag all 200 TXT files into there and it does the lot.
Many Thanks
Kez3
Fair enough! How strange that it can be done like that, but not directly onto the VBS. The GUI must do something else......maybe pass single files behind the scenese.....
Anyway, well done.
Rob.
Anyway, well done.
Rob.
heh, i even knew that,.. never tried 200, but quite a few.
thanks
thanks
wscript c:\convert2pdf.vbs file1.txt file2.txt "file 3.txt" ....etc
If they are all in the one folder, this becomes much easier....
Regards,
Rob.