Print this page
Yet another quick template hack:
Here's a trick to add a "print this" link to your template. This link will:
- open the page without navigation, BreadCrumbs, LeftMenu, etc.
- launch the browser's print dialog
You could probably do this much cleaner, e.g., by using <wiki:CheckRequestContext context="view">, but the idea was to do something that would take me less time than copy 'n paste into word..
Step 1: the doPrint switch
Add this in the ViewTemplate.jsp's head:
<%
String wikiPageName = request.getParameter("page");
String baseURL = request.getRequestURL()+"?page="+wikiPageName;
String printURL = baseURL+"&action=print";
String action = request.getParameter("action");
if (null == action) action="view";
boolean doPrint = action.equalsIgnoreCase("print");
%>
Step 2: if doPrint, then print:
<%
if (doPrint) {
%> <body onload="print();">
<% } else {
%> <body>
<% } %>
Step 3: remove unwanted sections:
<%
if (!doPrint) {
%>
<%@ include file="LeftMenu.jsp" %>
<P>
:
etc.
<% } %>
Step 4: the "print this" link
if (!doPrint) {
%>
<TD align="right"><%@ include file="SearchBox.jsp" %></TD>
<td align="right"><a href="<%=printURL%>">Print this</a></td>
<% } %>
Step 5: the "this page" link
if (doPrint) {
%>
<td colspan="2">This page: <a href="<%=baseURL%>"><%=baseURL%></a></td>
<% } %>