Group child pages in order for printing (RTF or PDF export)

Last modified by Tim Meneely on 2021/03/18 11:28

cogCreates a page containing the titles and text content of all sibling pages, to allow export to RTF or PDF. Ensures pages are ordered by title alphabetically (unlike the standard export). Snippet is in Python.
Type
Category
Developed by

Tim Meneely

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Table of contents

Description

Warning: I'm new to XWiki, and in particular to scripting it - but I found a way to do what I want that seems to do what you want, using a script (I used Python because I know Python).

My situation:

  • I'm writing a novel in xWiki.
  • Using xWiki 11.6. I didn't research backward compatibility.
  • I have a single "parent" page that's not very meaningful (and it gets ignored in my script), and all the information I want to print is in child pages off of that.
  • The titles of the child pages are what I want to sort on; I start them with sequence numbers to make this obvious, e.g, "0001 First page," "0002 Page that will print second," etc.
  • My child pages are only one layer deep. Layers could be accommodated with a loop; I didn't (yet).

What I want:

  • To print the whole novel, except:
  • There are some child pages I don't want to print. I created my own convention: Their titles contain the phrase, "DO NOT PRINT". (Position within the title doesn't matter).
  • I want to print the page title as an H2, then the page contents, then a breaker line.

What I did:

  • Created a new and dedicated child page (called "Entire book DO NOT PRINT").
  • Put the Python script below on that child page (clicked on "Source" and pasted this).
  • Put a link to this child page on the parent page. When I want to export the whole story, I go to this child page and just export (PDF, RTF, whatever) that single page.
{{python}}
sql = "where doc.parent='"+doc.parent+"' and doc.title not like '%DO NOT PRINT%' order by doc.title"
for item in xwiki.searchDocuments(sql):
 d = xwiki.getDocument(item)
 print "==",d.title,"=="
 print d.content
 print "----"
{{/python}}

(The four lines after the "for item..." line are indented two spaces. Python...)

Other characteristics you could print (other than "d.title" and "d.content") would be I think those listed on [this link in the docs.](https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/DatabaseSchema/DsXWikiDoc/) Replace "XWD_" with "d." and add it to the loop.

I hope this is helpful.
Tim

Get Connected