Here is my solution to the problem, combining some aspects of the other answers and overcoming limitations of those.
Advantages of this solution:
- Open source solution, thus also available for commercial backgrounds
- Really invisible, silent printing. No windows are popping up
The approach combines several steps:
- Filtering of emails and extraction of the attachments with Filtaquilla in Thunderbird
- A python script to print the files through FoxitReader. Other tools, such as AdobeReader or Ghostscript are not capable of silent printing - a window is visible for AdobeReader for quite a while and even for Ghostscript, a window is popping up.
- A scheduled task to run the python script on a regular basis.
Step 1
All emails are filtered in Thunderbird with Filtaquilla (available for Thunderbird 52.0-60.* as of 2019). Filtering for email sender and subject provides enough "security" for now. Emails are moved to an IMAP subfolder (as an archive for later inspection if anything went wrong). Filtaquilla extracts all attachments to a specified folder (C:\invoices
). Extraction of attachments is not enabled per default in Filtaquilla - be sure to check the settings of Filtaquilla.
Step 2
Place the following print.pyw in C:\invoices
:
import os
import subprocess
import sys
import glob
import time
foxit = "C:\Program Files (x86)\Foxit Software\Foxit Reader\FoxitReader.exe"
script_dir = os.path.dirname(os.path.realpath(__file__))
# get all pdf files
pdf_files = glob.glob(script_dir + "/*.pdf")
# print each pdf and delete it
for pdf_file in pdf_files:
command = []
command.append(foxit)
command.append("/p")
command.append("/h")
command.append(pdf_file)
proc = subprocess.Popen(command, stdout=subprocess.PIPE)
time.sleep(10)
os.remove(pdf_file)
Step 3
In principle, the print.pyw file can be run with Filtaquilla. However, this can result in multiple printing of extracted pdf files if the filter finds more than one email.
To overcome this, a scheduled task (action: run program) is helpful, executed every 10 minutes or so.
- program/script:
"C:\Program Files (x86)\Python36-32\pythonw.exe"
- arguments:
"C:\invoices\print.pyw"
- run in:
C:\invoices\
Please note the missing quotes in the run in field, otherwise the script won't run. It is also important, the script and the extracted files are not located on a network drive!