Sunday, August 9, 2009

Print selected portions of your page by winow.print()

Step 1:

create print.css file:

// to ignore input elements, images
img, input, .errortext, .noprint {
display : none;
}

.toprint {
display : block;
}

// to print table with border,lines
table.tablestyle1 { border-collapse: collapse; }
table.tablestyle1 th, table.tablestyle1 td { border: 1px solid #888; }

// to provide page break
.break {
page-break-after : always;
}

Step 2:

In JSP:

Link the above css in JSP file.
link href="css/print.css" media="print" type=text/css rel=stylesheet

Use class name 'toprint' on those portions which you like to display it on 'Print Preview'.

No comments:

Post a Comment