Use EL to dynamically specify the CSS file, here is an example that checks for the presence of the print request parameter (thus, <h:outputLink value="page.jsf?print" target="_blank"> is sufficient):
<link rel="stylesheet" type="text/css" href="${not empty param.print ? 'print.css' : 'normal.css'}" />
You can also get the regular JSF method as a bean proprerty:
<link rel="stylesheet" type="text/css" href="<h:outputText value="
If you use Facelets instead of JSP, you can also use a unified EL in the template text:
<link rel="stylesheet" type="text/css" href="#{bean.cssFile}" />
If you really don't need the print preview tab / page, you can also just specify the media attribute in the CSS link and let the link / button call window.print() during onclick instead of opening in a new tab.
<link rel="stylesheet" type="text/css" href="normal.css" media="screen, handheld, projection" /> <link rel="stylesheet" type="text/css" href="print.css" media="print" />
When the page is printed, only the one indicated by media="print" will be used instead.
source share