Sorting the TOC in a PDF Export

XWiki 9.11.3. We are generating a PDF export of a single page, with several dozen children. The child page tree is only one level deep. The root page has a documentTree which shows the children in alphabetical order based on folder name (identical to file name for each article) which is great. This forms a visual table of contents for the site.

When we generate a PDF Export of the root page, and include children, the pages in the PDF TOC come out in a random order, apparently by creation date. SOMETIMES they come out in alphabetical order as desired, but itā€™s random.

Iā€™ve read https://network.xwiki.com/xwiki/bin/view/DocXE981En/CustomizeExportLookAndFeel and https://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/Configuration/#HCustomizingthePDFexportLook26Feel and tried overriding the pdf.vm in the skin, adding a $sorttool.sort($pages, ā€œfullNameā€). Iā€™ve tried overriding the macros.vm includeChildren method, adding a the same sort to the child pages. Neither has any effect.

How can we get a reliably sorted TOC in the PDF Export?

1 Like

Just a note, the only work-around Iā€™ve been able to come up with is to create a new separate page with an {{include}} macro for each of the child pages in the correct order, which I can print out.

However, Itā€™s a maintenance headache, and the page is extremely slow to load as it is including 51 pages and a lot of content.

Hello,

I know this thread is quite old, but Iā€™m stuck at the same problem. Did you ever find a better solution to getting the correct page order?

Thank you!

Hi! No, there has been no progress, so we are continuing to generate our PDF ā€˜by handā€™, creating a separate page of links to get the results in the right order.

1 Like

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. Replace ā€œXWD_ā€ with ā€œd.ā€ and add it to the loop.

I hope this is helpful.
Tim

@fourthchakra my script basically automates what you were doing with {{include}} macros.

Tim

One more, and then Iā€™ll stop posting on this. I had a ā€œChildrenā€ macro on my home page for the book, but it shows a subset and then ā€œ7 moreā€ at the bottom, which was inconvenient. Iā€™ve now changed my home page to whatā€™s below, and itā€™s better.

Tim

{{python}}
print "Chapters:"
sql = "where doc.parent='"+doc.fullName+"' 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+">>doc:"+item+"]]"
print ""
print "Other Material:"
sql = "where doc.parent='"+doc.fullName+"' and doc.title like '%DO NOT PRINT%' order by doc.title"
for item in xwiki.searchDocuments(sql):
  d = xwiki.getDocument(item)
  print "* [["+d.title+">>doc:"+item+"]]"

{{/python}}