<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Pearl Tech &#187; printer friendly</title>
	<atom:link href="http://blog.pearltechnology.com/tag/printer-friendly/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.pearltechnology.com</link>
	<description></description>
	<lastBuildDate>Tue, 25 May 2010 14:37:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Printer Friendly jQuery</title>
		<link>http://blog.pearltechnology.com/printer-friendly-jquery/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://blog.pearltechnology.com/printer-friendly-jquery/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 13:39:46 +0000</pubDate>
		<dc:creator>AaronH</dc:creator>
				<category><![CDATA[Application Development]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[jQuery print tabs]]></category>
		<category><![CDATA[jQuery UI]]></category>
		<category><![CDATA[jQuery widgets]]></category>
		<category><![CDATA[printer friendly]]></category>
		<category><![CDATA[Sharepoint Web Parts]]></category>

		<guid isPermaLink="false">http://blog.pearltechnology.com/?p=344</guid>
		<description><![CDATA[Building websites to support different browsers is easy business when you&#8217;re relying on the jQuery framework. However, building printer friendly web content is another hurdle for application developers. I recently came across some useful jQuery for printing Sharepoint web parts. The idea was pure genius &#8211; wrap the bit of HTML you want to print [...]]]></description>
			<content:encoded><![CDATA[<p>Building websites to support different browsers is easy business when you&#8217;re relying on the <a href="http://jquery.com/">jQuery framework</a>. However, building printer friendly web content is another hurdle for application developers. I recently came across some <a href="http://www.endusersharepoint.com/2009/04/06/jquery-for-everyone-print-any-web-parts-plugin/">useful jQuery</a> for printing Sharepoint web parts. The idea was pure genius &#8211; wrap the bit of HTML you want to print into its own document window and inform the browser of your intentions to print. The key idea here is that we want to print <em>a portion of a webpage</em>, not the entire web page. If we wanted to print the entire webpage, I would recommend going the route of using the @media tag <a href="http://www.w3.org/TR/CSS2/media.html">found in CSS 2.0</a>. However, you will eventually run into printing quirks when you are building interactive websites.</p>
<p>Although I wasn&#8217;t using Sharepoint for this website, I was using jQuery, so I leveraged this idea to print specific portions of a website instead of only Sharepoint specific content. This site was also using <a href="http://jqueryui.com/">jQuery UI</a> for creating rich internet content, specifically the <a href="http://jqueryui.com/demos/tabs/">tabs</a>, <a href="http://jqueryui.com/demos/accordion/">accordion</a>, and <a href="http://jqueryui.com/demos/dialog/">dialog</a> widgets. The incredible thing about widgets is that they allow for highly interactive sites, yet the trouble with widgets is that they are not conducive to easily printing their content.</p>
<p>If you tried printing the <a href="http://jqueryui.com/demos/tabs/default.html">default tabs example</a> using jQuery UI, you end up with something that looks like this&#8230;</p>
<p><center><a href="http://blog.pearltechnology.com/wp-content/uploads/2009/09/jquery-tabs-default-functionality.PNG#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-medium wp-image-355" title="jquery tabs default functionality" src="http://blog.pearltechnology.com/wp-content/uploads/2009/09/jquery-tabs-default-functionality-300x119.PNG" alt="jquery tabs default functionality" width="300" height="119" /></a></center></p>
<p>At first glance, you may not realize the problem with this. The content of the inactive tabs is hidden from the print view. In our requirements, we needed to print all the content for each tab, whether it was active or not. Now you begin to see the clash between interactive content and printer friendly widgets.</p>
<p>There is a solution to this problem, but it varies depending on how you setup your widgets. Here are some tips to setup the print view. For printed tabs to work, you need to create some hidden panel headers and utilize some CSS to display the hidden tabs contents. The solution I came up with contains a &#8220;Printer Friendly&#8221; link which triggers the dynamic CSS changes for printing all the tabs contents.</p>
<p><center><a href="http://blog.pearltechnology.com/wp-content/uploads/2009/09/jquery-tabs-printer-friendly.PNG#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-medium wp-image-372" title="jquery tabs printer friendly" src="http://blog.pearltechnology.com/wp-content/uploads/2009/09/jquery-tabs-printer-friendly-300x47.PNG" alt="jquery tabs printer friendly" width="300" height="47" /></a></center></p>
<p>Add the following HTML to your page where you want the locate the &#8220;Printer Friendly&#8221; link for the tab widgets.</p>
<pre name="code" language="html">
<div id="dialog-1">
<h3>Printer Friendly Here</h3>
</div>
</pre>
<p>Here is the printer friendly window that is created after clicking on the &#8220;Printer Friendly&#8221; link.</p>
<p><center><a href="http://blog.pearltechnology.com/wp-content/uploads/2009/09/jquery-tabs-printer-friendly-dialog.PNG#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-medium wp-image-375" title="jquery tabs printer friendly dialog" src="http://blog.pearltechnology.com/wp-content/uploads/2009/09/jquery-tabs-printer-friendly-dialog-299x111.PNG" alt="jquery tabs printer friendly dialog" width="299" height="111" /></a></center></p>
<p>Here is the jQuery script that enables the printer-friendly jQuery UI tabs to happen.</p>
<pre name="code" language="jscript">$(function() {
	        $("#tabs").tabs();

	        // remove any print headers that we may have added
	        $("div.printHeader").remove();

	        // assign our id for print navigation removal
	        $("#tabs&gt;ul").each(function() {
	            $(this).addClass("tab-nav");
	        });

	        // create printer friendly tab view
	        $("#tabs&gt;ul&gt;li&gt;a").each(function() {
	            // what tab is this?
	            var tabNum = $(this).attr("href").replace("#", "");

	            // get our content for this tab
	            var tabContent = $("div[id=" + tabNum + "]");

	            // prepend our print header along with tab theme style
	            $(tabContent).before("
<div class="printHeader &quot; + $(this).parent().parent().parent().attr(&quot;class&quot;) + &quot;">\n" +
    	                            "
<ul class="&quot; + $(this).parent().parent().attr(&quot;class&quot;).replace(&quot;tab-nav&quot;, &quot;&quot;) + &quot;">\n" +
	                                    "
<li>" + $(this).text() + "

\n" +
	                                "</li>
</ul>

\n" +
	                            "</div>

\n");
	        });

	        drawPrinterFriendly(); // creates printer friendly links
	    });

	    // Prints contents of a dialog
	    // source: http://www.endusersharepoint.com/2008/12/09/jquery-for-everyone-print-any-web-part/
	    // remarks: added removal of printer friendly link
	    function printDialog(tagid, title) {
	        if (tagid) {
	            var CSSContent = ".printInfo,.tab-nav { display:none;}\n.ui-tabs .ui-tabs-hide,.printHeader { display: block !important; }\n";
	            var printCss = "
<!--
\n" + CSSContent + "
-->

";
	            // build html for print page
	            // remarks: we use parent here since the dialog is in a wrapped container
	            var html = "\n\n" + $("head").html() + "\n" + printCss + "\n\n\n" + $("#" + tagid).parent().html() +
                    "\n\n";
	            var printWP = window.open("", "printWebPart"); //open new window
	            printWP.document.open();
	            //insert content
	            printWP.document.write(html);
	            printWP.document.close();
	            //open print dialog
	            printWP.print();
	        }
	    }

	    // creates printer friendly link for matching dialog H3 tags
	    function drawPrinterFriendly() {
	        // find all dialogs by their TD
	        var tags = $("*[id^='dialog-']");
	        // loop through dialogs
	        tags.each(function() {
	            //get id for print function
	            var tagid = $(this).attr("id");
	            //append an image with onClick event
	            $(this).find("h3").html("").append(
                        "
<div class="printInfo">" +
                        "  <a onclick="printDialog(&quot; + " href="##utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed">Printer Friendly" +
                        "  </a>" +
                        "</div>

"
                    );
	        });
	    }</pre>
<p>You can find the entire solution <a href="http://blog.pearltechnology.com/wp-content/uploads/2009/09/printer-friendly-jquery.zip#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed">here</a>. This solution can easily be adapted to work with other widgets (dialogs, accordions, etc.) with the inclusion of the H3 tag inside a div with id prefix &#8220;dialog-&#8221;. Possibly in the future I will create a <a href="http://plugins.jquery.com/">jQuery plugin</a> that encapsulates this functionality for simple integration into your site. Have you found a better approach for printing select portions of a page containing jQuery widgets?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pearltechnology.com/printer-friendly-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
