在Internet Explorer中从javascript打印方法设置pdf的文件名不起作用

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

本文关键字:pdf 设置 文件名 不起作用 方法 打印 Internet Explorer 中从 javascript      更新时间:2023-09-26
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 文件名?

不幸的是,似乎无法从浏览器中完成。

看起来文件名来自PDF打印机,而不是浏览器,正如Teemu在这篇文章中评论的那样:从Internet Explorer打印时的默认文件名。

在Microsoft论坛上打开了一个关于如何设置要作为默认文件名的值的帖子,链接如下:

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 作为默认文件名。