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
Header Contentactual contentFooter content
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
var printWin = window.open(”,”,’left=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status =0′);
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.
Area1 content Area2 content