Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 722
Jakal Avatar asked Dec 15 '14 16:12

Jakal


1 Answers

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.

like image 191
Vinas Avatar answered Oct 26 '22 19:10

Vinas