Print and Close the Window

Hello, would really appreciate if someone can let me know if this achievable-

Print the content of an element (a pdf document) in browser and close it after printing is done. Tried below which prints correct num of Pdf pages and close the browser window but, pages "are empty"

      function printPdf() {
          var prnDoc = document.getElementById('pdfId'); //This element is an embedded pdf
          prnDoc.printAll();
          window.close();         
      }


nag_18Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
Hello nag_18,

I don't think it's possible until using of Adobe Acrobat Javascript : http://partners.adobe.com/public/developer/en/acrobat/sdk/AcroJSGuide.pdf
I see a script here, but work "bad" : http://bytes.com/topic/javascript/answers/90869-javascript-function-print-pdf-file

Regards.
0
Michel PlungjanIT ExpertCommented:
If this works


      function printPdf() {
          var  prnDoc = document.getElementById('pdfId'); //This element is an  embedded pdf
          prnDoc.printAll();
//           window.close();        
      }

then try



      function printPdf() {
          var  prnDoc = document.getElementById('pdfId'); //This element is an  embedded pdf
          prnDoc.printAll();
           setTimeout('window.close()',5000); // 5 seconds, adjust as needed
      }


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nag_18Author Commented:
To mplungjan:

My code to print works fine without trying to close as printAll() is Adobe Reader's documented javascript function. Issue is only with closing window right after issuing print command. Setting timeout would be per-case basis as embedded pdfs will differ in size for every window; will set timeout considering worst-case scenario.
Accepting your answer as i'm unaware of JS's timeout function till now. Thank you and lekim971 for trying to help.
0
nag_18Author Commented:
I did consider, before posting question, to put a timer for  closing window after printing is complete but was wondering if i can avoid it. Although it proved to be not possible, allotted points to mplungian for pointing to javascript call- setTimeout().
0
leakim971PluritechnicianCommented:
You're welcome!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.