Sorting the TOC in a PDF Export

#1

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

#2

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.

0 Likes

#3

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!

0 Likes

#4

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

#5

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

0 Likes

#6

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

Tim

0 Likes

#7

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}}
0 Likes