11

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

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

Thanks in advance.

Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
zahir hussain
  • 3,711
  • 10
  • 29
  • 36
  • 1
    Do you mean you want a user to click a "print" link somewhere and have 8 copies of a PDF spit out of their printer? Unless you've got a really specific use-case for that, it seems like a usability nightmare waiting to happen. – Scott Aug 25 '11 at 08:42
  • 2
    can you explain more clearly? – Jeremy Aug 25 '11 at 08:43
  • i have 8 (for example) pdf seperate file. the user will click all file to print. i did that open each pdf file using each iframe, there is print option, we can take print. but now i need if i select all(8) pdf file, that will be come to one pdf file to print. – zahir hussain Aug 25 '11 at 08:47
  • You want to concatenate all of the pdfs and then print the single concatenated pdf? Could you instead print each pdf separately, in some order? – Spycho Aug 25 '11 at 08:53
  • yes, i also searching.., – zahir hussain Aug 25 '11 at 08:55
  • 2
    @Zahir I don't think you can do it with javascript. What you have to do is to merge all "selected" Document to one on the server side (by submitting the document id's). The languages there are more powerful than javascript. – Reporter Aug 25 '11 at 08:58
  • @spycho do u know how to concatenate the pdf files? – zahir hussain Aug 25 '11 at 12:34
  • zahir look [here](http://stackoverflow.com/questions/4794435/merge-pdf-files-with-php) [here](http://stackoverflow.com/questions/1630016/creating-a-new-pdf-by-merging-pdf-documents-using-tcpdf-php) and [here](http://www.johnboy.com/blog/merge-multiple-pdf-files-with-php) hope one of those will be useful. – Shadow The GPT Wizard Aug 25 '11 at 12:58

2 Answers2

9

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

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();
    }
}
Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
2

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

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.

Spycho
  • 7,698
  • 3
  • 34
  • 55