Jump to content

Print PDF files automatically

Recommended Posts

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

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:

#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

Func _Exit()

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

    ;~ Force close opened Adobe Acrobat Reader processes
    While ProcessExists($g_sAdobeReader)

    ;~ 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)



Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...