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.
  • Former Member
    Former Member
    You should try the documentation for PDFCreator (its COM interface), as it states that

    "From Version 0.8.1 RC9 the PDFCreator has a COM Interface included. So it is possible to control the PDFCreator using the command line of any other application.
    Nearly all possiblities of the program are available using the COM Interface. The COM Interface includes Public classes, Public properties, Public methods and Public events."


    I think there you should find methods to use.

    And, if you prefer some other pdf-convertion tool, I'm sure they have similar interfaces.

    -emmi


  • Former Member
    Former Member
    Hi guys,

    Itried to use PDFCreator's COM...
    I wanna download in a TEMP folder a file and with PDFCreator convert it.

    I've an example to convert file to PDF named "convert2PDF.vbs" (on C:\Programmi\PDFCreator\COM\Windows Scripting Host\VBScripts) and it's work fine.

    I tried to import it in the actionScript but it doesn't handle events.

    have someone ideas ???
  • Former Member
    Former Member
    A thought. Event Handlers and Workflow scripts are executed at the server so the PDF Creator and viewers (Word Viewer etc) will probably need to be installed on the M-Files server. PDF Creator also has a server mode install. May need to experiment with a few options here.

    Cheers
  • Former Member
    Former Member
    Hi Rob,


    Thanks for your notice but I've installed already what you said to me but it didn't works.

    Have you got an example ?

    The vbscript I used works good manually.

    If I put all the code from my .vbs to the ActionScript it doesn't work becouse it doesn't recognize the command Wscript.CreateObject used to handle events.

    Set PDFCreator = Wscript.CreateObject("PDFCreator.clsPDFCreator", "PDFCreator_") 


    Do you have ideas ?

    Thanks a lot
  • Former Member
    Former Member
    Try removing the 'Wscript'. M-Files seems to be running a context that prefers to work without the Wscripthost part.

    Set PDFCreator = CreateObject("PDFCreator.clsPDFCreator", "PDFCreator_")

    Let us know if you get it going.

    Cheers

  • Former Member
    Former Member
    It doesn't work cuz Wscript.CreateObject has different argument of CreateObject

    http://msdn.microsoft.com/en-ca/library/7t9k08y5%28v=VS.80%29.aspx

    I haven't ideas to do it.
    I think I've to create a WindowsService with a FolderWatcher and when I put a file on this specific folder it create a pdf.

    I don't like this mode but I think it's the last beach
  • Former Member
    Former Member
    Giona, could you try once more to get it working with the code that RobW provided? The second parameter is optional.

    Samppa
  • 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