LucasKatzer 0 Posted May 25, 2022 Share Posted May 25, 2022 Hello, i have been trying to build a script to print PDF files that are downloaded to an specific folder. For example, as soon as i hit download and the pdf file is downloaded to this folder, the script would automatically print it. Can anybody help me? Link to post Share on other sites
Subz 826 Posted May 26, 2022 Share Posted May 26, 2022 Have a look at: Print files in order as they are shown in a directory - AutoIt GUI Help and Support - AutoIt Forums (autoitscript.com) It uses Sumatra PDF to print, you can modify the script to continuously check a folder, print the file and then move the file into another folder. Link to post Share on other sites
LucasKatzer 0 Posted May 26, 2022 Author Share Posted May 26, 2022 The biggest problem for me is that the files we print need some specific print options only available in adobe reader. Otherwise it won't get printed correctly. Link to post Share on other sites
Subz 826 Posted May 26, 2022 Share Posted May 26, 2022 Unfortunately Adobe Reader is harder to control, since it leaves the application open so you're unable to move the files afterwards unless, you force close Adobe Reader basic example: expandcollapse popup#include <File.au3> HotKeySet("+{ESC}", "_Exit") ;~ Printer Name Global $g_sPrinter = "Printer name" ;~ Adobe Acrobat Reader executable Global $g_sAdobeReader = "Acrord32.exe" ;~ Downloads folder Global $g_sDownloadDir = @ScriptDir & "\Downloads" If Not FileExists($g_sDownloadDir) Then DirCreate($g_sDownloadDir) ;~ Printed folder Global $g_sPrintedDir = @ScriptDir & "\Downloads\Printed" If Not FileExists($g_sPrintedDir) Then DirCreate($g_sPrintedDir) ;~ Check Downloads folder every 5 seconds AdlibRegister("_PrintPDF", 5000) While 1 Sleep(100) WEnd Func _Exit() Exit EndFunc Func _PrintPDF() ;~ Check for any .pdf files in Downloads folder Local $aFileList = _FileListToArrayRec($g_sDownloadDir, "*.pdf", 1, 0, 0, 0) ;~ No files found, continue waiting If @error Then Return ;~ Loop through list of pdf files For $i = 1 To $aFileList[0] ;~ Print each pdf file to Adobe Acrobat Reader to specified printer ShellExecute($g_sAdobeReader, '/N /T "' & $g_sDownloadDir & "\" & $aFileList[$i] & '" "' & $g_sPrinter & '"') ;~ Wait 3 seconds between printing Sleep(3000) Next ;~ Force close opened Adobe Acrobat Reader processes While ProcessExists($g_sAdobeReader) ProcessClose($g_sAdobeReader) WEnd ;~ Move printed files above to Printed folder For $i = 1 To $aFileList[0] ;~ Overwrites any existing file with the same name in Printed folder ;~ Altenatively you can move the file with a unique name example: ;~ FileMove($g_sDownloadDir & "\" & $aFileList[$i], $g_sPrintedDir & "\" & @YEAR & "-" & @MON & "-" & @MDAY & "_" & @HOUR & @MIN & @SEC & $aFileList[$i]) FileMove($g_sDownloadDir & "\" & $aFileList[$i], $g_sPrintedDir & "\" & $aFileList[$i], 1) Next EndFunc Link to post Share on other sites
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