I have a premium WordPress plugin that embeds PDFs and contains it's own toolbar for the PDFs.
After reaching out to the developer to create a print button for their toolbar, there response was "underwhelming". "Have the user download the PDF, then print form there". The developer has the DIVs inside a containing DIV with using only a class, not an ID.
I'm trying to now create my own print button and have it opening the print window, BUT it is not generating a print preview of only the PDF (which is spanning across nested DIVs)
Here is the structure of the rendered HTML output for the target DIVs that I want to print (I want to print all of them, not one at a time).
My problem is that the window. print function is not capturing only the content of the DIVs. It's previewing the whole webpage.
<div class="pdfemb-pagescontainer">
<div class="pdfemb-inner-div pdfemb-page1">
<canvas class="pdfemb-the-canvas">
</canvas>
</div>
<div class="pdfemb-inner-div pdfemb-page2">
<canvas class="pdfemb-the-canvas">
</canvas>
</div>
<div class="pdfemb-inner-div pdfemb-page3">
<canvas class="pdfemb-the-canvas">
</canvas>
</div>
</div>
Here is my current code:
<button onclick="printPDF()">Print Lesson PDF</button>
<script>
function printPDF() {
var x = document.getElementsByClassName("pdfemb-pagescontainer");
window.print(x[0].innerHTML);
}
</script>