0

I want to print the embeded content(a pdf) however, the following code is not working.

$("#printLabel").on('click', function () {
    $("#printContent").print({
        deferred: $.Deferred().done(function () {
            //$('#modal-addEdit').modal('hide');
        })
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jQuery.print/1.5.1/jQuery.print.js"></script>
<div>
<embed id="printContent" src="https://www.alejandrodelasota.org/wp-content/uploads/2013/03/demoform1.pdf">
</div>
<div>
 <button class="print-link no-print" id="printLabel">Print</button>
</div>

The print preview is displaying blank.

1 Answers1

0

I tried printing a while ago and couldent get it to work using jquery so I ended up using this plain js. Or try this link https://coderwall.com/p/c5xzpw/printing-the-contents-of-a-div-with-javascript

function printRequest(e) {      

    var content = document.getElementById("printerBox").innerHTML;
    var mywindow = window.open('', 'Print', 'height=600,width=800');   

    mywindow.document.write('<html><head><title>Print</title>');
    mywindow.document.write('</head><body >');
    mywindow.document.write(content);
    mywindow.document.write('</body></html>');

    mywindow.document.close();
    mywindow.focus()
    mywindow.print();
    mywindow.close();
    return true;
}

<div hidden id="printerBox">

</div>
PEPEGA
  • 2,214
  • 20
  • 37