1 of 1 found this page helpful

Printing part of a page

    Introduction

     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.

    History

    Version Date Author Description
     1.0 11/23/2009  rberinger   Initial Release

    Requirements

    • This template requires MindTouch version: MindTouch Lyons Version 9.02 or above.

    How do I install it?

    1. Create a template, call it "Template:PrintContainer" (or rename as you desire).  You must have UNSAFECONTENT permission for this to work.
    2. Create a "DekiScript" block on the template page (use the "Style" menu in the editor")
    3. Copy the code from the end of this page and paste it into the DekiScript block.  To copy, click "expand source", then mouse over the top right corner of the source code, and click the "view source" button.  This will pop up a window with the source code.  Select all, then copy to clipboard.
    4. Make sure there isn't an extra blank paragraph after the DekiScript block! Do this every time you edit!!!  
    5. Save.

     Download the attached jQuery.Print.js file and upload to your wiki.  Remember to change the reference in the template.

    A quick note about the examples on this page

    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. 

    How do I use it?

    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.

    Arguments

    Name
    Type
    Default
    Description
     container  str? #pageText  class or id of container to print.  You MUST include the . or # 
     text  str?  Print The text for the Print Link or Button 
     button  bool  false  False = Show as Link, True = Show as Button

    Examples

     

    <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};
    Here is some text I need printed. And I only want this portion of the page.
    Print Div Only

     

    Reference(s)

     Please refer all questions and/or comments to this forum thread.

    Credits/Special Thanks

     jQuery Team.

    Template/Extension Source Code

    // 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> 
    

     

    Disclaimers

    None.

    Was this page helpful?
    Tag page

    Files 1

    FileVersionSizeModified 
    Viewing 1 of 1 comments: view all
    Hi ,

    can you please create one sample HTML for that ?

    regards,
    Hitesh Panchal
    Posted 22:12, 8 Sep 2010
    Viewing 1 of 1 comments: view all
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by