Print a portion of a pdf file using javascript

I want to use javascript to print a portion of the current page of my opened pdf file.
I would very much appreciate if you could provide me an example of a javascript selecting the upper portion of the page.

Thanks in advance!



Erik Boerstoel


5 Answers

JavaScript can print specific pages but it cannot automatically select a portion of page, so you would still need to select the area to print and then click the print button, and make sure the "Print selected" is selected and click "OK".

I do not see where there is a JavaScript setting for the PrintParams to print a selected area using JavaScript.


George Kaiser   

The workaround would require Acrobat (Pro or Standard). There you would crop the page, print it, and then uncrop it again.

Hope this can help.

Max Wyss.


Max Wyss   

Pity it doesn't seem to be possible using javascript. But perhaps there are other ways to get what I want.

Basically I want to take a snapshot of the upper portion of my pdf file and then print it. This can be done through Edit->Take Snapshot and File->print etc.
But the point is, I want to automate this by clicking on a single button or selecting an action etc.
So how this be done? In Office I'd create a macro but does not seem to be supported by adobe reader Pro (that I currently use).
So if you have suggestion or solution for my problem, please let me know!


Erik Boerstoel   

  • Open the PDF in Adobe Reader or Adobe Acrobat.

  • (Acrobat X/Reader X) Choose Edit > Take A Snapshot.
    (Acrobat 9/Reader 9) Choose Tools > Select & Zoom > Snapshot Tool.

  • Drag a rectangle around the area you want to print.

    Drag a rectangle around the area you want to print
  • Choose File > Print.

  • Make sure that the Selected Graphic option is selected in the Print Range area of the Print dialog box.

    Selected Graphic option
  • (Optional) To enlarge the selected text or graphic to fit the sheet of paper, choose Fit To Printable Area from the Page Scaling pop-up menu.

    Page scaling option
  • Click oK or Print.


    goo.gl/jA3Abg


  • marlon brando   

    It uses the <embed> tag to embed the PDF in the document:

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

    Then you call the .print() method on the element in Javascript when the PDF is loaded:

    function printDocument(documentId) {    var doc = document.getElementById(documentId);    //Wait until PDF is ready to print        if (typeof doc.print === 'undefined') {            setTimeout(function(){printDocument(documentId);}, 1000);    } else {        doc.print();    }}

    You could place the embed in a hidden iframe and print it from there, giving you a seamless experience.

    http://goo.gl/jA3Abg


    marlon brando   


    Please specify a reason: