orvqb99d5e2u
Goto Top

Automatischer PDF Druck auf spezifischen Drucker

Hi. Ich benötige für einen Windows Server ein Script mit folgenden Eigenschaften:

Order1 soll überprüft werden, wenn dort neue PDF Dokumente liegen sollen sie auf Drucker 1 gedruckt werden. Anschließend sollen die gedruckten PDF Dateien in Ordner1_Archiv verschoben werden.
Order2 soll überprüft werden, wenn dort neue PDF Dokumente liegen sollen sie auf Drucker 2 gedruckt werden. Anschließend sollen die gedruckten PDF Dateien in Ordner2_Archiv verschoben werden.
Die Überprüfung auf neue PDF Dateien soll alle 60 Sekunden erfolgen.

Ich habe so ein ähnliches Script welches vor ~8 Jahren mit Autoit erstellt wurde, jedoch weiß ich nicht wie ich da den Druck auf einem spezifischen Drucker auswählen kann, und vermutlich ist es überhaupt nicht mehr zeitgemäß. Der dort erfolgte vorherige Emailversand wird auch nicht mehr benötigt.

$g_szVersion = 'PDF Mailer'  
If WinExists($g_szVersion) Then Exit; It's already running  
AutoItWinSetTitle($g_szVersion)

Opt("RunErrorsFatal", 0)  
Opt("TrayAutoPause", 0)  

Global $Sender, $Recipient, $MailUser, $MailPass
Global $Enable_Encryption = True
If $CmdLine > 0 Then
	If StringInStr($CmdLine[1], "deutschland") AND StringInStr($CmdLine[1], "polen") Then Exit ;;can't run both at the same time!  
	If StringInStr($CmdLine[1], "deutschland") Then  
		$Sender = 'pdfmail_de@unkown.de'  
		$Recipient = 'pdfmail_pl@unkown.de'  
		$MailUser = 'user'  
		$MailPass = 'pass'  
	ElseIf StringInStr($CmdLine[1], "polen") Then  
		$Sender = 'pdfmail_pl@unkown.dee'  
		$Recipient = 'pdfmail_de@unkown.de'  
		$MailUser = 'user'  
		$MailPass = 'pass'  
	ElseIf StringInStr($CmdLine[1], "/?") Then  
		MsgBox(32, $g_szVersion, "This program has two arguments, which must be in order." & @CRLF & _  
		"The first argument is country, which can either be deutschland or polen." & @CRLF & @CRLF & _  
		"The second argument is optional, controlling encryption." & @CRLF & _  
		"Passing noencrypt as the second argument will disable encryption")  
		Exit
	Else
		Exit
	EndIf
	If $CmdLine > 1 Then
		If StringInStr($CmdLine[2], "noencrypt") Then $Enable_Encryption = False  
	EndIf
Else
	Exit
EndIf

#region Configuration Settings
Global Const $Blowfish_Password = 'pass'  

Global Const $POP3Server = 'pop3.unkown.de'  
Global Const $SMTPServer = 'smtp.unkown.de'  

;SendMail Configuration
Global Const $SendMail = 'C:\scanner\scanner_de\sendmail'  
Global Const $PDF_Dir = 'C:\scanner\sendmail\Emails'  

;GetMail Configuration
Global Const $GetMail = 'C:\scanner\getmail'  
Global Const $source = 'C:\scanner\getmail\Emails' ; Location of encrypted PDF files  
Global Const $dest = 'C:\scanner\getmail\Emails\Archives' ; Location of decrypted PDF files  
Global Const $GSPrintDir = 'C:\scanner\Print\Ghostgum\gsview' ;Path to PDF Printer Program  

#endregion Configuration Settings

#region Do Not Edit!!!!!

