Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
395 views
in Technique[技术] by (71.8m points)

javascript - Silent print an embedded PDF

I have a web page with embedded PDF on it. My code looks like this:

<embed
    type="application/pdf"
    src="path_to_pdf_document.pdf"
    id="pdfDocument"
    width="100%"
    height="100%">
</embed>

I have this javascript code for print my PDF:

function printDocument(documentId) {

    //Wait until PDF is ready to print    
    if (typeof document.getElementById(documentId).print == 'undefined') {

        setTimeout(function(){printDocument(documentId);}, 1000);

    } else {

        var x = document.getElementById(documentId);
        x.print();
    }
}

When this code is executed Acrobat plug-in opens the well-known print dialog. Something like this:

PrintDialog

Two questions:

  • How to improve the way to detect that PDF is loaded and ready for print?
  • How to avoid showing print dialog?

A little more info about my system:

OS: Windows XP

Browser: Internet Explorer 7

PDF Plugin: Acrobat Reader 9

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You are not going to be able to print silently with plain old JavaScript. How would you like your printer to start printing out 100000000 pages of all black. Not a good thing. If you want to print silently and have it work for Internet Explorer only, there are ActiveX controls out there that can do it. This requires higher security settings for your page and for your users to really trust your site.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...