Print a Part of Page using Javascript

do you want to print a part of the web page?

do you have multiple print buttons in a web page, which prints portion of the page?

do you want to exclude some elements in print of your page? (like images, ads)

do you want to print the display page differently? (changing font or colors of text)

Here, I am going to give code examples to above questions

Let us take a sample HTML web page

if you want to print the whole page then

To Print a part of the web page:
– create a print window and write html text you wanted to print
– focus the window and call the “print()” function
– close the print window

Here is the modified printPage function

You can hide some of the elements within your actual content by adding style elements or include css file in print window html

In the above example, I have added style and css file, you can use either one or both. Using these styles or css, we can style the text only for print.

If you have multiple print buttons, and each one prints selected area of a web page, then you need to pass id of the print area on each button click.

Comments

  1. By Raja

    Reply

  2. By vosmer

    Reply

  3. By vosmer

    Reply

    • By admin

      Reply

  4. By LMW1

    Reply

  5. By Siva

    Reply

  6. By Amr

    Reply

  7. By Ely

    Reply

  8. By Luis

    Reply

  9. By Venky

    Reply

  10. By Farid E. Galindo

    Reply

  11. By Amit Mishra

    Reply

  12. By abi

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Bitnami