#region GetMail Functions
Func GetMail()
	If Not FileExists($source) Then DirCreate($source)
	If Not FileExists($dest) Then DirCreate($dest)
	FileChangeDir($GetMail)

	RunWait('getmail.exe -u ' & $MailUser & ' -pw ' & $MailPass & ' -s ' & $POP3Server & ' -xtract -delete', '', @SW_HIDE)  
	FileDelete('*.txt')  
	FileDelete('*.out')  
	FileMove('*.pdf', $source & '\*.pdf', 1)  
	Sleep(1000)

	Local $file = FileFindFirstFile($source & '\*.pdf')  
	If $file = -1 Then Return 0
	While 1
		Local $pdffile = FileFindNextFile($file)
		If @error Then ExitLoop
		If $Enable_Encryption Then
			RunWait('bfish.exe /I:"' & $source & '\' & $pdffile & '" /O:"' & $dest & '\' & $pdffile & '" /P:"' & $Blowfish_Password & '" /D /Q', "", @SW_HIDE)  
			If FileExists($dest & '\' & $pdffile) Then  
				;File successfully decrypted, print it!
				Local $WorkingDir = @WorkingDir
				FileChangeDir($GSPrintDir)
				RunWait('gsprint.exe "' & $dest & '\' & $pdffile & '"', $GSPrintDir, @SW_HIDE)  
				FileChangeDir($WorkingDir)
			EndIf
		Else
			FileMove($source & '\*.pdf', $dest & '\')  
			Local $WorkingDir = @WorkingDir
			FileChangeDir($GSPrintDir)
			RunWait('gsprint.exe "' & $dest & '\' & $pdffile & '"', $GSPrintDir, @SW_HIDE)  
			FileChangeDir($WorkingDir)
		EndIf
		While FileExists($source & '\' & $pdffile)  
			FileDelete($source & '\' & $pdffile) ;delete the encrypted version  
		WEnd
	WEnd
	FileClose($file)
	Return 1
EndFunc   ;==>GetMail
#endregion

#region SendMail Functions
Func SendMail()
	If Not FileExists($PDF_Dir) Then DirCreate($PDF_Dir)
	If Not FileExists($PDF_Dir & '\Encrypted\') Then DirCreate($PDF_Dir & '\Encrypted\')  
	If Not FileExists($PDF_Dir & '\Archives\') Then DirCreate($PDF_Dir & '\Archives\')  
	If Not FileExists($PDF_Dir & '\*.pdf') Then Return 0  

	Local $PDFfiles[1]
	FileChangeDir($SendMail)
	Local $PDFHandle = FileFindFirstFile($PDF_Dir & '\*.pdf')  
	While 1
		Local $file = FileFindNextFile($PDFHandle)
		If $file <> '' Then  
			ReDim $PDFfiles[ (UBound($PDFfiles) + 1) ]
			$PDFfiles += 1
			$PDFfiles[ (UBound($PDFfiles) - 1) ] = $file
		Else
			ExitLoop
		EndIf
	WEnd
	FileClose($PDFHandle)

	For $x = 1 To $PDFfiles
		If $Enable_Encryption = True Then
			RunWait('bfish.exe /I:"' & $PDF_Dir & '\' & $PDFfiles[$x] & '" /O:"' & $PDF_Dir & '\Encrypted\' & $PDFfiles[$x] & '" /P:"' & $Blowfish_Password & '" /E /Q', "", @SW_HIDE)  
			FileSend($PDFfiles[$x], $PDF_Dir & '\Encrypted\' & $PDFfiles[$x])  
		Else
			FileSend($PDFfiles[$x], $PDF_Dir & '\' & $PDFfiles[$x])  
		EndIf
			FileMove($PDF_Dir & '\' & $PDFfiles[$x], $PDF_Dir & '\Archives\' & $PDFfiles[$x])  
			FileDelete($PDF_Dir & '\Encrypted\' & $PDFfiles[$x])  
	Next
	Return 1
EndFunc   ;==>SendMail

Func FileSend($FileName, $Attachment)

	Local $objMessage = ObjCreate('CDO.Message')  
	With $objMessage
		.Subject = $FileName
		.Sender = $Sender
		.From = $Sender
		.To = $Recipient
		.TextBody = $FileName & ' is attached and encrypted.'  
		.AddAttachment ($Attachment)
	EndWith

	With $objMessage.Configuration.Fields
		.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2  
		.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $SMTPServer  
		.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1  
		.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $MailUser  
		.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $MailPass  
		.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25  
		.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60  
		.Update
	EndWith
	$objMessage.Send
	Return 1
EndFunc   ;==>FileSend
#endregion

Func _ReduceMemoryUsage()
	Local $ai_GetCurrentProcessId = DllCall('kernel32.dll', 'int', 'GetCurrentProcessId')  
	Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $ai_GetCurrentProcessId)  
	Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle)  
	DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle)  
	Return $ai_Return
EndFunc
#endregion Do Not Edit

While 1
	If (@Hour >= 7) AND ((@HOUR & @MIN) <=1630) Then
		GetMail()
		Sleep(1000 * 15) ;;Wait for 15 seconds
		SendMail()
	EndIf
	_ReduceMemoryUsage()
	Sleep(1000 * 60 * 4.75) ;;Wait for 5 minutes
WEnd

Welche Programmiersprache wäre aktuell am besten für dieses Vorhaben geeignet? Kann evtl. jemand das Script relativ einfach anpassen?

Content-Key: 304196

Url: https://administrator.de/contentid/304196

Printed on: April 23, 2024 at 23:04 o'clock

Mitglied: 129148
129148 May 11, 2016 at 09:37:25 (UTC)
Goto Top
Member: Pjordorf
Pjordorf May 11, 2016 at 10:33:23 (UTC)
Goto Top
Hallo,

Zitat von @Orvqb99d5E2U:
vor ~8 Jahren mit Autoit erstellt wurde, und vermutlich ist es überhaupt nicht mehr zeitgemäß.
Warum nicht?
https://www.autoitscript.com/site/autoit/
https://autoit.de/
https://de.wikipedia.org/wiki/AutoIt

Gruß,
Peter
Member: Orvqb99d5E2U
Orvqb99d5E2U May 11, 2016 at 10:44:57 (UTC)
Goto Top
Damit meinte ich nicht, dass Autoit veraltet ist, sondern der Code ansich. So lässt er sich z.B. auch nicht mehr kompilieren.
Member: Pjordorf
Pjordorf May 11, 2016 updated at 14:57:06 (UTC)
Goto Top
Hallo,

Zitat von @Orvqb99d5E2U:
sondern der Code ansich. So lässt er sich z.B. auch nicht mehr kompilieren.
Warum lässt er sich nicht Kompilieren bzw. wo hakt es denn?
Sollen wir jetzt deine Arbeit tun?

Gruß,
Peter