Quantcast

Python File as the Default PDF handler for Windows

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Python File as the Default PDF handler for Windows

Naftali
Long time lurker.

I'm looking to register a python script as the default pdf reader for windows. I assume I can just register the .py in the section windows section for registering default handlers, but I'm wondering how to access the file from within the program.

The issue is this:

We have Java application that outputs user uploaded pdf files. It does this simply by instructing windows to open the downloaded pdf file and windows takes it from there. The data entry person will view the pdf and usually upload it into another part of the system. Problem is the second leg of the system modifies the pdf, and thus crashes when the pdf is protected against writing. Data entry make use of a program to unlock them as needed but it is an extra step and it only comes to their awareness after their client crashes on the locked pdf (because it doesn't make sense to check them proactively.

I cannot change the Java system.

What I want to do is write a pdf handler to handle windows open instruction. In the script I would run a command line pdf unlocker on the file and open the unlocked file with adobe (or the like).

I've googled and though I get tons of 'how to open pdf from a python script' I haven't found anything describing how to write and set up my python program to deal with the pdf hand-off from the OS.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Python File as the Default PDF handler for Windows

Chris Angelico
On Fri, Jun 19, 2015 at 7:04 AM, Naftali <nmichalowsky at gmail.com> wrote:
> What I want to do is write a pdf handler to handle windows open instruction. In the script I would run a command line pdf unlocker on the file and open the unlocked file with adobe (or the like).
>
> I've googled and though I get tons of 'how to open pdf from a python script' I haven't found anything describing how to write and set up my python program to deal with the pdf hand-off from the OS.
>

Possibly the reason you've found nothing is that this isn't actually a
Python issue :) What you want to do is tell your OS that when you
double-click on a PDF, it should run this program. That's better
referred to as "file associations". Different versions of Windows put
that in different places, but poke around in your GUI or on the
internet and you should be able to find something on updating
associations.

If you're having trouble getting a Python program to run in that
situation, it may help to explicitly name a Python interpreter - an
executable binary.

ChrisA

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Python File as the Default PDF handler for Windows

Naftali
In reply to this post by Naftali
On Thursday, June 18, 2015 at 5:05:15 PM UTC-4, Naftali wrote:

> Long time lurker.
>
> I'm looking to register a python script as the default pdf reader for windows. I assume I can just register the .py in the section windows section for registering default handlers, but I'm wondering how to access the file from within the program.
>
> The issue is this:
>
> We have Java application that outputs user uploaded pdf files. It does this simply by instructing windows to open the downloaded pdf file and windows takes it from there. The data entry person will view the pdf and usually upload it into another part of the system. Problem is the second leg of the system modifies the pdf, and thus crashes when the pdf is protected against writing. Data entry make use of a program to unlock them as needed but it is an extra step and it only comes to their awareness after their client crashes on the locked pdf (because it doesn't make sense to check them proactively.
>
> I cannot change the Java system.
>
> What I want to do is write a pdf handler to handle windows open instruction. In the script I would run a command line pdf unlocker on the file and open the unlocked file with adobe (or the like).
>
> I've googled and though I get tons of 'how to open pdf from a python script' I haven't found anything describing how to write and set up my python program to deal with the pdf hand-off from the OS.

Thank you for responding, Chris:

I may be missing something in your reply, but I am *not* wondering how to associate python with the .pdf file extension. That I know how to do. What I want to know is how from within the program that I've told windows to run when the user clicks on the file --- how to access the file that the user wishes to open. Windows must somehow make that available to my program. How to I access it. Tomorrow, I'll try doing it an looping through the sys.argvs and see what's there. maybe it's a simple as passing a path into the called program.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Python File as the Default PDF handler for Windows

Chris Angelico
On Fri, Jun 19, 2015 at 11:03 AM, Naftali <nmichalowsky at gmail.com> wrote:
> I may be missing something in your reply, but I am *not* wondering how to associate python with the .pdf file extension. That I know how to do. What I want to know is how from within the program that I've told windows to run when the user clicks on the file --- how to access the file that the user wishes to open. Windows must somehow make that available to my program. How to I access it. Tomorrow, I'll try doing it an looping through the sys.argvs and see what's there. maybe it's a simple as passing a path into the called program.
>

Oh! I see what you mean. You should get the full path and name of the
file in sys.argv, but if you don't, I think what you need to do is add
"%s" to the end of the association definition. My apologies for the
prior misunderstanding.

ChrisA

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Python File as the Default PDF handler for Windows

Naftali
In reply to this post by Naftali
On Thursday, June 18, 2015 at 5:05:15 PM UTC-4, Naftali wrote:

> Long time lurker.
>
> I'm looking to register a python script as the default pdf reader for windows. I assume I can just register the .py in the section windows section for registering default handlers, but I'm wondering how to access the file from within the program.
>
> The issue is this:
>
> We have Java application that outputs user uploaded pdf files. It does this simply by instructing windows to open the downloaded pdf file and windows takes it from there. The data entry person will view the pdf and usually upload it into another part of the system. Problem is the second leg of the system modifies the pdf, and thus crashes when the pdf is protected against writing. Data entry make use of a program to unlock them as needed but it is an extra step and it only comes to their awareness after their client crashes on the locked pdf (because it doesn't make sense to check them proactively.
>
> I cannot change the Java system.
>
> What I want to do is write a pdf handler to handle windows open instruction. In the script I would run a command line pdf unlocker on the file and open the unlocked file with adobe (or the like).
>
> I've googled and though I get tons of 'how to open pdf from a python script' I haven't found anything describing how to write and set up my python program to deal with the pdf hand-off from the OS.


Thank you, Chris.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Python File as the Default PDF handler for Windows

MRAB-2
In reply to this post by Chris Angelico
On 2015-06-19 02:18, Chris Angelico wrote:
> On Fri, Jun 19, 2015 at 11:03 AM, Naftali <nmichalowsky at gmail.com> wrote:
>> I may be missing something in your reply, but I am *not* wondering how to associate python with the .pdf file extension. That I know how to do. What I want to know is how from within the program that I've told windows to run when the user clicks on the file --- how to access the file that the user wishes to open. Windows must somehow make that available to my program. How to I access it. Tomorrow, I'll try doing it an looping through the sys.argvs and see what's there. maybe it's a simple as passing a path into the called program.
>>
>
> Oh! I see what you mean. You should get the full path and name of the
> file in sys.argv, but if you don't, I think what you need to do is add
> "%s" to the end of the association definition. My apologies for the
> prior misunderstanding.
>
I don't think it should be "%s", but "%*".

This has more details:

https://technet.microsoft.com/en-us/library/bb490912.aspx


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Python File as the Default PDF handler for Windows

Chris Angelico
On Fri, Jun 19, 2015 at 11:39 AM, MRAB <python at mrabarnett.plus.com> wrote:
> I don't think it should be "%s", but "%*".

Thanks, it's been a while since I fiddled with Windows associations.

ChrisA

Loading...