Let's print PDF with python using foxit reader and specify the printer silently!
Development environment
os:windows10
Language: python3.7
Software to use: foxit reader
About installing foxit reader
It is easy to download the free version from the window company.
https://forest.watch.impress.co.jp/library/software/foxitreader/
If you try to download from the official website, it seems that you need to register your e-mail address etc. even for the free version (viewing / printing only).
Printing requirements that I needed
・ Documents in a slightly complicated format are okay.
・ Printing speed is fast (1 second)
-It is a simple procedure.
How to print python
- win32 dt>
- There was only one that sent text data directly and printed it. dd>
- adobe PDF Reader dt>
- Print using adobe PDF Reader commands.
Created with reference to the following article.
https://qiita.com/hrs_sano645/items/e0fcf5d896b70822e998
Initially it was planned to adopt this, but at the implementation stage
It was discovered that it took about 3 seconds to come out from printing.
There are times when the CPU occupancy rate goes up to 100% for a moment.
The GUI screen of adobe PDF Reader is displayed.
This seeks a different way. dd>
- ghost scripter dt>
- I found a ghost scripter.
However, it was rejected because it was difficult to support Japanese fonts. dd>
- foxit reader dt>
- "From now on, PDF will be in the age of red to orange."
A full-blown promotional phrase jumps in
Competitive software for adobe PDF reader
There are many advantages of functions that are not defeated by the complaint!
The printing speed of text-based PDF is extremely fast.
(The scanned PDF is about the same speed.)
When printing from a command, the GUI screen is not displayed and silent printing is possible.
CPU usage is 50% or less
The command is similar to the command format of adobe, so you can learn it immediately. dd>
## Follow the steps below to implement.
Please install foxit reader as standard.
If this is the case, I just installed foxit reader.
From here is magma-style programming.
-Copy and paste the source code of foxit.py below
-Control Panel> "Devices and Printers"> Right-click the printer name you want to use> Printer Properties> Copy the printer name without making a mistake> Copy the printer name to "Printer Name" in the source code
-Copy and paste the path of the PDF file you want to print into the source code'pdf_name'
Run! Yeah!
Explosive printing is now possible!
The command line is created by referring to the following.
https://www.lifedesignedit.com/use_foxit_pdf_command_line_options
foxit.py
#foxit_Print via reader
import subprocess
#This is when a printer is specified.
#You can also use the default printer.
#For more information, start Foxit Reader and help>With command line options
def print_PDF_file_via_foxitReader(self,pdf_name,printer_name):
#The foxit path is for a standard installation. It may be different depending on the environment.
foxit_exe = r"C:\Program Files (x86)\Foxit Software\FoxitReader\FoxitReader.exe"
print_cmd = '"{}" /t "{}" "{}"'.format(foxit_exe,pdf_name,printer_name)
subprocess.Popen(print_cmd)
if __name__ == '__main__':
pdf_name = 'pdf_name'
print_name = 'Printer name'
print_PDF_file_via_foxitReader(pdf_name,printer_name)
Please let me know if you make any mistakes.