Post without Account — your post will be reviewed, and if appropriate, posted under Anonymous.

Rearrange pages

  • 5 Replies
  • 713 Views
*

Offline sciurius

  • Jr. Member
  • **
  • 67
    • View Profile
    • Website
Rearrange pages
« September 05, 2017, 05:13:55 AM »
Maybe I'm overlooking something trivial, but how can I rearrange the pages in a PDF document?

For example, a document has just been created (so I still have it in core) and I want to shuffle some pages.

*

Offline Phil

  • Global Moderator
  • Sr. Member
  • *****
  • 353
    • View Profile
Re: Rearrange pages
« Reply #1: September 05, 2017, 09:50:13 AM »
Offhand, I can't think of any built-in function to do that. It doesn't sound like something that would be used often enough to warrant building into PDF::Builder. There are plenty of utilities out there to extract selected pages from a complete PDF document, and glue pages together in a given order (although this may take several passes of the file to get it done). Of course, updating any content such as page numbers would be outside the scope of such a utility.

You mentioned that you had just created the PDF, and it may not even be yet written to file. Other than outputting the pages in the desired order in the first place, could you give an example of something where it might be reasonable to have pages might come out in the wrong order, and need to rearrange them? Remember that you can output a sequence of pages, and then insert a page in-between any two. One of the examples illustrates this.  Perhaps this would satisfy your needs?

*

Offline sciurius

  • Jr. Member
  • **
  • 67
    • View Profile
    • Website
Re: Rearrange pages
« Reply #2: September 05, 2017, 12:06:50 PM »
The challenge at hand is that after typesetting several pages, I want to add a table of contents. And I want this table of contents to precede te pages themselves.
Page numbers do not matter (the TOC has its own numbering).

There are some ways to do this, I was just wondering if shuffling the pages array was possible.

*

Offline Phil

  • Global Moderator
  • Sr. Member
  • *****
  • 353
    • View Profile
Re: Rearrange pages
« Reply #3: September 05, 2017, 03:32:36 PM »
If you haven't yet output the file, there might be a way to rearrange the page ordering. However, I think it would be a lot easier to insert front end matter pages (such as TOC) before page 1 (regular content). Internally, that may very well be shuffling the page order, but you don't have to see the dirty internals. See examples/012_pages as an example. If you want to insert multiple pages, I don't know offhand whether you just use page() after page(1), or if you have to do page(2), page(3), etc. -- I will think about expanding the example.

*

Offline sciurius

  • Jr. Member
  • **
  • 67
    • View Profile
    • Website
Re: Rearrange pages
« Reply #4: September 06, 2017, 02:52:58 AM »
Yes, you have to do page(2) after page(1) and so on. This works fine but (in my case) requires some additional calculations to get page numbers and references right. But it is no doubt more safe than hacking the internal arrays.

*

Offline Phil

  • Global Moderator
  • Sr. Member
  • *****
  • 353
    • View Profile
Re: Rearrange pages
« Reply #5: October 25, 2017, 04:18:43 PM »
By the way, I did augment 012_pages to show insertion of three TOC pages i, ii, and iii before page 1, so it seems to work well.