Print this page

Yet another quick template hack:

Here's a trick to add a "print this" link to your template. This link will:

  1. open the page without navigation, BreadCrumbs, LeftMenu, etc.
  2. 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.
<% } %>

if (!doPrint) {
%>	
        <TD align="right"><%@ include file="SearchBox.jsp" %></TD>
 	<td align="right"><a href="<%=printURL%>">Print this</a></td>
<% } %>
if (doPrint) {
%>	
            <td colspan="2">This page: <a href="<%=baseURL%>"><%=baseURL%></a></td>
<% } %>

Add new attachment

In order to upload a new attachment to this page, please use the following box to find the file, then click on “Upload”.
« This page (revision-6) was last changed on 28-Feb-2005 16:29 by 158.228.228.108