Everyone knows that you can print a page using PrinceXML by using the print button on the tool bar at the top of a page. However this will only print server side rendered data. This means it will print only what the server renders. Any changes done with jQuery, PHP, etc... will not be presented as part of the printed page. Additionally its (sorta) an all or nothing print. I created this template to enable printing of data that is rendered by ajax requests and presented as a dashboard view. Incidentally you can target a certain section of the page to print if desired by passing the template a class or id of any valid container on the page.
Please direct all questions and/or comments the this forum thread.
| Version | Date | Author | Description |
| 1.0 | 11/23/2009 | rberinger | Initial Release |
Download the attached jQuery.Print.js file and upload to your wiki. Remember to change the reference in the template.
For all the examples on this page, the code is shown before the working example. The code is shown with the syntax extension, and looks like this:
PrintContainer()
This means that the actual code on the page should be enclosed in a DekiScript block. If you want to copy the code from this page, then use the same procedure as described in steps 2-4 above.
All you need to do is identify a container by class name or id that identifies the portion of the page to be printed. By default the id is #pageText which is a page wrapper for the fiesta skins. This may be the same on the other skins as well however I have no experience with them.
| Name | Type | Default | Description |
| container | str? | #pageText | class or id of container to print. You MUST include the . or # |
| text | str? | The text for the Print Link or Button | |
| button | bool | false | False = Show as Link, True = Show as Button |
<div id="printme">'Here is some text I need printed. And I only want this portion of the page.'</div>
PrintContainer{container: '#printme', text: 'Print Div Only'};
PrintContainer{text: 'Print Whole Page', button: true};
Please refer all questions and/or comments to this forum thread.
jQuery Team.
// AUTHOR: rberinger
// VERSION: 1.0
// DATE: 11/23/2009
// ARGUMENTS:
// container: The container class or id of the portion of the page to print
// text: The text for the print link or button
// button: (Present as a button) - true or false
var container = ($container ?? $0 ?? '#pageText');
var linktext = ($text ?? $1 ?? 'Print');
var button = ($button ?? $2 ?? false);
var id = @id;
if(button == false) {
<a id=(id) class="printit">(linktext)</a>
} else {
<input type="button" id=(id) class="printit" value=(linktext) />
}
<html><head>
<script type="text/javascript" src="http://developer.mindtouch.com/@api/deki/files/4952/=jQuery.print.js" />
<script type="text/javascript">"
$(document).ready(function() {
// Hook up the print link.
$( "..json.emit('#'..id)..").attr( 'href', 'javascript:void( 0 )' ).click(function(){
// Insert code here if you need to reformate the information within the
// Print container prior to printing.
// Print the DIV.
$("..json.emit(container)..").print();
// Cancel click event.
return( false );
});
});
"</script>
</head></html>
None.
| Images 0 | ||
|---|---|---|
| No images to display in the gallery. |
Copyright © 2011 MindTouch, Inc. Powered by
can you please create one sample HTML for that ?
regards,
Hitesh Panchal