#Region PDFCreator.au3 - Header ; #INDEX# ======================================================================================================================= ; Title .........: UDF for PDFCreator 1.x.x ; AutoIt Version : 3.3.10.2++ ; Language ......: English ; Description ...: A collection of functions for UDF for PDFCreator 1.x.x ; Author(s) .....: mLipok ; Modified ......: ; =============================================================================================================================== #cs Title: UDF for PDFCreator 1.x.x Filename: PDFCreator.au3 Description: A collection of functions for PDFCreator 1.x.x Author: mLipok Modified: Version: 0.1 Last Update: 2015/05/21 Requirements: this UDF is for PDFCreator 1.x.x not for 2.x.x Remarks: Thanks to @ptrex (https://www.autoitscript.com/forum/profile/6305-ptrex/) for this UDF: http://www.autoitscript.com/forum/topic/42776-pdfcreator-print2pdf/ which was for me an inspiration, not only for PDFCreator, but to learn ActiveX controls. #CE #EndRegion PDFCreator.au3 - Header #Region PDFCreator.au3 - Options OnAutoItExitRegister('_PDFCreator_CleanUp') #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7 ;~ #AutoIt3Wrapper_Run_Debug_Mode=Y #Tidy_Parameters=/sort_funcs /reel #EndRegion PDFCreator.au3 - Options #Region PDFCreator.au3 - INCLUDE #include-once #include #include #EndRegion PDFCreator.au3 - INCLUDE #Region PDFCreator.au3 - Variable Declaration Global $g__oPDFCreator Global $g__oPDFCreator_ErrorHandler Global Enum _ $g_ePDFCreator_Format_PDF, _ $g_ePDFCreator_Format_PNG, _ $g_ePDFCreator_Format_JPG, _ $g_ePDFCreator_Format_BMP, _ $g_ePDFCreator_Format_PCX, _ $g_ePDFCreator_Format_TIFF, _ $g_ePDFCreator_Format_PS, _ $g_ePDFCreator_Format_EPS, _ $g_ePDFCreator_Format_ASCII, _ $g_ePDFCreator_Format_COUNTER Global Enum _ $g__ePDFCreator_CONFIG_Visible, _ $g__ePDFCreator_CONFIG_DefaultPrinter, _ $g__ePDFCreator_CONFIG_PrinterStop, _ $g__ePDFCreator_CONFIG_UseAutoSave, _ $g__ePDFCreator_CONFIG_UseAutoSaveDirectory, _ $g__ePDFCreator_CONFIG_AutoSaveDirectory, _ $g__ePDFCreator_CONFIG_AutoSaveFilename, _ $g__ePDFCreator_CONFIG_AutoSaveFormat, _ $g__ePDFCreator_CONFIG_COUNTER Global Enum _ $g__ePDFCreator_ERROR_OK, _ $g__ePDFCreator_ERROR_STANDARD, _ $g__ePDFCreator_ERROR_OBJECT_CREATION, _ $g__ePDFCreator_ERROR_NOT_PRINTABLE, _ $g__ePDFCreator_ERROR_NO_PRINTJOBS, _ $g__ePDFCreator_ERROR_ANOTHER_PRINTJOBS, _ $g__ePDFCreator_ERROR_PRINTER_NOT_INSTALED, _ $g__ePDFCreator_ERROR_COUNTER #EndRegion PDFCreator.au3 - Variable Declaration #Region PDFCreator.au3 - Example Init If Not @Compiled And @ScriptName = 'PDFCreator.au3' Or @ScriptName = 'PDFCreator_DebugIt.au3' Then $g__oPDFCreator_ErrorHandler = ObjEvent("AutoIt.Error", "__PDFCreator_ErrFunc") #CS Not working yet _PDFCreator_ConvertDocument(@ScriptDir & '\PDFCreator.rtf',@ScriptDir & '\PDFCreator_2.pdf') ShellExecute(@ScriptDir & '\PDFCreator.rtf') ShellExecute(@ScriptDir & '\PDFCreator_2.pdf') MsgBox(0, 'END', '_PDFCreator_ConvertDocument()') #CE _PDFCreator_Example_1_RTF2PDF() MsgBox(0, 'END', '_PDFCreator_Example_1_RTF2PDF()') _PDFCreator_Example_2_COMBINEALL() MsgBox(0, 'END', '_PDFCreator_Example_2_COMBINEALL()') _PDFCreator_Example_3_COMBINEALL() MsgBox(0, 'END', '_PDFCreator_Example_3_COMBINEALL()') MsgBox(0, 'EXIT', 'Close this MsgBox to exit example script.') ;~ MsgBox(0, '$g__oPDFCreator.cWindowsVersion', $g__oPDFCreator.cWindowsVersion) Exit EndIf #EndRegion PDFCreator.au3 - Example Init #Region PDFCreator.au3 - Examples Func _PDFCreator_Example_1_RTF2PDF() __PDFCreator_ObjCreate() If @error Then Return SetError(@error) Else ; Initialize PDFCreator ; Get Current PDFCreator configuration Local $aPDFCreator_Stored_Config = _PDFCreator_Config_GetCurrent() $g__oPDFCreator.cVisible = True $g__oPDFCreator.cPrinterStop = False ; remarks: @ScriptDir & '\PDFCreator.rtf' should be created by your self _PDFCreator_RTF2PDF(@ScriptDir & '\PDFCreator.rtf') ; Restore previous PDFCreator configuration _PDFCreator_Config_Set($aPDFCreator_Stored_Config) ; CleanUp _PDFCreator_CleanUp() ; show the results ShellExecute(@ScriptDir & '\PDFCreator.pdf') EndIf EndFunc ;==>_PDFCreator_Example_1_RTF2PDF Func _PDFCreator_Example_2_COMBINEALL() Local $sDest_FileFullPath = @ScriptDir & '\PDFCreator_Example_2_Combined.pdf' ; Example - pre setting - CleanUp and data prepartion FileDelete($sDest_FileFullPath) FileDelete(@ScriptDir & '\PDFCreator_*.txt') FileWrite(@ScriptDir & '\PDFCreator_1.txt', 'PAGE 1') FileWrite(@ScriptDir & '\PDFCreator_2.txt', 'PAGE 2') FileWrite(@ScriptDir & '\PDFCreator_3.txt', 'PAGE 3') ; Initialize PDFCreator _PDFCreator_INIT() If Not @error Then ; Get Current PDFCreator configuration Local $aPDFCreator_Stored_Config = _PDFCreator_Config_GetCurrent() ; stop PDFCreator _PDFCreator_Printer_Stop(True) ; Set PDFCreator to AutoSave file _PDFCreator_AutoSave_State(True) ; Set PDFCreator destination FileFullPath and Type _PDFCreator_AutoSave_SetFilePath($sDest_FileFullPath, 'PDF') ; Printing few documents _PDFCreator_PrintDocument(@ScriptDir & '\PDFCreator_1.txt') _PDFCreator_PrintDocument(@ScriptDir & '\PDFCreator_2.txt') _PDFCreator_PrintDocument(@ScriptDir & '\PDFCreator_3.txt') ; Say to PDFCretor to combine all queued documents - just now _PDFCreator_CombineAll() ; Finally start Combine proces by: ; Starting Printer ; waiting to all queued documents are done ; waiting $sDest_FileFullPath is not used _PDFCreator_Autosave_Start() ; Restore previous PDFCreator configuration _PDFCreator_Config_Set($aPDFCreator_Stored_Config) ; CleanUp _PDFCreator_CleanUp() ; show the results ShellExecute($sDest_FileFullPath) EndIf EndFunc ;==>_PDFCreator_Example_2_COMBINEALL Func _PDFCreator_Example_3_COMBINEALL() Local $sDest_FileFullPath = @ScriptDir & '\PDFCreator_Example_3_Combined.pdf' ; Example - pre setting - CleanUp and data prepartion FileDelete($sDest_FileFullPath) FileDelete(@ScriptDir & '\PDFCreator_*.txt') FileWrite(@ScriptDir & '\PDFCreator_1.txt', 'PAGE 1') FileWrite(@ScriptDir & '\PDFCreator_2.txt', 'PAGE 2') FileWrite(@ScriptDir & '\PDFCreator_3.txt', 'PAGE 3') ; Initialize PDFCreator _PDFCreator_INIT() If Not @error Then ; Get Current PDFCreator configuration Local $aPDFCreator_Stored_Config = _PDFCreator_Config_GetCurrent() Local $a_File = StringSplit($sDest_FileFullPath, '\', '') Local $sAutoSaveFileName = $a_File[$a_File[0]] Local $sAutoSaveDirectory = StringTrimRight($sDest_FileFullPath, StringLen($sAutoSaveFileName) + 1) Local $aPDFCreator_New_Config[$g__ePDFCreator_CONFIG_COUNTER] With $g__oPDFCreator $aPDFCreator_New_Config[$g__ePDFCreator_CONFIG_Visible] = False ; Hide PDFCreator Console/GUI $aPDFCreator_New_Config[$g__ePDFCreator_CONFIG_DefaultPrinter] = 'PDFCreator' ; Set PDFCreator as Default Printer $aPDFCreator_New_Config[$g__ePDFCreator_CONFIG_PrinterStop] = True ; STOP PDFCreator Printer $aPDFCreator_New_Config[$g__ePDFCreator_CONFIG_UseAutoSave] = 1 ; Set PDFCreator to AutoSave file $aPDFCreator_New_Config[$g__ePDFCreator_CONFIG_UseAutoSaveDirectory] = 1 ; Use PDFCreator with AutoSave $aPDFCreator_New_Config[$g__ePDFCreator_CONFIG_AutoSaveDirectory] = $sAutoSaveDirectory ; Set AutoSave Directory $aPDFCreator_New_Config[$g__ePDFCreator_CONFIG_AutoSaveFilename] = $sAutoSaveFileName ; Set AutoSave FileName $aPDFCreator_New_Config[$g__ePDFCreator_CONFIG_AutoSaveFormat] = $g_ePDFCreator_Format_PDF ; Set AutoSave Document Type EndWith ; Using new Config Setup _PDFCreator_Config_Set($aPDFCreator_New_Config) ; Printing few documents _PDFCreator_PrintDocument(@ScriptDir & '\PDFCreator_1.txt') _PDFCreator_PrintDocument(@ScriptDir & '\PDFCreator_2.txt') _PDFCreator_PrintDocument(@ScriptDir & '\PDFCreator_3.txt') ; Say to PDFCretor to combine all queued documents - just now _PDFCreator_CombineAll() ; Finally start Combine proces by: ; Starting Printer ; waiting - all queued documents are done ; waiting - $sDest_FileFullPath is not used _PDFCreator_Autosave_Start() ; Restore previous PDFCreator configuration _PDFCreator_Config_Set($aPDFCreator_Stored_Config) ; CleanUp _PDFCreator_CleanUp() ; show the results ShellExecute($sDest_FileFullPath) EndIf EndFunc ;==>_PDFCreator_Example_3_COMBINEALL #EndRegion PDFCreator.au3 - Examples #Region PDFCreator.au3 - Event Handler Func __PDFCreator_ErrFunc($oError) ; Do anything here. ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) ;~ MsgBox(0, '', 'ERROR') EndFunc ;==>__PDFCreator_ErrFunc Func _PDFCreator_EVENT_eError() Local $vErrorNumber = $g__oPDFCreator.cErrorDetail("Number") Local $sErrorDescription = $g__oPDFCreator.cErrorDetail("Description") MsgBox(0, "PDFCreator AX: An error is occured!", 'Error: #' & $vErrorNumber & @CRLF & 'Description: ' & $sErrorDescription) EndFunc ;==>_PDFCreator_EVENT_eError Func _PDFCreator_EVENT_eReady() ConsoleWrite('! _PDFCreator_eReady = 1' & @CRLF) ; TODO - any concept how to use this ? ; Local $ReadyState = 1 EndFunc ;==>_PDFCreator_EVENT_eReady #EndRegion PDFCreator.au3 - Event Handler #Region PDFCreator.au3 - INTERNAL FUNCTIONS Func __PDFCreator_ObjCreate() If Not IsObj($g__oPDFCreator) Then If ProcessExists("PDFCreator.exe") Then ;~ $g__oPDFCreator = ObjGet('', "PDFCreator.clsPDFCreator") ProcessClose('PDFCreator.exe') Else EndIf $g__oPDFCreator = ObjCreate("PDFCreator.clsPDFCreator") If @error Then Return SetError($g__ePDFCreator_ERROR_OBJECT_CREATION) Else ObjEvent($g__oPDFCreator, "_PDFCreator_EVENT_") ;~ $g__oPDFCreator.cStart("/NoProcessing") $g__oPDFCreator.cStart("/NoProcessingAtStartup") $g__oPDFCreator.cClearcache() EndIf EndIf EndFunc ;==>__PDFCreator_ObjCreate Func __PDFCreator_WaitFileIsNotUsed($sPDF_FileFullPath) Do Sleep(100) Until Not _WinAPI_FileInUse($sPDF_FileFullPath) EndFunc ;==>__PDFCreator_WaitFileIsNotUsed #EndRegion PDFCreator.au3 - INTERNAL FUNCTIONS #Region PDFCreator.au3 - Functions CONFIG Func _PDFCreator_Config_GetCurrent() __PDFCreator_ObjCreate() If @error Then Return SetError(@error) Else Local $aCONFIG[$g__ePDFCreator_CONFIG_COUNTER] With $g__oPDFCreator $aCONFIG[$g__ePDFCreator_CONFIG_Visible] = .cVisible $aCONFIG[$g__ePDFCreator_CONFIG_DefaultPrinter] = .cDefaultprinter $aCONFIG[$g__ePDFCreator_CONFIG_PrinterStop] = .cPrinterStop $aCONFIG[$g__ePDFCreator_CONFIG_UseAutoSave] = .cOption("UseAutosave") $aCONFIG[$g__ePDFCreator_CONFIG_UseAutoSaveDirectory] = .cOption("UseAutosaveDirectory") $aCONFIG[$g__ePDFCreator_CONFIG_AutoSaveDirectory] = .cOption("AutosaveDirectory") $aCONFIG[$g__ePDFCreator_CONFIG_AutoSaveFilename] = .cOption("AutosaveFilename") $aCONFIG[$g__ePDFCreator_CONFIG_AutoSaveFormat] = .cOption("AutosaveFormat") ; $aCONFIG[$g__ePDFCreator_CONFIG_] = EndWith Return $aCONFIG EndIf EndFunc ;==>_PDFCreator_Config_GetCurrent Func _PDFCreator_Config_Set($aCONFIG) __PDFCreator_ObjCreate() If @error Then Return SetError(@error) Else If Not IsObj($g__oPDFCreator) Then MsgBox(0, 'Error', 'Not IsObj($g__oPDFCreator)') With $g__oPDFCreator .cVisible = $aCONFIG[$g__ePDFCreator_CONFIG_Visible] .cDefaultprinter = $aCONFIG[$g__ePDFCreator_CONFIG_DefaultPrinter] .cPrinterStop = $aCONFIG[$g__ePDFCreator_CONFIG_PrinterStop] .cOption("UseAutosave") = $aCONFIG[$g__ePDFCreator_CONFIG_UseAutoSave] .cOption("UseAutosaveDirectory") = $aCONFIG[$g__ePDFCreator_CONFIG_UseAutoSaveDirectory] .cOption("AutosaveDirectory") = $aCONFIG[$g__ePDFCreator_CONFIG_AutoSaveDirectory] .cOption("AutosaveFilename") = $aCONFIG[$g__ePDFCreator_CONFIG_AutoSaveFilename] .cOption("AutosaveFormat") = $aCONFIG[$g__ePDFCreator_CONFIG_AutoSaveFormat] ; = $aCONFIG[$g__ePDFCreator_CONFIG_] = EndWith EndIf EndFunc ;==>_PDFCreator_Config_Set #EndRegion PDFCreator.au3 - Functions CONFIG #Region PDFCreator.au3 - Functions Func _PDFCreator_CleanUp() If IsObj($g__oPDFCreator) Then $g__oPDFCreator.cPrinterStop = False $g__oPDFCreator.cVisible = True If Not $g__oPDFCreator.cIsClosed() Then $g__oPDFCreator.cClose() EndIf $g__oPDFCreator_ErrorHandler = '' $g__oPDFCreator = '' EndFunc ;==>_PDFCreator_CleanUp Func _PDFCreator_CombineAll() __PDFCreator_ObjCreate() If @error Then Return SetError(@error) Else If $g__oPDFCreator.cCountOfPrintjobs > 1 Then $g__oPDFCreator.cCombineAll() Do Sleep(200) Until $g__oPDFCreator.cCountOfPrintjobs = 1 $g__oPDFCreator.cCombineAll() ;~ MsgBox(0, 'combined', 0) Else Return SetError($g__ePDFCreator_ERROR_NO_PRINTJOBS) EndIf EndIf EndFunc ;==>_PDFCreator_CombineAll ; #FUNCTION# ==================================================================================================================== ; Name ..........: _PDFCreator_ConvertDocument ; Description ...: ; Syntax ........: _PDFCreator_ConvertDocument($sInput_FileFullPath, $sOutput_FileFullPath[, $sSubFormat = "PDF/X"[, ; $bDoNotDeleteInputFile = True]]) ; Parameters ....: $sInput_FileFullPath - a string value. ; $sOutput_FileFullPath- a string value. ; $sSubFormat - [optional] a string value. Default is "PDF/X". ; $bDoNotDeleteInputFile- [optional] a boolean value. Default is True. ; Return values .: None ; Author ........: mLipok ; Modified ......: ; Remarks .......: Allowed values for 'SubFormat': "PDF/A-1b" for "PDF/A-1b"files; "PDF/A-2b" for "PDF/A-2b"files; "PDF/X" for "PDF/X"-files ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _PDFCreator_ConvertDocument($sInput_FileFullPath, $sOutput_FileFullPath, $sSubFormat = "PDF/X", $bDoNotDeleteInputFile = True) __PDFCreator_ObjCreate() If @error Then Return SetError(@error) Else If $bDoNotDeleteInputFile Then FileCopy($sInput_FileFullPath, $sInput_FileFullPath & '.backup') ; TODO ; Public Sub cConvertFile(ByVal InputFilename As String, ByVal OutputFilename As String, Optional ByVal SubFormat As String = "") ' Allowed values for 'SubFormat': "PDF/A-1b" for "PDF/A-1b"files; "PDF/A-2b" for "PDF/A-2b"files; "PDF/X" for "PDF/X"-files $g__oPDFCreator.cConvertFile($sInput_FileFullPath, $sOutput_FileFullPath, $sSubFormat) If $bDoNotDeleteInputFile Then FileMove($sInput_FileFullPath & '.backup', $sInput_FileFullPath) EndIf EndFunc ;==>_PDFCreator_ConvertDocument Func _PDFCreator_ConvertDocument2($sFileFullPath = "", $sOutputDocumentFormat = "PDF") __PDFCreator_ObjCreate() If @error Then Return SetError(@error) Else If Not $g__oPDFCreator.cIsPrintable(String($sFileFullPath)) Then ConsoleWrite("Conversion imposible - file: " & $sFileFullPath & @CRLF & ' is not printable file' & @CRLF) Return SetError($g__ePDFCreator_ERROR_NOT_PRINTABLE) EndIf If $g__oPDFCreator.cCountOfPrintjobs <> 0 Then Return SetError($g__ePDFCreator_ERROR_ANOTHER_PRINTJOBS, 0, '') $g__oPDFCreator.cClearcache() Local $bPreviousStopStatus = _PDFCreator_Printer_Stop(False) Local $sPreviousPrinter = $g__oPDFCreator.cDefaultprinter Local $a_File = StringSplit($sFileFullPath, '\', '') Local $a_File2 = StringSplit($a_File[$a_File[0]], '.') Local $sAutoSaveDirectory = StringReplace($sFileFullPath, '\' & $a_File[$a_File[0]], '') Local $sOUT_FileName = StringReplace($a_File[$a_File[0]], '.' & $a_File2[$a_File2[0]], '') ; $sOUT_FileName with out extension ; TODO ErrorChecking _PDFCreator_AutoSave_State(True) $sOUT_FileName &= _PDFCreator_AutoSave_SetFormat($sOutputDocumentFormat) _PDFCreator_AutoSave_SetFilePath($sFileFullPath, $sOutputDocumentFormat) Local $sDest_FileFullPath = $sAutoSaveDirectory & '\' & $sOUT_FileName ;~ MsgBox(0, '$sFileFullPath', $sFileFullPath) ;~ MsgBox(0, '$sDest_FileFullPath', $sDest_FileFullPath) __PDFCreator_WaitFileIsNotUsed($sFileFullPath) FileDelete($sDest_FileFullPath) ;~ MsgBox(0, '', 2) ;~ ShellExecuteWait($sFileFullPath,'',$sAutoSaveDirectory,'print',@SW_HIDE) $g__oPDFCreator.cPrintfile(String($sFileFullPath)) _PDFCreator_Autosave_Start() ; CleanUp $g__oPDFCreator.cDefaultprinter = $sPreviousPrinter _PDFCreator_Printer_Stop($bPreviousStopStatus) $g__oPDFCreator.cClearcache() ; $g__oPDFCreator.cClose() EndIf EndFunc ;==>_PDFCreator_ConvertDocument2 Func _PDFCreator_INIT() __PDFCreator_ObjCreate() If @error Then Return SetError(@error) Else ;~ $g__oPDFCreator.cPrinterStop = False ;~ $g__oPDFCreator.cVisible = True ;~ ObjEvent( "eReady", "_PDFCreator_eReady") ;~ ObjEvent( "eError", "_PDFCreator_eError") EndIf EndFunc ;==>_PDFCreator_INIT Func _PDFCreator_RTF2PDF($sRTF_FileFullPath) _PDFCreator_ConvertDocument2($sRTF_FileFullPath, "PDF") Return @error EndFunc ;==>_PDFCreator_RTF2PDF #EndRegion PDFCreator.au3 - Functions #Region PDFCreator.au3 - AUTOSAVE FUNCTIONS Func _PDFCreator_AutoSave_SetFilePath($sPDF_FileFulllPath, $sOutputDocumentFormat = "PDF") __PDFCreator_ObjCreate() If @error Then Return SetError(@error) Else Local $a_File = StringSplit($sPDF_FileFulllPath, '\') Local $sAutoSaveFileName = $a_File[$a_File[0]] Local $sAutoSaveDirectory = StringTrimRight($sPDF_FileFulllPath, StringLen($sAutoSaveFileName) + 1) $g__oPDFCreator.cOption("UseAutosaveDirectory") = 1 $g__oPDFCreator.cOption("AutosaveDirectory") = $sAutoSaveDirectory $g__oPDFCreator.cOption("AutosaveFilename") = $sAutoSaveFileName _PDFCreator_AutoSave_SetFormat($sOutputDocumentFormat) EndIf EndFunc ;==>_PDFCreator_AutoSave_SetFilePath Func _PDFCreator_AutoSave_SetFormat($sAutoSaveFormat = 'PDF') __PDFCreator_ObjCreate() If @error Then Return SetError(@error) Else Local $sFileExtension = '' Select Case $sAutoSaveFormat = "PDF" $g__oPDFCreator.cOption("AutosaveFormat") = $g_ePDFCreator_Format_PDF $sFileExtension = '.pdf' Case $sAutoSaveFormat = "PNG" $g__oPDFCreator.cOption("AutosaveFormat") = $g_ePDFCreator_Format_PNG $sFileExtension = '.png' Case $sAutoSaveFormat = "JPG" $g__oPDFCreator.cOption("AutosaveFormat") = $g_ePDFCreator_Format_JPG $sFileExtension = '.jpg' Case $sAutoSaveFormat = "BMP" $g__oPDFCreator.cOption("AutosaveFormat") = $g_ePDFCreator_Format_BMP $sFileExtension = '.bmp' Case $sAutoSaveFormat = "PCX" $g__oPDFCreator.cOption("AutosaveFormat") = $g_ePDFCreator_Format_PCX $sFileExtension = '.pcx' Case $sAutoSaveFormat = "TIFF" $g__oPDFCreator.cOption("AutosaveFormat") = $g_ePDFCreator_Format_TIFF $sFileExtension = '.tif' Case $sAutoSaveFormat = "PS" $g__oPDFCreator.cOption("AutosaveFormat") = $g_ePDFCreator_Format_PS $sFileExtension = '.ps' Case $sAutoSaveFormat = "EPS" $g__oPDFCreator.cOption("AutosaveFormat") = $g_ePDFCreator_Format_EPS $sFileExtension = '.eps' Case $sAutoSaveFormat = "ASCII" $g__oPDFCreator.cOption("AutosaveFormat") = $g_ePDFCreator_Format_ASCII $sFileExtension = '.txt' Case Else ; TODO EndSelect Return SetExtended($g__oPDFCreator.cOption("AutosaveFormat"), $sFileExtension) EndIf EndFunc ;==>_PDFCreator_AutoSave_SetFormat Func _PDFCreator_Autosave_Start() __PDFCreator_ObjCreate() If @error Then Return SetError(@error) Else Local $sAutoSaveDirectory = $g__oPDFCreator.cOption("AutosaveDirectory") Local $sAutoSaveFileName = $g__oPDFCreator.cOption("AutosaveFilename") Local $sOUT_FileFulllPath = $sAutoSaveDirectory & '\' & $sAutoSaveFileName _PDFCreator_Printer_Stop(False) ; waiting - $sDest_FileFullPath is not used __PDFCreator_WaitFileIsNotUsed($sOUT_FileFulllPath) ; waiting - all queued documents are done Do Sleep(20) Until $g__oPDFCreator.cCountOfPrintjobs = 0 ; waiting - $sDest_FileFullPath is not used __PDFCreator_WaitFileIsNotUsed($sOUT_FileFulllPath) $g__oPDFCreator.cPrinterStop = True EndIf EndFunc ;==>_PDFCreator_Autosave_Start Func _PDFCreator_AutoSave_State($bNewState = Default) __PDFCreator_ObjCreate() If @error Then Return SetError(@error) Else Local $iPreviousState = $g__oPDFCreator.cOption("UseAutosave") If $bNewState = Default Then Return $iPreviousState If $bNewState Then $g__oPDFCreator.cOption("UseAutosave") = 1 Else $g__oPDFCreator.cOption("UseAutosave") = 0 EndIf Return $iPreviousState EndIf EndFunc ;==>_PDFCreator_AutoSave_State #EndRegion PDFCreator.au3 - AUTOSAVE FUNCTIONS #Region PDFCreator.au3 - PRINTER Func _PDFCreator_CountOfPrintJobs() __PDFCreator_ObjCreate() If @error Then Return SetError(@error) Else Return $g__oPDFCreator.cCountOfPrintjobs EndIf EndFunc ;==>_PDFCreator_CountOfPrintJobs Func _PDFCreator_Printer_GetDefault() __PDFCreator_ObjCreate() If @error Then Return SetError(@error) Else Return $g__oPDFCreator.cDefaultprinter EndIf EndFunc ;==>_PDFCreator_Printer_GetDefault Func _PDFCreator_Printer_SetDefault($sNewDefaultPrinterName) __PDFCreator_ObjCreate() If @error Then Return SetError(@error) Else Local $sPreviousPrinter = $g__oPDFCreator.cDefaultprinter If $g__oPDFCreator.cPrinterIsInstalled Then $g__oPDFCreator.cDefaultprinter = $sNewDefaultPrinterName Return $sPreviousPrinter Else Return SetError($g__ePDFCreator_ERROR_PRINTER_NOT_INSTALED, 0, $sPreviousPrinter) EndIf EndIf EndFunc ;==>_PDFCreator_Printer_SetDefault Func _PDFCreator_Printer_Stop($bStop_NewState = True) __PDFCreator_ObjCreate() If @error Then Return SetError(@error) Else Local $bPreviousStopStatus = $g__oPDFCreator.cPrinterStop ConsoleWrite('$bPreviousStopStatus = ' & $bPreviousStopStatus & @CRLF) ConsoleWrite('$bStop_NewState = ' & $bStop_NewState & @CRLF) If IsBool($bStop_NewState) Then Do Sleep(100) $g__oPDFCreator.cPrinterStop = $bStop_NewState Until $g__oPDFCreator.cPrinterStop = $bStop_NewState If $bStop_NewState = False Then Do Sleep(100) Until $g__oPDFCreator.cCountOfPrintjobs = 0 EndIf ;~ MsgBox(0, '$bStop_NewState=' & $bStop_NewState, $g__oPDFCreator.cPrinterStop) Else ; TODO EndIf ;~ MsgBox(0, '2', $g__oPDFCreator.cPrinterStop) ;$g__oPDFCreator.cClose() Return $bPreviousStopStatus EndIf EndFunc ;==>_PDFCreator_Printer_Stop Func _PDFCreator_PRINTER_TestPage($sPrinterName) __PDFCreator_ObjCreate() If @error Then Return SetError(@error) Else $g__oPDFCreator.cPrintPrinterTestpage($sPrinterName) EndIf EndFunc ;==>_PDFCreator_PRINTER_TestPage Func _PDFCreator_TestPage() __PDFCreator_ObjCreate() If @error Then Return SetError(@error) Else $g__oPDFCreator.cPrintPDFCreatorTestpage() EndIf EndFunc ;==>_PDFCreator_TestPage #EndRegion PDFCreator.au3 - PRINTER #Region PDFCreator.au3 - MISC Func _PDFCreator_OpenDocument($sFileFullPath) If FileExists($sFileFullPath) Then Local $sFile_WorkingDir = StringRegExp($sFileFullPath, '(?i)(.+)\\.+', 3)[0] If Not StringInStr($sFileFullPath, '"') Then $sFileFullPath = '"' & $sFileFullPath & '"' ShellExecute($sFileFullPath, $sFile_WorkingDir, "open", @SW_MAXIMIZE) Else ; TODO EndIf EndFunc ;==>_PDFCreator_OpenDocument Func _PDFCreator_PrintDocument($sFileFullPath) __PDFCreator_ObjCreate() If @error Then Return SetError(@error) Else If FileExists($sFileFullPath) Then Local $sFile_WorkingDir = StringRegExp($sFileFullPath, '(?i)(.+)\\.+', 3)[0] Local $sFileName = StringRegExp($sFileFullPath, '(?i).+\\(.+)', 3)[0] If Not StringInStr($sFileFullPath, '"') Then $sFileFullPath = '"' & $sFileFullPath & '"' Local $sPreviousPrinter = $g__oPDFCreator.cDefaultprinter $g__oPDFCreator.cDefaultprinter = 'PDFCreator' Local $iCountOfPrintJobs = $g__oPDFCreator.cCountOfPrintjobs ShellExecuteWait($sFileName, '', $sFile_WorkingDir, "print", @SW_HIDE) ;~ $g__oPDFCreator.cPrintfile(String($sFileFullPath)) Do Sleep(10) Until $iCountOfPrintJobs <> $g__oPDFCreator.cCountOfPrintjobs If $sPreviousPrinter <> 'PDFCreator' Then $g__oPDFCreator.cDefaultprinter = $sPreviousPrinter Else ; TODO EndIf EndIf EndFunc ;==>_PDFCreator_PrintDocument #EndRegion PDFCreator.au3 - MISC #Region PDFCreator.au3 - HELP - DOC - TODO #CS http://www.freebasic.net/forum/viewtopic.php?f=6&t=21496 dhGetValue( "%s", @szResponse, pdfdoc, ".cWindowsVersion") dhGetValue( "%s", @szResponse2, pdfdoc, ".cPDFCreatorApplicationPath") dhCallMethod(pdfdoc, ".cPrintPDFCreatorTestpage") #CE #CS http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch/Samples~from~Users+wbconvert2pdfcreator.txt eNumber = oPDFC.cErrorDetail("Number") eDetail = oPDFC.cErrorDetail("Description") Message("wbConvert2PDF Error-control",StrCat("Error [%eNumber%]:", eDetail,@CRLF,"This script stops!!")) oPDFC.cOption("FilenameSubstitutionsOnlyInTitle")= 0 ; no substitution oPDFReady=oPDFC.cTestEvent("Ready") oPDFError=oPDFC.cTestEvent("Error") If AppExist("PDFCreator.exe") oPDFC = ObjectGet("PDFCreator.clsPDFCreator") newPDFC = @FALSE Else oPDFC = ObjectCreate("PDFCreator.clsPDFCreator") newPDFC = @TRUE EndIf #CE ;~ http://www.autoitscript.com/forum/topic/42776-pdfcreator-print2pdf/ ;TODO Public PrintAfterSaving As Long ;TODO Public StandardAuthor As String ;Public PDFGeneralResolution As Long ;Public PDFHighEncryption As Long ;Public PDFLowEncryption As Long ;Public LastUpdateCheck As String ;Public PDFOptimize As Long #CS http://www.vbforums.com/showthread.php?444027-PDFCreator-Termination-Need-Help 'Make sure the PDF printer can start If pdfjob.cStart("/NoProcessingAtStartup") = False Then MsgBox "Can't initialize PDFCreator.", vbCritical + _ vbOKOnly, "Error!" Exit Sub End If pdfjob.cCloseRunningSession #CE #CS .cError() As clsPDFCreatorError .cErrorDetail(ByVal PropertyName As String) As Variant .cIsClosed() .cPDFCreatorApplicationPath() .cProgramIsRunning() .cDeletePDFCreatorPrinter(ByVal PrinterName As String) As Boolean .cGetPDFCreatorPrinters() As Collection .cIsAdministrator() As Boolean .cPrinterIsInstalled(ByVal PrinterName As String) As Boolean .cStart(Optional ByVal Params As String, Optional ByVal ForceInitialize As Boolean = False) As Boolean .cPrintFile(ByVal filename As String) .cPrintPDFCreatorTestpage() .cPrintPrinterTestpage(Optional ByVal PrinterName As String) .cPrintURL(ByVal URL As String, Optional ByVal TimeBetweenLoadAndPrint As Long = 0) .cTestEvent(ByVal EventName As String) .cErrorClear() .cConvertFile(ByVal InputFilename As String, ByVal OutputFilename As String, Optional ByVal SubFormat As String = "") ' Allowed values for 'SubFormat': "PDF/A-1b" for "PDF/A-1b"files; "PDF/A-2b" for "PDF/A-2b"files; "PDF/X" for "PDF/X"-files #CE #EndRegion PDFCreator.au3 - HELP - DOC - TODO