0

How can I print only the content residing in Content Editor Web Part? The content inside my Content Editor Web Part is an image.

1 Answer 1

2

You can use JavaScript to print a particular div content

<div id="printDiv">
    <img src="image.png" />
</div>

<input type="button" onclick="printDiv('printDiv')" value="Print" />

function printDiv(divName) {
    var printContents = document.getElementById(divName).innerHTML;
    var originalContents = document.body.innerHTML;

    document.body.innerHTML = printContents;

    window.print();

    document.body.innerHTML = originalContents;
}

Another way to do this by hiding unwanted elements from the UI using JavaScript and then window.print()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.