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
There was only one that sent text data directly and printed it.
adobe PDF Reader
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.
ghost scripter
I found a ghost scripter. However, it was rejected because it was difficult to support Japanese fonts.
foxit reader
"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.
  ## 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.

Recommended Posts

Let's print PDF with python using foxit reader and specify the printer silently!
Behind the flyer: Using Docker with Python
Using Python and MeCab with Azure Databricks
Let's read the RINEX file with Python ①
Working with OpenStack using the Python SDK
Get and estimate the shape of the head using Dlib and OpenCV with python
I'm using tox and Python 3.3 with Travis-CI
Execute raw SQL using python data source with redash and display the result
[Python] Let's execute the module regularly using schedule
[Automation] Extract the table in PDF with Python
Specify the Python executable to use with virtualenv
Let's control EV3 motors and sensors with Python
Solving the Lorenz 96 model with Julia and Python
Archive and compress the entire directory with python
Extract images and tables from pdf with python to reduce the burden of reporting
Let's transpose the matrix with numpy and multiply the matrices.
Try translating with Python while maintaining the PDF layout
[Python] How to specify the download location with youtube-dl
Let's make a simple game with Python 3 and iPhone
Visualize the range of interpolation and extrapolation with python
Convert the image in .zip to PDF with Python
Send and receive Gmail via the Gmail API using Python
Install the latest stable Python with pyenv (both 2 and 3)
Specify MinGW as the compiler to use with Python
Try hitting the Twitter API quickly and easily with Python
I tried using the Python library from Ruby with PyCall
Probably the easiest way to create a pdf with Python3
Let's create a PRML diagram with Python, Numpy and matplotlib.
[Python] LASSO regression with equation constraints using the multiplier method
IP spoof using tor on macOS and check with python
Let's touch the API of Netatmo Weather Station with Python. #Python #Netatmo
Using Python with SPSS Modeler extension nodes ① Setup and visualization
Solve the spiral book (algorithm and data structure) with python!
[Let's play with Python] Image processing to monochrome and dots
Serial communication control with python and I2C communication (using USBGPIO8 device)
Touch NoSQL with Python using the Oracle NoSQL Database Cloud Simulator
Get additional data to LDAP with python (Writer and Reader)
Serial communication control with python and SPI communication (using USBGPIO8 device)
Let's move word2vec with Chainer and see the learning progress
Play with the password mechanism of GitHub Webhook and Python
This and that for using Step Functions with CDK + Python