Let's say I'd like to print (or convert to PDF) a particular area (e.g., a div
) of a complex HTML page. How to do that in Chrome or Firefox? I didn't find a specific option from the "inspect element" function.
Just select the desired text on the current page and press CTRL+P. This will bring up the Print dialog, where you can simply select the "Selection" option there. This will print out only the selected text. I just did this on my Firefox 30.0 and it worked perfectly.
You can use this function for print a specific area of web page or full web page content. Use printPageArea() function on onclick event of print button element and provide the content area div ID which you want to print.
I know it's a quite an old topic, but here is what worked for me:
<div id="parent_div">
<p>NOT to be printed</p>
<div id="print_div">
Print this!
</div>
<button id="print_now" onclick="PrintDiv('print_div')">
</div>
And the JS function:
function PrintDiv(div_id) {
$('body').css("visibility", "hidden");
$("#"+div_id).css("visibility", "visible");
window.print();
$('body').css("visibility", "visible");
}
If you are not using jQuery, you can still change the CSS with:
document.getElementById("body").style.visibility = "hidden";
document.getElementById(div_id).style.visibility = "visible";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With