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

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.

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.

Print a PDF with JavaScript without dialog or with fixed settings

I'm a newbie with JavaScript and I was looking for a method to print a pdf document with a button click without any dialog window opening or not make the user able to change the print settings, I want to print it with a fixed printer, number of pages and format.
I already tried Print.js but it still opens a dialog window and the user can change the settings in it.
The browser does not allow it to print automatically without the user being able to choose the settings to print. This would be extremely problematic as someone can print endless pages without the users permission

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.

Setting filename of pdf from javascript print method in Internet Explorer not working

var docprint = window.open("", "", "toolbar=0,location=0,menubar=0,scrollbars=1");
docprint.document.open();
docprint.document.write("<html><head><title>Title here</title></head>");
docprint.document.write("<body>body content here</body></html>");
docprint.document.close();
docprint.focus();
docprint.print();
This is my javascript code for opening a new window and automatically opening the print dialog. When the user selects the option to print to Adobe PDF from the print dialog, a menu comes up with the option to define the pdf filename. In Firefox and Chrome, the pdf filename is set as the title of the page, which is fine. However, in Internet Explorer, the pdf filename is set as the parent window's url basename. How can I set the pdf filename programatically in Internet Explorer?
It seems that unfortunately it can't be done from the browser.
It looks like the file name comes from the PDF printer, not the browser, as commented by Teemu on this post: Default File Name when printing from Internet Explorer.
There's a thread opened on the Microsoft's forum about how to set the value to be taken as the default file name on the link below:
https://answers.microsoft.com/en-us/ie/forum/ie8-windows_xp/filenames-when-printing-to-a-pdf-driver/e5541ba9-d545-e011-9577-d485645a8348
But it applies only to static pages you wanna print by hitting Ctrl + P. As you are dynamically creating a document, it will take the parent's URL as the default file name.

save as pdf using chrome with 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

Categories