Python Forum

Full Version: Printing PDF files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to create an application to automate a file creation process, but the first thing that I need to print out is a PDF file. I've tried to just use startfile() and import os, but I get the error:

Error:
Traceback (most recent call last): File "C:\Users\christopher.donnelly\PycharmProjects\HelloWorld\JobFileAutomation\JobFileAutomation.py", line 5, in <module> os.startfile(filename, "print") OSError: [WinError 1155] No application is associated with the specified file for this operation: 'Y:\\company orders\\C-Active Orders\\281794 Customer\\1-Sales\\281794 Customer OA.pdf'
and my code is only a few lines:

import os

filename = r'Y:\company orders\C-Active Orders\281794 Customer\1-Sales\281794 Customer OA.pdf'
os.startfile(filename, "print")
Why does the print option not work for a PDF file but it works for a text file? Does it need to be able to read the contents of the file to print it?
The error indicates that there is no default application associated with the PDF file type on your OS.
The os.startfile() function relies on the default program associated with the file type to handle the print command.
(Jul-11-2024, 10:45 AM)snippsat Wrote: [ -> ]The error indicates that there is no default application associated with the PDF file type on your OS.
The os.startfile() function relies on the default program associated with the file type to handle the print command.

I'm downloading adobe acrobat reader just now. I didn't think of just downloading a PDF application- sometimes it's too easy to overcomplicate things lol

Edit: thanks for the help, lucky I have an adobe license which I should have been using in the first place!