[luatex] Re-order pages

Hans Hagen j.hagen at xs4all.nl
Wed Aug 1 15:05:04 CEST 2018


On 8/1/2018 2:18 PM, Patrick Gundlach wrote:

> pdf is capable of rendering the pages which is not necessary in the order of the time written. Let's say you write 10 pages into the pdf file, you can tell afterwards that the logical order is
> 
> 1 7 2 3 4 5 6 8 9 10
> 
> Now I'd like to haven an interface to that.
> 
> The application is (as I have written in the first post) writing a table of contents. When I am at the end of a document, I know all the entries for the table of contents including the page numbers they appear on. Now instead of writing this information on the harddrive and reading it back in the second run, I could create another page (toc) and insert this as the real table of contents.
> 
> In the example above I write the table on page 7 and tell the PDF that it should display page number 7 after the first one. Of course, the visible page numbers should be in order, but this is not what I am asking.
> 
> My documents are sometimes really big (20 minutes to 40 minutes) and this would speed up things dramatically.
for that you need to adapt the page tree to flush a different order and 
i have been playing with that idea a while ago but didn't like messing 
up the backend for that (it would involve some caching and such)

i can think of a dirty hack where we have a callback that fetches the 
required page object number for each entry in the page tree and as one 
can ask for the object number that could work ok, think of (probably 
wrong but you get the idea):

local noftocpages = 2
local nofdocpages = 3

function gimmethepageobject(pagenumber)
     if pagenumber > noftocpages then
         return pdf.getpageref(pagenumber - noftocpages)
     else
         return pdf.getpageref(nofdocpages + pagenumber)
     end
end

So think about this:

1   123 doc    ->  126
2   124 doc    ->  127
3   125 doc    ->  123
4   126 toc    ->  124
5   127 toc    ->  125

no checking of errors, no checking for valid numbers ... just a simple hack

(i can add such a callback if needed)

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------


More information about the luatex mailing list