PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 15, 2022

[FIXED] How to print pdf file without opening PDF viewer print prompt in python

 September 15, 2022     adobe, pdf, printing, python, windows     No comments   

Issue

I'd like to print a PDF file by Python, without opening any PDF viewer program (ex. adobe).

I have tried some code. It pop up the adobe program before printing.

first code

import win32print
import win32api

currentprinter = win32print.GetDefaultPrinter()
win32api.ShellExecute(0, "print", 'report.pdf', currentprinter,  ".",  0)

second code

import os

os.startfile("report.pdf", "print")

Any code I have to rewrite or any recommend program to use instead of adobe?


Solution

  1. download PDFtoPrinter.exe and move it into folder.

  2. code it.

    import subprocess
    
    def command_print(event = None):
    
        command = "{} {}".format('PDFtoPrinter.exe','report.pdf')
    
        subprocess.call(command,shell=True)
    
    command_print()
    


Answered By - Vittawat Laorungroj
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing