Printing pages where content is output from a module

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
IanB
New Member
New Member
Posts: 6
Joined: Sat May 30, 2009 1:55 am

Printing pages where content is output from a module

Post by IanB »

Hi guys. I have looked and looked for solution to what I would think is a common problem.
I am trying to print a page where content has been created by a module.
The basic print template simply prints the {content}. This is ok where the content is 'static' but how do I get a page which has been defined as the target page for output from a module such as CGCalendar via option detailpage="this-page" for example. The {content} of a page like this is basically empty.
Another really simple example would be the page set up for the results of a Search.
It's on the screen ok but when you hit the print icon - nothing.
There must be a simple solution.

Thanks
cms_man
Forum Members
Forum Members
Posts: 12
Joined: Mon May 04, 2009 8:00 pm

Re: Printing pages where content is output from a module

Post by cms_man »

Hi IanB,

Here is your  solution.

http://winfolinx.com/tips/howto/various/printready.htm

It is a simple  javascript that do the job. You may difine the print area by  adding div print tags.

Code: Select all

<a href="javascript:void(printSpecial())">Print this Page</a>

Code: Select all

<div id="printReady">
<p>Hello World! Your Printable Page Content Goes Here</p>
</div>

Includer this  in the header

Code: Select all

{literal}
<__script__ language="JavaScript">
var gAutoPrint = true; // Flag for whether or not to automatically call the print function

function printSpecial()
{
	if (document.getElementById != null)
	{
		var html = '<__html>\n<HEAD>\n';

		if (document.getElementsByTagName != null)
		{
			var headTags = document.getElementsByTagName("head");
			if (headTags.length > 0)
				html += headTags[0].innerHTML;
		}
		
		html += '\n</HE' + 'AD>\n<BODY>\n';
		
		var printReadyElem = document.getElementById("printReady");
		
		if (printReadyElem != null)
		{
				html += printReadyElem.innerHTML;
		}
		else
		{
			alert("Could not find the printReady section in the HTML");
			return;
		}
			
		html += '\n</BO' + 'DY>\n</HT' + 'ML>';
		
		var printWin = window.open("","printSpecial");
		printWin.document.open();
		printWin.document.write(html);
		printWin.document.close();
		if (gAutoPrint)
			printWin.print();
	}
	else
	{
		alert("Sorry, the print ready feature is only available in modern browsers.");
	}
}

</__script>
{/literal}
Post Reply

Return to “Modules/Add-Ons”