As a part of my program I was trying to, as the title suggests, open a pdf file in a web browser on a specific page so reading the contents of that pdf page and printing it via pdfplumber or PyPDF2 won't really do.
I tried searching up methods to do so but to no avail, any help would be appreciated.
I am writing a python code which writes a hyperlink into a excel file.This hyperlink should open in a specific page in a pdf document.
I am trying something like
Worksheet.write_url('A1',"C:/Users/...../mypdf#page=3") but this doesn't work.Please let me know how this can be done.
Are you able to open the pdf file directly to a specific page even without xlsxwriter? I can not.
From Adobe's official site:
To target an HTML link to a specific page in a PDF file, add
#page=[page number] to the end of the link's URL.
For example, this HTML tag opens page 4 of a PDF file named
myfile.pdf:
Note: If you use UNC server locations (\servername\folder) in a link,
set the link to open to a set destination using the procedure in the
following section.
If you use URLs containing local hard drive addresses (c:\folder), you cannot link to page numbers or set destinations.
I'd like to download multiple files from a single website, but the biggest quirk I have is that the server automatically generates a random filename upon requesting the file to download. The issue here is then I won't know which file is which, without having to manually go through each file. However, on the site that has the links to download the files, they all have a name. For example...
File name -> Resultant file name(fake file names)
Week1.pdf 2asd123e.pdf
Week1_1.jpg dsfgp142.jpg
.
.
Week10.pdf 19fgmo2o.pdf
Week11.pdf 0we5984w.pdf
If I were to download them manually by myself, I would type click "download" and a popup "Save as" menu comes up, which gives me the option to change the file name manually, then click ok to confirm the download, to which it starts downloading.
Currently, my code is made to open up the website, log into my account, go to the files page, and then find a file, with it's corresponding server request link. IE: . I am able to store the name of the file, "Week1.pdf" into a variable, and click on the request link, but the only problem is that the Save as menu, doesn't have the ability to change the name of the filename, and only gives me the option to view the file, or Save the file immediately. I've looked around a little, and tried to play around with the Firefox profile settings, but nothing has worked. How would I go about solving this problem?
Thanks
I can think of a few things that you might try...
After the file is saved, look in the downloads folder for the most recently saved file (with the correct extension) using time stamps. This will probably be OK as long as you aren't running this threaded.
Get the list of files in the download directory, download the file, find the file that doesn't exist in the list of files. Again this should be safe unless you are running this threaded.
Create a new folder, set the download directory to the newly created folder, download the file. It should be the only file in that directory. As far as I know, you can only set the download directory before creating the driver instance.
In each of these cases, if you plan to download multiple files I would rename each file as you download them or move them into some known directory to make it easier on yourself.
There's another method I ran across in another answer.
What are the Python modules/libraries which can be used to change or set the permissions of PDF file? I want to disable Print, Save, Save as, Copy for PDF file.
I think it's impossible. The browser display PDF file as local file. So when user can see the PDF, it is already be downloaded.
You can display the file using another format, instead of browser's PDF viewer. See this site as a example: http://wenku.baidu.com/link?url=_u5cgVNlfyprUwDiVVUWWYyNh5QFdF9MeG099qZtyHZ4r4_QUV3C9JZlhIcNTTefgvjdH1gvFUuNrwyJzw8S_JlySBs5NAVc23MG5lG9Uey
I have a simple html file with text input for file name. It will search the file in the folders and display contents in the browser using cgi script. The file can be pdf or image file. Wish to display 'file name as well as the contents in the browser'. Currently it displays either file name or contents but not both depending on Content type selected. Kindly guide. I need the exact code.