1 of 1 found this page helpful

Print Multiple Pages on One

    Follow the discussion and send feedback in this forum post

    The following templates are used to enhance the printing function of Mindtouch. All credit goes to carles.coll. The documentation might not be complete, so feel free to change it accordingly.

    This additional functionality consists of two templates, PrintWikiTree() and PrintMultiplePagesForm(). The first one basically loops over the subpages of a given page and does a wiki.page for every subpage. The Form template can either be used to present a form where you can paste a path to a section you want to print or it creates a link. The link is a static call to the PrintWikiTree() template with the parent page of the page the link is on.

    NOTE: This was tested for 9.12.1, but I'm sure it can be used with other versions as well.

    About

    With the standard printing function of Mindtouch one is only be able to print/ save the current page, although often it is more convenient to have several pages printed/ saved at once (e.g. the Handbook of FAQ). The standard procedure would be to create a new page and on that page loop wiki.page over the subpages of the section you want to print. This would cause a lot of useless pages that are just existing to print a set of other pages. The workaround presented here is working on the same path but only needs one "dummy" page for the printing content that is used for every multiple page print. This page is just made of a template call.

    History

    Version Date Author Description
    1.0 26-Apr-2010 baum First published version

    Credits/Special Thanks

    All credit of the original code goes to carles.coll. Thanks for help also go to DocDuck, neilW and stevenage.

    How do I install it?

    1. Create the templates (see below)

    2. Create the dummy page with the template call (see below)

    1. Templates

    a) PrintWikiTree

    1. Create a template, call it "Template:PrintWikiTree" (or rename as you desire, of course).
    2. Create a "Dekiscript" block on the template page (use the "Style" menu in the editor")
    3. Copy the code from below 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. Edit the toctext variable to match your language. Save.

    • /* Template merges all subpages of a given path into a new page */
      
      /* Input parameters */
      var pth     = $path;            // path to the parent page of the subpages to merge
      
      /* Admin parameters */
      var toctext = 'Inhaltsangabe';
      
      if ($include_toc) {
          if (String.toupper($include_toc) == 'TRUE') {
              web.html("<h1>"..(toctext).."</h1>");
              wiki.toc(page.path);
          }
      } else {
          web.html("<h1>"..(toctext).."</h1>");
          wiki.toc(page.path);
      }
      if ($include_root) {
          if (String.toupper($include_root) == 'TRUE') {
              web.html("<h1>"..wiki.getpage(pth).title.."</h1>");
              wiki.page(""..(pth));
          }
      }
      var data = wiki.getpage(pth).subpages;
      foreach (var p in data) {
          var s = '<h'..(#p.parents-#wiki.getpage(pth).parents)..' style="page-break-before: always;">'..p.title..'</h'..(#p.parents-#wiki.getpage(pth).parents)..'>';
          web.html(s);
          wiki.page(p.path);
      }

    b) PrintMultiplePagesForm

    1. Create a template, call it "Template:PrintMultiplePagesForm" (or rename as you desire, of course).  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 below 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. Edit the defaulttext, printpagepath (see below), language, imagepath, printtext, buttonpdf and buttonhtml variable to match your installation. Save.

    • /* Please adjust the Admin parameters according to your Installation (you can as well just delete the language parts
      to have a shorter template) */
      
      /* Input parameters */
      var defaulttext = 'Übersicht';                         // localized version of "Guide" or similar
      var linkText    = $text ?? $0 ?? $defaulttext;
      var static      = $stat ?? $1 ?? 0;                    // present a link ('1') or not ('0')
      
      /* Admin paramaters */
      var printpagepath = 'Hilfe/Drucken/Druckseite';        // path to the Dummy page that joins multiple pages
      var language      = 'german';                          // default is english
      var imagepath     = 'http://developer.mindtouch.com/@api/deki/files/6019/=pdficon_small.gif'; // path to "pdf image"
      var printtext     = 'Pfad zum Drucken (Hauptseite): '; // localized version of "path to print: "
      var buttonpdf     = 'PDF Ausgabe';                     // localized version of "Print PDF"
      var buttonhtml    = 'HTML Ausgabe';                    // localized version of "Print HTML"
      
      var pid      = wiki.getpage(printpagepath).id;
      <html><head>
          <script type="text/javascript">"
              $(document).ready(function(){
                  $(\"#saveaspdf\").click(function(){
                      window.location = '/@api/deki/pages/'+"..pid.."+'/pdf?path=' + escape('"..page.path.."');
                      return false;
                  });
                  $(\"#submit_pdf\").click(function(){
                      var PrtParent   = $('#PrintParent').val();
                      window.location = '/@api/deki/pages/'+"..pid.."+'/pdf?path=' + escape(PrtParent);
                      return false;
                  });
                  $(\"#submit_html\").click(function(){
                      var PrtParent   = $('#PrintParent').val();
                      window.location = '"..printpagepath.."' + '?action=print&path=' + escape(PrtParent);
                      return false;
                  });
              });
          "</script>
      </head></html>
      if (static == 1) {    
          var clinktxt;
          if (language == 'german') {
              let clinktxt = "Speichere "..linkText.." als .PDF";
          } else {
              let clinktxt = "Save "..linkText.." to .PDF";
          }
          <p>
              <a href="#" id="saveaspdf" title=(clinktxt)>
                  <img src=(imagepath) style="width: 16px; height: 16px; margin-right: 5px;" alt=(clinktxt) class="internal default" />
                  (clinktxt);
              </a>
          </p>
      } else {
          <div style="padding:15px; background-color:#eee; border:2px solid gray;">
              if (language == 'german') {
                  <p>'Diese Seite generiert eine .pdf Datei der angegebenen Seite inklusive aller Unterseiten.'</p>;
                  <p>'(';<span style="font-weight:bold;">'Beispiel:';</span>' /Pfad/zur/Seite)'</p>;
                  <p>'Um einen Link zu dieser Funktion im Wiki hinzuzufügen, fügen Sie bitte die folgende Zeile hinzu:'</p>;
                  <p><span style="font-family:'Courier New';" class="plain">'{{PrintMultiplePagesForm()}}'</span></p>;
                  <p class="caution">
                      "Aus Seiten, die funktionale Inhalte (z.B. kollabierende Elemente, Tabs, dynamische Inhalte, etc.) enthalten, können möglicherweise keine korrekten .pdf Dateien erzeugt werden. Falls Sie die folgende Fehlermeldung erhalten, enthalten die Seiten, aus denen das .pdf Dokument erzeugt werden soll, möglichweise inkompatible Inhalte.";
                      <br />;
                      <span style="font-style:italic;">;'Internal Error (500) Unable to create PDF for page id: '..(pid)..'. Please verify that Prince is installed and princexml-path is configured.';</span>;
                  </p>;
              } else {
                  <p>'This page creates a .pdf file of the page (and all sub-pages) at the entered path.'</p>;
                  <p>'(';<span style="font-weight:bold;">'Example:';</span>' /Path/To/Page)'</p>;
                  <p>'To add a link to a page that will create a .pdf file of that page and all sub-pages, at the top of the root page you wish to print, add the following line:'</p>;
                  <p><span style="font-family:'Courier New';" class="plain">'{{PrintMultiplePagesForm()}}'</span></p>;
                  <p class="caution">
                      "Pages that include funtional content (collapsing divs, dynamically generated content, etc.) may not work with this tool or the associated GuideToPDF template. If you receive the following error, the pages you are trying to convert to .pdf contain incompatible material.";
                      <br />;
                      <span style="font-style:italic;">;'Internal Error (500) Unable to create PDF for page id: '..(pid)..'.  Please verify that Prince is installed and princexml-path is configured.';</span>;
                  </p>;
              }
          </div>;
          <p>&nbsp;</p>
          <form>
              <div class="coloured">(printtext);
                  <input size="45" name="PrintParent" id="PrintParent" style="margin-right: 10px;"> </input>
                  <input type="submit" id="submit_pdf" value=(buttonpdf) style="margin-right: 10px; width: 120px;"> </input>
                  <input type="submit" id="submit_html" value=(buttonhtml) style="width: 120px;"> </input>
              </div>
          </form>
      }

    2. Dummy print page

    Go somewhere in your wiki where people do not browse/ edit normally and create a new Page (e.g. /Help/Print/Printmerges). On this page include the call to the PrintWikiTree template, like

    {{ PrintWikiTree{path: __request.args.path,include_toc: 'true'} }}

    Now edit the Admin parameter printpagepath in the PrintMultiplePagesForm template above to match this new page.

    How do I use it?

    In general you now only need to use the PrintMultiplePagesForm() to have this functionality on your Wiki.

    Examples

    Here are some examples.

    The simple call of

    {{ PrintMultiplePagesForm(); }}

    will just produce this:print.png

     

     

     

     

     

     

     

     

     

     

    The call of

    {{ PrintMultiplePagesForm('Handbook',1); }}

    will produce a link that generates a pdf consisting of all subpages to the page you use this call on.button.png

    Disclaimers

    None.

    Was this page helpful?
    Tag page

    Files 3

    FileVersionSizeModified 
    • v1
    • 11.51 kB
    • 06:15, 26 Apr 2010
    •  
    Viewing 7 of 7 comments: view all
    Cool... This is nice. Can you do something similar to a page with a bunch of hyperlinks to other pages so that a prf can be made with out actually restructuring the wiki infrastructure? Delmar
    Posted 15:31, 22 Jun 2010
    @DelmarLarsen Of course it can be done, parsing XML page contents, just post a thread on the forum and someone can help on it. edited 06:00, 23 Jun 2010
    Posted 05:59, 23 Jun 2010
    @carles.coll
    The template is great, but in my case it is sorting the pages in the pdf different than it is shown in my nav inside the wiki.
    How can I change that?
    Posted 05:02, 9 Aug 2010
    Sorting solution can be found here: http://forums.developer.mindtouch.com/showthread.php?p=42048&posted=1#post42048
    Posted 22:34, 10 Aug 2010
    @SeGo I see neilw helped you, I was on holidays thouse days :P
    Posted 03:47, 23 Aug 2010
    How can we get wiki.getpage(pth).subpages to list *all* the subpages, and not just a depth of 1? It (.subpages) seems to only be able to return the immediate subpages of the path, but not the subpage's subpages.
    Posted 12:45, 28 Sep 2010
    @mhoydis
    I had the similar problem and neilw managed to solve it on the forums. In PrintWikiTree template you have to change the line:
    var data = wiki.getpage(pth).subpages;
    to:
    var data = list.sort(wiki.getsearch("+type:wiki +path:"..string.searchescape(pth).."/*", 1000), "path");
    Posted 00:21, 24 Nov 2010
    Viewing 7 of 7 comments: view all
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by