I want to convert a document to PDF format using VBScript upon entering a workflow state like approval.
please help.
Option explicit
Const maxTime = 30 ' in seconds
Const sleepTime = 250 ' in milliseconds
Dim objArgs, ifname, fso, PDFCreator, DefaultPrinter, ReadyState, i, c
Set fso = CreateObject("Scripting.FileSystemObject")
Set PDFCreator = CreateObject("PDFCreator.clsPDFCreator","localhost")
PDFCreator.cStart "/NoProcessingAtStartup"
With PDFCreator
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveFormat") = 0 ' 0 = PDF
DefaultPrinter = .cDefaultprinter
.cDefaultprinter = "PDFCreator"
.cClearcache
.cPrinterStop = false
End With
With PDFCreator
ifname = "C:\Temp\test.docx"
If Not fso.FileExists(ifname) Then
MsgBox "Can't find the file: " & ifname, vbExclamation + vbSystemModal, AppTitle
End If
if Not .cIsPrintable(CStr(ifname)) Then
MsgBox "Converting: " & ifname & vbcrlf & vbcrlf & _
"An error is occured: File is not printable!", vbExclamation + vbSystemModal, AppTitle
End if
ReadyState = 0
.cOption("AutosaveDirectory") = fso.GetParentFolderName(ifname)
.cOption("AutosaveFilename") = fso.GetBaseName(ifname)
.cPrintfile cStr(ifname)
c = 0
Do While (ReadyState = 0) and (c
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
End If
End With
With PDFCreator
.cDefaultprinter = DefaultPrinter
.cClearcache
WScript.Sleep 200
.cClose
End With
'--- PDFCreator events ---
Public Sub PDFCreator_eReady()
ReadyState = 1
End Sub
Option explicit
Const maxTime = 30 ' in seconds
Const sleepTime = 250 ' in milliseconds
Dim objArgs, ifname, fso, PDFCreator, DefaultPrinter, ReadyState, i, c
Set fso = CreateObject("Scripting.FileSystemObject")
Set PDFCreator = CreateObject("PDFCreator.clsPDFCreator","localhost")
PDFCreator.cStart "/NoProcessingAtStartup"
With PDFCreator
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveFormat") = 0 ' 0 = PDF
DefaultPrinter = .cDefaultprinter
.cDefaultprinter = "PDFCreator"
.cClearcache
.cPrinterStop = false
End With
With PDFCreator
ifname = "C:\Temp\test.docx"
If Not fso.FileExists(ifname) Then
MsgBox "Can't find the file: " & ifname, vbExclamation + vbSystemModal, AppTitle
End If
if Not .cIsPrintable(CStr(ifname)) Then
MsgBox "Converting: " & ifname & vbcrlf & vbcrlf & _
"An error is occured: File is not printable!", vbExclamation + vbSystemModal, AppTitle
End if
ReadyState = 0
.cOption("AutosaveDirectory") = fso.GetParentFolderName(ifname)
.cOption("AutosaveFilename") = fso.GetBaseName(ifname)
.cPrintfile cStr(ifname)
c = 0
Do While (ReadyState = 0) and (c
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
End If
End With
With PDFCreator
.cDefaultprinter = DefaultPrinter
.cClearcache
WScript.Sleep 200
.cClose
End With
'--- PDFCreator events ---
Public Sub PDFCreator_eReady()
ReadyState = 1
End Sub
© 2024 M-Files, All Rights Reserved.