在Internet Explorer中使用JavaScript打印方法设置PDF文件名无效

7
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();

这是我的JavaScript代码,用于打开一个新窗口并自动打开打印对话框。当用户从打印对话框中选择将内容打印为Adobe PDF时,会出现一个菜单,其中包含定义PDF文件名的选项。在Firefox和Chrome中,PDF文件名设置为页面标题,这很好。但是在Internet Explorer中,PDF文件名设置为父窗口的URL基础名称。我如何在Internet Explorer中以编程方式设置PDF文件名?

你找到解决方案了吗? - Amber
1个回答

3
很遗憾,无法从浏览器中完成此操作。似乎文件名来自PDF打印机而不是浏览器,正如Teemu在此帖子中所评论的那样:Default File Name when printing from Internet Explorer。微软论坛上有一个关于如何设置要作为默认文件名的值的线程,请点击下面的链接查看:https://answers.microsoft.com/en-us/ie/forum/ie8-windows_xp/filenames-when-printing-to-a-pdf-driver/e5541ba9-d545-e011-9577-d485645a8348。但是,它仅适用于通过Ctrl + P打印的静态页面。由于您正在动态创建文档,因此将使用父URL作为默认文件名。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接