This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Can I convert a document to PDF format using VBScript

Former Member
Former Member
I want to convert a document to PDF format using VBScript upon entering a workflow state like approval.
please help.
Parents
  • Former Member
    Former Member
    Hi Samppa,
    I tried but nothing to do...

    I post my code. this is a stupid code that convert the file C:\Temp\test.docx into c:\Temp\test.docx


    There isn't someone had tried to convert a document in a pdf format?




    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
Reply
  • Former Member
    Former Member
    Hi Samppa,
    I tried but nothing to do...

    I post my code. this is a stupid code that convert the file C:\Temp\test.docx into c:\Temp\test.docx


    There isn't someone had tried to convert a document in a pdf format?




    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
Children
No Data