I have the following external pdf embedded as shown below. The pdf displays fine, but how do I cache the pdf so that the page doesn't redownload the pdf each time I visit the page? Should I use an object tag instead?
<embed src="http://samplepdf.com/sample.pdf#toolbar=0&navpanes=0&scrollbar=0" width="500" height="375">
From my understanding, you have a pdf on your server that you would like to cache onto the client side so that the pdf is not redownloaded each time the user refreshes the page.
By sending the proper headers, you can enforce cache rules (or at least try to enforce them as any browser can overrule your rules).
Php or in your case, Django, can send the appropriate headers to tell the browser to cache this pdf. My recommendation would be that you link that you provide in the embed tag links to a script instead of the pdf diriectly. This django script would sent out 2 sets of headers. One tells the browser to cache this content and other tells the browser it is sending a PDF file. This ensures that the pdf gets cached. When you load a webpage, the typical headers' scope by not encompass all external files/pdfs. As each is a separate request.
The method that I prescribed adds extra work than simply embedding the pdf but it should get the job done.
Related
I am writing a Chrome extension that manipulates PDF files and am looking to get all the text of a PDF file that's currently open in Chrome's PDF viewer.
I learned from
How can I get selected text in pdf in Javascript?
how to get selected text, but I couldn't find in the API a function that extracts the entire text (or better yet the PDF itself, and then send it to a server). Is it possible?
I am aware of the solution of sending the URL and downloading it on the server side, but sometimes it is problematic (e.g. PDFs from password-protected websites).
Thanks.
I have tried looking in the API, https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/resources/pdf/pdf_scripting_api.ts
I have also tried "downloading" the PDF on client side and sending it as Blob to a server, but it's a problematic solution (sometimes blocked for example, requires extra permission).
I have some generic javascript that loads and displays photos on an html page based on an xml file that it reads. The problem is that if I change the content of the xml file, it doesn't show up on the web page. Here's a section of an xml file to give you an idea of what I'm talking about:
<slides>
<slide>
<name>slideshow/cal2018/20180506.jpeg</name>
<alt>some alt text</alt>
...
The problem that triggered my issue is I decided to move the "slideshow/" into the xml file instead of having it in the javascript. When I did that, the photos stopped showing up - I just got the alt text. However when I switched to a different page, the photos were brought up properly.
The problem is that all the web browsers seem to want to hold on to xml files for a long time - apparently at least a week, which is how long I worked on the pages without the current version of the xml file being loaded.
I can manually clear the browser cache and the problem resolves itself for that browser. Simply reloading the page, which is sufficient to reload the javascript, doesn't do that.
I use a lot of xml files to drive web pages. I need to ensure that the xml file is the current one and not some ancient cached copy. Is there a cross-browser (javascript?) way I can clear the (xml) cache before loading an xml file?
Also, why do browsers ignore xml files when I ask for a page reload?
Task:
I have a huge html file that is placed on server, I want to show it to the user by click of an URL.
Issue:
As this file is huge, On click of the URL the browser doesn't render the page in time*(Records get appended continuously while the vertical scroll bar size diminishes, user is not able to do anything but see the first few records)* and the default spinner of the browser spins endlessly.
Can this be achieve this way, if yes, how?---> On click of the "link", the html file should get downloaded on client machine first, then viewed on client browser window from his local system not from URL directly(maybe in a iframe or something).
EDIT
loading 500 MB of HTML was asking a lot of a browser.
Work around
Since generated htmls files were huge, we converted htmls files to pdf format. Later, used browser's default pdf viewer capability to view the data on browser window itself or simply downloaded the pdf file onto the disk.
No, there is no way to force a browser to download an HTML file to disk and open it.
In practical terms, a 500+ MB HTML file will never be readable -- loading it requires much more memory than is available to a web browser. Downloading it won't help. You need to break it up into smaller documents.
I am running a local Tomcat server within which I am hosting a PDF report. Once my Tomcat server is up and running, if I enter the following URL in my browser:
https://localhost:9000/Report.pdf
Then the page displays just fine. But within my javascript application if I call window.open(https://localhost:9000/Report.pdf), then a page will open with that URL, but it will display as blank. Refreshing or reloading the page won’t help, I need to close the whole tab and paste the URL in order to get it to load properly.
The server is being linked through the Symphony Messaging application, so https is a must. I'm not quite sure if that's what's causing the error or windows.open just doesn't work with a pdf file. I've tested it with other file types (ex. https://localhost:9000/logo.png) and it works just fine.
I've seen some similar questions about passing a byte array into window.open to display a PDF, but this seems kind of redundant: do I really have to convert the PDF to a byte array and then have window.open convert it back to PDF format just to display?
FYI both the HTML page and underlying Javascript from which I am attempting to call window.open are hosted on localhost:9000 as well.
I am taking a text file from user and then posting that file back to the browser using ajax storing the content in db and then showing the content back to user page using Jquery post response.
Now i want to something like this..
Read the text file from the user computer using javascript. Display the content and when he submits the page I will save the values.
Can't be done in pure JS for security reasons. You would need to have the user upload the file to your server, and fetch the contents back through Ajax.
If you use Flash or Java, you should be able to gain direct access to the file. If you speak Flash/Actionsript, maybe SWFUpload's source code (especially the new client-side resizing functions) can serve as an inspiration.
Update: This blog entry should help. Read and write local files with Flash Player 10
Update: To elaborate on the "upload and fetch" thing, if you do the uploading in an IFRAME, you could even have the upload script simply output the text file's contents. Because the iframe belongs to your domain, you will be able to retrieve its contents via JavaScript when the upload has finished. As long as you send a content-type: application/text it should be fairly safe from any malicious attacks.
If you're ok with Firefox 3.6 support only check out https://developer.mozilla.org/en/Using_files_from_web_applications, otherwise you should use Flash, Java or silverlight for this.
You won't be able to read a file in user's computer due to security issues.
Reading client files in javascript is possible with the new File API available in modern browsers. Check this site and its code: http://www.readfileonline.com/
However, before reading file contents in javascript, the user must explicitly select the files it allows to read. This is a security feature of the standard.