Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pyinstaller + win32print
#1
Hello everyone, I’ll say right away that I’m new to programming, I mainly use GPT chat. The essence of the problem is that there is code in Python, and it works. But when I compile it into an exe file and transfer it to another machine, it stops sending it to print. in the code I use import win32print. When compiling, I don’t see anywhere a mention that such a method was added to my executable file.
There are no errors, just don’t print and that’s it, although the printer itself finds it, this is displayed in the log file.
Tell me, has anyone encountered this problem? how to solve or get around it in another way.
I apologize for my English, I used Google translator
def print_pdf(self, pdf_file_path):
        
        with open('logfile.txt', 'w') as file:
            try:
                default_printer = win32print.GetDefaultPrinter()
                print("test 1:", default_printer, file=file)
                                
                printer_handle = win32print.OpenPrinter(default_printer)
                print("test 2:", printer_handle, file=file)
                
                print_pdf_alternative(pdf_file_path, default_printer)
                print("test 3:", printer_handle, file=file)
                
                win32print.ClosePrinter(printer_handle)

            except Exception as e:
                logging.error(f'Error occurred while printing: {str(e)}')
in the log file on the new PC there is an entry only for test 1 and 2, on the PC where Python is installed all 3 tests pass and printing works

Thank you.
Reply
#2
I'll answer my own question. Since I’m not good at programming yet, I don’t fully understand the principle of operation, and it turned out that the win32print method still compiles normally, it’s just that on those PCs on which I tested (these were ordinary, almost clean test machines), no pdf reader. And to print a PDF file, you had to open it with something and send it for printing, and it turns out that Windows didn’t know how to open it. Although if it’s just under Windows, it would open with a regular browser without any problems. so I didn’t immediately understand the reason. Thanks to all.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  win32print FritsCornelius 1 8,726 May-19-2020, 10:41 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020