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.
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.
| Version | Date | Author | Description |
| 1.0 | 26-Apr-2010 | baum | First published version |
All credit of the original code goes to carles.coll. Thanks for help also go to DocDuck, neilW and stevenage.
1. Create the templates (see below)
2. Create the dummy page with the template call (see below)
/* 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);
} /* 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> </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>
} 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.
In general you now only need to use the PrintMultiplePagesForm() to have this functionality on your Wiki.
Here are some examples.
The simple call of
{{ PrintMultiplePagesForm(); }}
will just produce this:
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.
None.
| File | Version | Size | Modified | |
|---|---|---|---|---|
| ||||
| ||||
| ||||
Copyright © 2011 MindTouch, Inc. Powered by
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?
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");