I am working with Python 3.6.6 and need to display several pdf-files in the browser.
I tried several pdf files and got 2 different results.
For example:
import webbrowser
webbrowser.open('https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/pdf_reference_archives/PDFReference.pdf')
opens a new tab in my browser and displays the file.
Other files are downloaded immediatelly, instead of displaying in a new tab in the browser.
I want to know the reason for, why some files are downloaded automatically and others are displayed in the browser, where I can manually download the file.
I need a solution where I can force the file to open in the browser.
I already read through this question but it seems it is more restricted to HTML.
One last thing I noticed. If I try to download any pdf file from the internet it opens the file in a new tab. The problem with downloading them only appears with files which are saved on a webserver within my company.
Is this just a missing configuration on the webserver?
If yes, is it anyhow possible to get around this configuration using python?
It's the web-browser's decision whether to put the file in the downloads directory (and not display it) or whether to cache the file and open it in-browser. As such, do not use the web-browser installed on the end-user's system.
Instead, have your program include its own web-browser. Open the pdf (and everything else your program displays) in your program's web-browser. That way, you can always modify your program's web-browser to view files in-browser instead of saving to the downloads directory.
Several free open-source web-browsers are available on the market. Just use one of them.
Related
For the past month I've been writing a desktop application for MacOS using Python. It requires opening files and saving compressed data to them. This application creates files using a my own made up extension, so the files are not usable for for other applications. I have almost everything figured out. However, I want to make it so that I can right click on a file with the extension and open it with my python application. I tried using sys.argv to get any arguments for the path of the file to open, but that doesn't work. I know there has to be a way. Preferably there's a builtin variable that is easy to use, but I haven't found anything that helps.
Any help would be useful.
Thanks.
I am trying to make a simple program that closes a specific folder every time it gets opened to deny access to said folder. I've tried using VBScript , and the codes I was given worked at first, but they failed after some circumstances (like trying to open the specific folder a lot of times in quick succession, or sometimes even after closing an unrelated folder).
The folder I'm trying to close is C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
I am having a problem with PyCharm (Community Edition) in that, when I open a .py file in the program, I can happily read and write in the file as usual, however when I click out of PyCharm (to look my emails for example) and then click back into it to carry on with my code, the file automatically closes and the project tree structure collapses (so I have to re-open it every time).
So far I have tried changing the tab limit to a high number, but this doesn't seem to help (and it shouldn't be related, since this happens when I open just one file).
I had the same issue before. I'm assuming you're connected to a network shared folder via UNC path (e.g. \\foo\bar\)?
If so, it is not currently supported. You'll need to map your network folder and give it a Drive letter. Then load up your project using the mapped drive, and it'll work like a charm.
If that's not the scenario though, please give us more information.
With Selenium Webdriver, I have to upload some files on a website but since the pop-up window for browsing the file location is handled by the operating system and not the browser, I cannot automate that part with Selenium.
So I want to know which framework or module I need to use to work with system windows of Windows OS. Can tkInter or wxPython be used for this?
My script will be used on Windows 7, 8 & 10.
Actually, you can upload files without interacting with upload prompt pop-ups.
To be able to handle file upload with selenium you should send path to file to appropriate input field without clicking on "Upload" button. Try following:
path_to_file = 'C:\\Files\\path\\to\\file' # use your specific path instead
driver.find_element_by_xpath('//input[#type="file"]').send_keys(path_to_file)
P.S. Let me know if this code doesn't work as you expect
You can call autoit3 framework from Python even to open the File Open dialog and fill in the values and press OK or do whatever with the windows. Autoit3 has a dll that can be loaded and called using ctypes. That's what I did in one or 2 projects.
If I understand your question correctly, wxpython or tk won't help you. They can be used to make the windowed UI, not to control other programs.
I am facing a strange problem
Whenever my python scripts are creating any csv file, it is making them "Archive".
I mean in properties, Archive check box is checked.
Because of which it can't be read in later part of same script .
How can i create a csv file not archive?
Please help me resolve this problem.
Are you running a Windows OS? If yes, then this is not a problem with the Python CSV library. As about the error encountered while reading the CSV; you may want to re-check your python code for any flaws.
The Archive checkbox is actually an attribute of the file on Windows systems that indicates that the file needs to be backed up. Right click on any other file and you should see "Archive" checked.
Here are a couple of links that would give you more information
MSDN Technet discussion on File Attributes
Wikipedia article on Archive bit