locked
Print documents using Javascript. RRS feed

  • Question

  • User870584148 posted

    Hello,

           Are there any way to print office document(unstructured document), PDF, images using java script or any other design approach could print documents, except any ActiveX and vb-script.

    Thanks

    Wednesday, February 28, 2018 9:13 AM

All replies

  • User-492460945 posted

    Hello,

    For printing using javascript, I think below one is useful for you.

    Wednesday, February 28, 2018 2:19 PM
  • User1400794712 posted

    Hi dexononforum,

    Window.print() is a javascript metnod to print the document.

    When we use window.print() directly, it will print the whole page.

    If you just want to print the specify part of body, you can use the following code:

    <div class="hello">
        hello
    </div>
    <div class="hi">
        hi
    </div>
    <input type="button" value="print" onclick="printDiv('hello')" />
    <script>
        function printDiv(divClass) {
            var printContents = document.getElementsByClassName(divClass)[0].innerHTML;
            var originalContents = document.body.innerHTML;
            document.body.innerHTML = printContents;
            window.print();
            document.body.innerHTML = originalContents;
        }
    </script>

    Best Regards,

    Daisy

    Thursday, March 1, 2018 6:00 AM
  • User-183374066 posted

    Not sure about office documents but you can print pdf, images and html through printjs

    Thursday, March 1, 2018 8:01 AM