wmoerdijk Posted March 14, 2007 Posted March 14, 2007 Hello,I am trying to write a script to convert a RTF document to PDF. For this I am using the COM reference available with the "PDFCreator" package. In the installation there are working examples using WSH but I do not want to be dependent on WSH for this to work. The problem is that when I convert the script it does not work any more. I will post the full working vbs file and my simplified attemt to do a similar thing. My example is just a tes tthat convert a "test.rtf" in the root folder to a "test.pdf" in the "temp" folder.This VBS script works when WSH and PDFCreator are installed:CODE' 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 ExplicitConst maxTime = 30 ' in secondsConst sleepTime = 250 ' in millisecondsDim objArgs, ifname, fso, PDFCreator, DefaultPrinter, ReadyState, _ i, c, AppTitle, Scriptname, ScriptBasenameSet fso = CreateObject("Scripting.FileSystemObject")Scriptname = fso.GetFileName(Wscript.ScriptFullname)ScriptBasename = fso.GetFileName(Wscript.ScriptFullname)AppTitle = "PDFCreator - " & ScriptBaseNameIf CDbl(Replace(WScript.Version,".",",")) < 5.1 then MsgBox "You need the ""Windows Scripting Host version 5.1"" or greater!", vbCritical + vbSystemModal, AppTitle Wscript.QuitEnd ifSet objArgs = WScript.ArgumentsIf objArgs.Count = 0 Then MsgBox "Syntax: " & vbtab & Scriptname & " <Filename>" & vbcrlf & vbtab & "or use ""Drag and Drop""!", vbExclamation + vbSystemModal, AppTitle WScript.QuitEnd IfSet PDFCreator = Wscript.CreateObject("PDFCreator.clsPDFCreator", "PDFCreator_")PDFCreator.cStart "/NoProcessingAtStartup"With PDFCreator .cOption("UseAutosave") = 1 .cOption("UseAutosaveDirectory") = 1 .cOption("AutosaveFormat") = 0 ' 0 = PDF DefaultPrinter = .cDefaultprinter .cDefaultprinter = "PDFCreator" .cClearcacheEnd WithFor 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("AutosaveDirectory") = fso.GetParentFolderName(ifname) .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 WithNextWith PDFCreator .cDefaultprinter = DefaultPrinter .cClearcache WScript.Sleep 200 .cCloseEnd With'--- PDFCreator events ---Public Sub PDFCreator_eReady()ReadyState = 1End SubPublic Sub PDFCreator_eError() MsgBox "An error is occured!" & vbcrlf & vbcrlf & _ "Error [" & PDFCreator.cErrorDetail("Number") & "]: " & PDFcreator.cErrorDetail("Description"), vbCritical + vbSystemModal, AppTitle Wscript.QuitEnd Subbut this AutoIt script does not:CODE; Convert2PDF script;If $CmdLine[0] = 0 Then Exit(1)$file = "c:\test.rtf";Constants$maxTime = 30 ; in seconds$sleepTime = 250 ; in milliseconds;Event handlerFunc PDFCreator_eReady() $ReadyState = 1EndFunc ; init PDFCreator$oPDFC = ObjCreate("PDFCreator.clsPDFCreator")$ok = ObjEvent($oPDFC,"PDFCreator_")$oPDFC.cStart "/NoProcessingAtStartup"$oPDFC.cOption("UseAutosave") = 1$oPDFC.cOption("UseAutosaveDirectory") = 1$oPDFC.cOption("AutosaveFormat") = 0$DefaultPrinter = $oPDFC.cDefaultprinter$oPDFC.cDefaultprinter = "PDFCreator"$oPDFC.cClearCache $ReadyState = 0 $sOutFname = "test" $sOutPath = "c:\temp\" $oPDFC.cOption("AutosaveDirectory") = "c:\temp" $oPDFC.cOption("AutosaveFilename") = "test" $oPDFC.cPrintfile (String($file)) $oPDFC.cPrinterStop = false $c = 0 While ($ReadyState = 0) and ($c < (30 * $maxTime / $sleepTime)) $c = $c + 1 Sleep (250) WEnd If $ReadyState = 0 then MsgBox (1, "Error", "An error is occured: Time is up!") EndIf$oPDFC.cDefaultprinter = $DefaultPrinter$oPDFC.cClearcache$oPDFC.cCloseSleep(1000); wait a secondIt seems that the "cOption" setting I am trying do have no effect. What am I doing wrong?Wouter.
ptrex Posted March 16, 2007 Posted March 16, 2007 @wmoerdijk I have posted an example in the EXAMPLE scripts section of this forum. Enjoy !! ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now