Python File as the Default PDF handler for Windows
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. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python File as the Default PDF handler for Windows
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. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python File as the Default PDF handler for Windows
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. -- https://mail.python.org/mailman/listinfo/python-list
Opening PDF Using subprocess.Popen Failing
It actually doesn't fail but it 'cannot open in protected mode' (see here
http://blogs.adobe.com/dmcmahon/2012/07/27/adobe-reader-cannot-open-protected-mode-due-to-a-problem-with-your-system-configuration/)
I am using subprocess.Popen("AcroRe32.exe /n ") which is the actuall
adobe reader command I'd issue on the command line to open the pdf (the /n
option opens it the file in a new instance of reader).
Now, when I issue the command straight from powershell, the pdf opens no
problem, but when I open in my script (whether a .py or py2exe) I get the pop
up complaining that the PDF cannot be opened in 'protected mode.' One of the
options is to open it anyways, which works.
Looking into it (see the link in the first paragraph) my best guess is that
it's due to something like "JS-invoked processes: Launching a process through
JavaScript is not allowed with Protected Mode enabled."
But my naive understanding was that when I give Popen instruction, the command
is handed off to windows and the called program is unaware of how it got
called, so my thinking is that either that is incorrect or windows somehow
'cooperates' with reader to figure things out.
I am looking for *any* insight as to how to deal with this, and the 'turn off
protected mode" option wont work for me.
Here is my code,
outputname = " unlocked.pdf"
commandstr = "qpdf --decrypt " + sys.argv[1] + outputname
os.system(commandstr)
new_command_str = "AcroRd32.exe /n" + outputname
subprocess.Popen(new_command_str)
sys.exit(0)
--
https://mail.python.org/mailman/listinfo/python-list
Re: Opening PDF Using subprocess.Popen Failing
On Friday, June 19, 2015 at 1:25:12 PM UTC-4, Naftali wrote:
> It actually doesn't fail but it 'cannot open in protected mode' (see here
> http://blogs.adobe.com/dmcmahon/2012/07/27/adobe-reader-cannot-open-protected-mode-due-to-a-problem-with-your-system-configuration/)
>
> I am using subprocess.Popen("AcroRe32.exe /n ") which is the
> actuall adobe reader command I'd issue on the command line to open the pdf
> (the /n option opens it the file in a new instance of reader).
>
> Now, when I issue the command straight from powershell, the pdf opens no
> problem, but when I open in my script (whether a .py or py2exe) I get the pop
> up complaining that the PDF cannot be opened in 'protected mode.' One of the
> options is to open it anyways, which works.
>
> Looking into it (see the link in the first paragraph) my best guess is that
> it's due to something like "JS-invoked processes: Launching a process through
> JavaScript is not allowed with Protected Mode enabled."
>
> But my naive understanding was that when I give Popen instruction, the
> command is handed off to windows and the called program is unaware of how it
> got called, so my thinking is that either that is incorrect or windows
> somehow 'cooperates' with reader to figure things out.
>
> I am looking for *any* insight as to how to deal with this, and the 'turn off
> protected mode" option wont work for me.
>
> Here is my code,
>
> outputname = " unlocked.pdf"
>
> commandstr = "qpdf --decrypt " + sys.argv[1] + outputname
> os.system(commandstr)
>
> new_command_str = "AcroRd32.exe /n" + outputname
> subprocess.Popen(new_command_str)
>
> sys.exit(0)
Yes, this is excellent. thank you so much. Will update the list when this works
out.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Opening PDF Using subprocess.Popen Failing
On Friday, June 19, 2015 at 1:25:12 PM UTC-4, Naftali wrote:
> It actually doesn't fail but it 'cannot open in protected mode' (see here
> http://blogs.adobe.com/dmcmahon/2012/07/27/adobe-reader-cannot-open-protected-mode-due-to-a-problem-with-your-system-configuration/)
>
> I am using subprocess.Popen("AcroRe32.exe /n ") which is the
> actuall adobe reader command I'd issue on the command line to open the pdf
> (the /n option opens it the file in a new instance of reader).
>
> Now, when I issue the command straight from powershell, the pdf opens no
> problem, but when I open in my script (whether a .py or py2exe) I get the pop
> up complaining that the PDF cannot be opened in 'protected mode.' One of the
> options is to open it anyways, which works.
>
> Looking into it (see the link in the first paragraph) my best guess is that
> it's due to something like "JS-invoked processes: Launching a process through
> JavaScript is not allowed with Protected Mode enabled."
>
> But my naive understanding was that when I give Popen instruction, the
> command is handed off to windows and the called program is unaware of how it
> got called, so my thinking is that either that is incorrect or windows
> somehow 'cooperates' with reader to figure things out.
>
> I am looking for *any* insight as to how to deal with this, and the 'turn off
> protected mode" option wont work for me.
>
> Here is my code,
>
> outputname = " unlocked.pdf"
>
> commandstr = "qpdf --decrypt " + sys.argv[1] + outputname
> os.system(commandstr)
>
> new_command_str = "AcroRd32.exe /n" + outputname
> subprocess.Popen(new_command_str)
>
> sys.exit(0)
I am running the script via powershell. that sounds very promising. I'm going
to read the link Laura pointed to upthread and see what happens outside
powershell on Monday when I get back to the windows environment.
But thank you for the heads up cause that makes a lot sense.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Opening PDF Using subprocess.Popen Failing
On Friday, June 19, 2015 at 1:25:12 PM UTC-4, Naftali wrote:
> It actually doesn't fail but it 'cannot open in protected mode' (see here
> http://blogs.adobe.com/dmcmahon/2012/07/27/adobe-reader-cannot-open-protected-mode-due-to-a-problem-with-your-system-configuration/)
>
> I am using subprocess.Popen("AcroRe32.exe /n ") which is the
> actuall adobe reader command I'd issue on the command line to open the pdf
> (the /n option opens it the file in a new instance of reader).
>
> Now, when I issue the command straight from powershell, the pdf opens no
> problem, but when I open in my script (whether a .py or py2exe) I get the pop
> up complaining that the PDF cannot be opened in 'protected mode.' One of the
> options is to open it anyways, which works.
>
> Looking into it (see the link in the first paragraph) my best guess is that
> it's due to something like "JS-invoked processes: Launching a process through
> JavaScript is not allowed with Protected Mode enabled."
>
> But my naive understanding was that when I give Popen instruction, the
> command is handed off to windows and the called program is unaware of how it
> got called, so my thinking is that either that is incorrect or windows
> somehow 'cooperates' with reader to figure things out.
>
> I am looking for *any* insight as to how to deal with this, and the 'turn off
> protected mode" option wont work for me.
>
> Here is my code,
>
> outputname = " unlocked.pdf"
>
> commandstr = "qpdf --decrypt " + sys.argv[1] + outputname
> os.system(commandstr)
>
> new_command_str = "AcroRd32.exe /n" + outputname
> subprocess.Popen(new_command_str)
>
> sys.exit(0)
Thank you, Robin, just got in, happy Monday. I don't think it's the path
because I added the acrobat exe to my path env variable which is why it didn't
crash and burn. I tried running it via the standard prompt (as opposed to
powershell) and ran into the same issue but the prompt gave a bit more
information the power shell, in that it said 'open unlocked.pdf: Permission
denied. based on your success I'm thinking that it has to do with the qpdf
creates the file. I'm going to play around with that and will update. thank you
so much for your help.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Opening PDF Using subprocess.Popen Failing
On Friday, June 19, 2015 at 1:25:12 PM UTC-4, Naftali wrote:
> It actually doesn't fail but it 'cannot open in protected mode' (see here
> http://blogs.adobe.com/dmcmahon/2012/07/27/adobe-reader-cannot-open-protected-mode-due-to-a-problem-with-your-system-configuration/)
>
> I am using subprocess.Popen("AcroRe32.exe /n ") which is the
> actuall adobe reader command I'd issue on the command line to open the pdf
> (the /n option opens it the file in a new instance of reader).
>
> Now, when I issue the command straight from powershell, the pdf opens no
> problem, but when I open in my script (whether a .py or py2exe) I get the pop
> up complaining that the PDF cannot be opened in 'protected mode.' One of the
> options is to open it anyways, which works.
>
> Looking into it (see the link in the first paragraph) my best guess is that
> it's due to something like "JS-invoked processes: Launching a process through
> JavaScript is not allowed with Protected Mode enabled."
>
> But my naive understanding was that when I give Popen instruction, the
> command is handed off to windows and the called program is unaware of how it
> got called, so my thinking is that either that is incorrect or windows
> somehow 'cooperates' with reader to figure things out.
>
> I am looking for *any* insight as to how to deal with this, and the 'turn off
> protected mode" option wont work for me.
>
> Here is my code,
>
> outputname = " unlocked.pdf"
>
> commandstr = "qpdf --decrypt " + sys.argv[1] + outputname
> os.system(commandstr)
>
> new_command_str = "AcroRd32.exe /n" + outputname
> subprocess.Popen(new_command_str)
>
> sys.exit(0)
Sadly so far it looks like the only answer is to disable protected mode, either
generally or on a my app basis, which is the same thing because my app will be
registered as the default handler for pdf. So this is a deal breaker. I've even
tried routing the opening through a bat file... so either I get this to open up
in protected mode or I don't see anyway to make it go, with out using a
different reader. But thank you all for your help, will update should I have
any success in this.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Opening PDF Using subprocess.Popen Failing
On Friday, June 19, 2015 at 1:25:12 PM UTC-4, Naftali wrote:
> It actually doesn't fail but it 'cannot open in protected mode' (see here
> http://blogs.adobe.com/dmcmahon/2012/07/27/adobe-reader-cannot-open-protected-mode-due-to-a-problem-with-your-system-configuration/)
>
> I am using subprocess.Popen("AcroRe32.exe /n ") which is the
> actuall adobe reader command I'd issue on the command line to open the pdf
> (the /n option opens it the file in a new instance of reader).
>
> Now, when I issue the command straight from powershell, the pdf opens no
> problem, but when I open in my script (whether a .py or py2exe) I get the pop
> up complaining that the PDF cannot be opened in 'protected mode.' One of the
> options is to open it anyways, which works.
>
> Looking into it (see the link in the first paragraph) my best guess is that
> it's due to something like "JS-invoked processes: Launching a process through
> JavaScript is not allowed with Protected Mode enabled."
>
> But my naive understanding was that when I give Popen instruction, the
> command is handed off to windows and the called program is unaware of how it
> got called, so my thinking is that either that is incorrect or windows
> somehow 'cooperates' with reader to figure things out.
>
> I am looking for *any* insight as to how to deal with this, and the 'turn off
> protected mode" option wont work for me.
>
> Here is my code,
>
> outputname = " unlocked.pdf"
>
> commandstr = "qpdf --decrypt " + sys.argv[1] + outputname
> os.system(commandstr)
>
> new_command_str = "AcroRd32.exe /n" + outputname
> subprocess.Popen(new_command_str)
>
> sys.exit(0)
Well a happy if not completely satisfying ending. So alternative readers worked
ok, but IT was ok with turning off protective mode and also disabling
javascript in adobe reader, considering the relative benign provenance of the
pdf's coming into the system (though I am curious whether or not disabling java
script is actually *more* secure than a sandbox, i.e. can a system be harmed by
rendering a pdf with no java script?
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python File as the Default PDF handler for Windows
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. Just to update, you are correct, Chris, the file short name is passed into sys.argv. didn't need to add anything to the path. But a gotcha -- Windows didn't like my .py, clicking on the pdf causes Windows to complain about 'file x' is not a valid windows executable. I didn't research it so cant speak definitely, but converting the .py to a py2exe correlated with that complaint going away. In the end, though since, making any changes to the program required redoing the py2exe and since this is to be running on a colleagues machine, I ended up putting the handler commands into a .bat file. My hunch is that it's faster that way, too. -- https://mail.python.org/mailman/listinfo/python-list
