Fall es jemand benötigt,
Ich habe mal etwas gebastelt, da mir das erstellen von PDFs in Autoit zwar gelingt über die MPdf UDF aber ich leider mit der Form nicht ganz zufrieden bin <.< zu viel abstand und co. fast egal wie ich die Parameter einstelle.
Deshalb dachte ich als Zusatzlösung muss ich doch irgendwie an Microsoft Print to PDF kommen. Also habe ich was geschrieben :
Benötigte UDF´s/Includes sind :
#include <File.au3>
#include <WinAPI.au3>
#include <timers.au3>
#include <MsgBoxConstants.au3>
UDF PrintMgr.au3 (https://www.autoitscript.com/forum/topic/15…management-udf/)
_SwitchPrintToDefaultAndPrint($sFileName, $sFilepath, $destpath = '', $PrinterNameSetDefault = '', $PrinterNameGetDefault = '')
$sFileName : der string wie das File*pdf heißen soll.
$sFilepath : Dort wo sich das File befindet das zur PDF konvertiert werden soll.
$destpath : Dort wo das PDF File dann hin verschoben wird.
$PrinterNameSetDefault = Standard = Microsoft Print to PDF, optional Druckername
$PrinterNameGetDefault = soll den Default drucker am ende wieder auswählen oder beliebigen Druckername
Hier das Script noch eine Gute Nacht an alle :).
#include <File.au3>
#include <WinAPI.au3>
#include <MsgBoxConstants.au3>
#include <printer\PrintMgr.au3>
#include <timers.au3>
example()
Func example()
Local $file = @ScriptDir & '\work.txt'
Local $ret = _SwitchPrintToDefaultAndPrint('filename', $file, @ScriptDir & '\pdf\', '', '')
If $ret = 'ready' Then
MsgBox(0, $ret, 'Erfolg', 5)
ElseIf $ret = 'error' Then
MsgBox(0, $ret, 'Miserfolg')
EndIf
EndFunc ;==>example
Func _SwitchPrintToDefaultAndPrint($sFileName, $sFilepath, $destpath = '', $PrinterNameSetDefault = '', $PrinterNameGetDefault = '')
If FileExists($sFilepath) = 0 Then Return 'error'
If $sFileName = '' Then Return 'error'
If $PrinterNameGetDefault = '' Then $PrinterNameGetDefault = _default_printer()
If $PrinterNameSetDefault = '' Then $PrinterNameSetDefault = 'Microsoft Print to PDF'
If $destpath = '' Then $destpath = @ScriptDir
Local $aPrinterList = _PrintMgr_EnumPrinter()
Local $find = 0
Local $check = 0
Local $tempWIN = '%temp%\'
Local $iTimeOut = 100
Local $file = $sFileName & '.pdf'
If FileExists(@TempDir & '\' & $file) Then FileDelete(@TempDir & '\' & $file)
Do
_CheckUserActivity($check)
If $check = 0 Then ContinueLoop
$msg = MsgBox(53, "Vorausichtlicher Fehler", "Sie haben noch eine oder mehere " & @CRLF & "'Druckausgabe speichern unter' Fenster " & @CRLF & "geöffnet Beenden Sie diese Ordnungsgemäß und drücken Sie auf Wiederholen.", 0)
Switch $msg
Case 5 ;RETRY
_CheckUserActivity($check)
Case 2 ;CANCEL
Return 'ABBRUCH'
EndSwitch
Until $check = 0
For $i = 1 To UBound($aPrinterList) - 1 Step 1
$string = $aPrinterList[$i]
If StringInStr($string, $PrinterNameSetDefault) Then
$find = 1
_WinAPI_SetDefaultPrinter($string)
$iIsPrinted = _FilePrint($sFilepath)
If $iIsPrinted Then
BlockInput(1)
$hDtStart = TimerInit()
Do
ToolTip('Waiting for PDF')
$hwd = _WinLists()
$iDtWait = TimerDiff($hDtStart) / 1000
If $iDtWait > $iTimeOut Then
_WinAPI_SetDefaultPrinter($PrinterNameGetDefault[0])
Exit -2
EndIf
Until $hwd <> ''
WinWaitActive($hwd, '', '')
Sleep(200)
ControlSend($hwd, '', 1001, $tempWIN & $file)
ToolTip('Waiting for PDF Creating')
ControlSend($hwd, '', 1, '!s')
Sleep(200)
BlockInput(0)
_WinAPI_SetDefaultPrinter($PrinterNameGetDefault[0])
ToolTip('End PDF Creating')
ExitLoop
EndIf
EndIf
Next
Sleep(1700)
If $find = 0 Then
ConsoleWrite('wert : ' & $PrinterNameSetDefault & ' treiber nicht vorhanden.' & @CRLF)
Return 'error'
EndIf
If FileExists(@TempDir & '\' & $file) = 1 Then
If FileMove(@TempDir & '\' & $file, $destpath, $FC_CREATEPATH) = 1 Then
Return 'ready'
ElseIf FileMove(@TempDir & '\' & $file, $destpath, 1) = 1 Then
If FileExists($destpath & '' & $file) = 1 Then
Return 'ready'
EndIf
EndIf
ElseIf FileExists(@TempDir & '\' & $file) = 0 Then
Return 'error'
EndIf
EndFunc ;==>_SwitchPrintToDefaultAndPrint
Func _default_printer()
Local $aPrinterListProp = _PrintMgr_EnumPrinterProperties(), $areturn[0]
For $i = 0 To UBound($aPrinterListProp) - 1 Step 1
$name = $aPrinterListProp[$i][6]
$default = $aPrinterListProp[$i][18]
If $default = True Then
_ArrayAdd($areturn, $name)
EndIf
Next
Return $areturn
EndFunc ;==>_default_printer
Func _CheckUserActivity(ByRef $check, $string_language = '')
If $string_language = '' Then $string_language = 'Druckausgabe speichern unter'
Local $aWinListCheck = WinList($string_language)
If $aWinListCheck[0][0] = 0 Then
$check = 0
ElseIf $aWinListCheck[0][0] > 0 Then
$check = 1
EndIf
EndFunc ;==>_CheckUserActivity
Func _WinLists($string_language = '')
If $string_language = '' Then $string_language = 'Druckausgabe speichern unter'
Local $aWinList = WinList($string_language)
ConsoleWrite('fertig' & @CRLF)
If $aWinList[0][0] > 0 Then Return $aWinList[1][1]
EndFunc ;==>_WinLists
Alles anzeigen