I am trying to offer users the option to save the current webpage as a PDF using Chrome natively, no other browser support is required and introducing a 3rd party system is not a practical option.
Currently I have to manually instruct the user where the "Open PDF in Preview" link is within the print dialogue and only offer the following button:
<a href="#" onclick="event.preventDefault(); window.print();">
PDF Preview
</a>
I would like to jump the user straight to the PDF preview dialogue for them to save, the following will of course not work, but is more similar to what I would like to achieve.
<a href="#" onclick="event.preventDefault(); window.print('pdf');">
PDF Preview
</a>
It is not possible to do this.
Chrome currently meets the HTML standard as "print" generically means obtaining the page in some physical way, be that a traditional printed document or a PDF. How it chooses to do this is up to the browser vendor.
Additionally Chrome users can select their default action for printing to be PDF or a printer on their network.
From that I would infer that it's unlikely Chrome would let the web application override the user preference.
Sources
https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#simple-dialogs
https://html.spec.whatwg.org/multipage/rendering.html#obtain-a-physical-form
https://productforums.google.com/forum/#!topic/chrome/D0CYzpWx7xE;context-place=topicsearchin/chrome/save%20as%20PDF
Related
I am using IE 11 for web development. Now in javascript, I do window.msSaveOrOpenBlob(fileBlob), a pop up shows on the button of the page with save and open option.
Now what I want to achieve is that perform click event on open so the file will be open automatically(without user click open).
Here is the case:
User click a link, it should open the associated file with whatever file reader that can open the file. PDF, will be adobe reader, word document will be opened in microsoft word.
Things still works when I click the open button from pop up. I just want to skip this manual click and do it in the code.
I've seen some webpage does this, but can't figure out myself. Need some help.
As far as I know, we can't control the "open or save" prompt using JavaScript. It is the browser behavior.
As a workaround, to the pdf file, I suggest you could try to use the pdf.js plugin to display the pdf file. To the Office documents, you could check the following article to use the Office Web Viewer to view the document.
Office Web Viewer: View Office documents in a browser
Besides, here is an article about displaying (Show) Word, Excel, PowerPoint (PPT) and PDF files in browser web page in ASP.Net, you can also refer to it.
Google Chrome have the option "Save as PDF" when you enter the Print dialog or window.print().
The user need to choice this option in dialog to save the page as pdf.
Can I call some funcion or pass an argument to window.print() in chrome to "print" the page as a pdf without the print dialog appears?
Any ideas?
Unfortunately there isn't any param you could pass to window.print(); and force it to print pdf unless there is a pdf driver plugin already present on the client's browser. There are plugins for firefox and IE (JS Print Setup and MeadCo Script respectively).
You may want to look at MrRio/jsPDF, a tool to generate pdf files at client-side JS.
I'm a library and information science student and a true programming novice (I've only taken one introductory course in JS, PHP, and MySQL), so I would really love some help. I'm sorry that I might not have the right vocabulary to talk about this!
I am building a prototype of a digital thesis collection for a course, and I am using the embedit.in sitewide script so that users can view the PDFs linked to in each thesis record in an overlay viewer. The problem is that the overlay viewer does not give the user the option to download the PDF (although that is an advertised feature, there actually is no download button in the viewer for some reason), and the script works for the whole page, so I cannot provide an alternate link to the PDF that would allow users to download directly. I also can't see the script itself so I don't know exactly what it's doing. I really like the overlay viewer, but I want users to be able to download the PDFs as well. Ideally, I envision having two side-by-side links, one that says "Click here to view or print," which allows users to launch the viewer, and the other that says, "Click here to download," that does not launch the viewer and lets them download it. Is there anyway to write a script that would prevent the embedit.in script from working against a specific link on the page, without seeing the script itself?
Here is a bit of the HTML code from a sample thesis record page below, for a bit of context:
<h2>Development of the Black Community of Bedford-Stuyvesant</h2>
<div id="description">
<p><strong>Title:</strong> Development of the Black Community of Bedford-Stuyvesant<br />
<strong>Author:</strong> Austin Finigan, Jr.<br />
<strong>Date:</strong> 1974<br />
<strong>Subjects:</strong> African Americans--New York (State)--New York<br />
Brooklyn (New York, N.Y.)--History<br />
<br />
Click here to view or print PDF</div>
<script src="http://embedit.in/sitewide.054fbf300b0637d7d8cc525ff36789500da4f3c2.js" type="text/javascript"></script>
I just created two links and put them side-by-side, one that links to the PDF directly and opens the overlay viewer via the embedit.in sitewide script and the other that links to a new blank page with a redirect script to the PDF so that the browser's download dialog box launches when the page opens. I hate the blank page but it works.
I have a website which hosts large PDF documents, as well as some other file formats.
How can I open up a download-dialog box in javascript so that the user can save the document to their computer?
PDF always needs download (even for iframe / embed /object ) so do not use those as its then potential double overload on server, once to downlink and show then potentially a second time by the scripting (However if user selects the "save download as" button in viewer the download should be just once)
The answer is display a small image or icon to show the download content, then back that up with
<Img src="cover.png">
something like this:-
<a href="https://africau.edu/images/default/sample.pdf" download="A Sample.pdf"><img src="https://www.freeiconspng.com/uploads/download-pdf-icon-png-icon-29.png" width="128" height="128"><a><br>right click icon to chose download options
note clicking the icon may show a blank page based on browser security, that is normal, hence the suggestion the user uses their discretion.
I have a PDF embedded in a web page using the following code:
<object id="pdfviewer" data='test_full.pdf#page=1&toolbar=0&statusbar=0&messages=0&navpanes=0'
type='application/pdf'
width='500px'
height='350px'>
The PDF itself is set to open in full screen mode which shows no controls. The user can advance the slides by clicking on the view.
What I'd like to have is some way to trigger that click so that I can advance 2 similar PDF:s side-by-side (one for the actual slideshow and one for the speaker notes). Is this possible to do in javascript and/or jQuery? I have tried using the click()-method but it doesn't get through to the embedded PDF.
Update: Can't find any info on it, so I guess I'm out of luck and have to try a workaround. Am currently juggling 3 embeds of the same pdf (current page, next page and previous page), hiding and showing them and loading more pages as the user clicks around.
I doubt it. Allowing web page scripts to pass input events to the PDF viewer could be a security risk (since the viewer generally has access to system file dialogues via things like Save As).