使用 JavaScript 打印多个 PDF 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7187400/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 23:14:29  来源:igfitidea点击:

Printing multiple PDF files using JavaScript

javascript

提问by zahir hussain

I want to know how to print multiple PDF files in a single print click.

我想知道如何在一次打印点击中打印多个 PDF 文件。

I can easily print single PDF file but I dont know how to print when there are more files.

我可以轻松打印单个 PDF 文件,但是当有更多文件时我不知道如何打印。

Thanks in advance.

提前致谢。

回答by Shadow Wizard is Ear For You

You can call print()multiple times in your code, resulting in the files being printed one after the other:

您可以print()在代码中多次调用,导致文件一个接一个打印:

function PrintAll() {
    var pages = ["page1.pdf", "page2.pdf", "page3.pdf"];
    for (var i = 0; i < pages.length; i++) {
        var oWindow = window.open(pages[i], "print");
        oWindow.print();
        oWindow.close();
    }
}

回答by Spycho

Either do as Shodow Wizard suggests and print out the files sequentially or concatenate the files server-side.

按照 Shodow 向导的建议进行操作并按顺序打印文件或在服务器端连接文件。

You could make an ajax request with the fine names that the user wants to print, concatenate them server side, return the concatenated pdf and then print that out. The concatenation implementation would depend on what server-side language you are using.

您可以使用用户想要打印的精细名称发出 ajax 请求,将它们连接到服务器端,返回连接后的 pdf,然后将其打印出来。连接实现将取决于您使用的服务器端语言。