save as pdf using chrome with javascript - javascript

Chrome allows users to hit Ctrl + P and choose 'Save to PDF'.
Is it possible to have this function through an javascript?
Like if click on an html button and the window for chrome save as pdf or window asking me where my "would be" pdf will be saved and with what name?
Note: Preferred that only chrome's API is used.

you have jsPDF that works with html5

Related

How to download PDF in chrome viewer using automation script

I have to download PDFs using any automation script, when i click on download PDF button, it opens up in new tab in chrome pdf viewer, manually I can click on Download button and download. But when I try to automate it, I can see the button id 'Download' in Inspect element, but when I use command Document.GetelementbyID('Download').click(), the button or any other icon on screen in not getting identified.
I tried changing the chrome setting to directly download pdf, instead of opening in new tab, but it fails for large PDFs (maybe something wrong with source application). I cannot change browsers.
So is there a way to download pdf from pdf viewer, some key shortcut or some script to retrieve the PDF from chrome temp.

How to open a file directly from msSaveOrOpenBlob?

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.

Exporting HTML canvas from inside of Chrome extension

I'm writing a Chrome extension where a canvas is modified, and I want to have the option to save the canvas data as an image. Is there any way for me (using JavaScript) to save directly to the file system (ideal) or at least prompt the user with a download menu so they can save it themselves?
There seems to be no way to do this except for these ideas:
Online backend written in PHP or something
An iframe to show the online website which would have the canvas on it
Tell the user to right click and save the canvas image

JavaScript Print PDF using Adobe toolbar

I am trying to print a PDF in an iFrame. I have a print button for the user to click. I am finding it hard to write JavaScript to print the PDF that will work across IE, Chrome, Firefox. It's been really hard to print PDF, in an Iframe, in particular on IE.
While working on this, I noticed a toolbar for saving and printing the PDF when hovered over the PDF. I think these features are offered by Adobe.
I would like to know if there is a way to access these Adobe PDF controls through JavaScript.
How can I fire them using the print button?

Javascript call programmatically the "Save as PDF" feature of Chrome dialog print

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.

Categories