can somebody help me with this... i need a javacript code to print multiple documents when a print button is pressed. I posted 20 documents on my site and i just wanted to have a print button underneath the links of all the documents so the viewers can just print all the documents in a press of a button. I just dont want them to open those documents and print them one by one. Coz all the documents are basically have to be printed anyway. Thanks a lot!!!

i have this code but this code opens up a dialog box for each new window and is annoying. i just need one print dialog box for ALL the pages


function print(url,name)
{
var win=window.open(url,name,"width=100,height=100");
win.opener.focus()
win.print();
}

function printAll()
{
print("about:blank","win1") \\about blank is a sample url
print("about:blank","win2")
print("about:blank","win3")
print("about:blank","win4")
print("about:blank","win5")
print("about:blank","win6")
print("about:blank","win7")
print("about:blank","win8")
}

<form>
<input name="Print" onClick="printAll(); return false" type="button" value="Print">
</form>

Sorry. Welcome to the world of the browser. The user is God of this world. Meaning, that you can't script an automated print. That would be "hijacking" control away from the user. The JavaScript "print" method sends a request to the browser. The browser responds by opening the Print Dialog for the user. The user can decide if/where/how they want to print.

Now, there is a rather convoluted work-around. I coded a system for a financial firm that did automated document/form processing. Users would browse to a PDF form, fill it out, and the server would process/validate the information, store in a database, and return the PDF to the user with corrected data. It would then automatically print, silently, to the default printer.

The key is to use a PDF. Embed a PDF JavaScript into the PDF. While the browser object model doesn't have a silent print method, the Acrobat/PDF object model DOES.

That only addresses part of your problem, in that it's still a document-at-a-time.

Perhaps a totally different approach. Provide a zip file with all documents, that the user can download to the desktop and do with what they choose.

Thanks a lot for the info tgreer. I see what your saying. Actually i thought about zipping them too into a file. but the reason i didnt do it is because most of the users that will gain access to my site are senior citizens and maybe most of them arent familiar with zip files. While most of the links are office docs, i converted them into a pdf file so all they have to do is open the pdf and print it.looks like its doing pretty good.now my job is to arrange them in order which is like 50 pages. but hey, it works...thanks again mayn for the reply.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.