Split Document into Pages

Get help using and writing Nisus Writer Pro macros.
Post Reply
adryan
Posts: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Split Document into Pages

Post by adryan »

G'day, all

We have a number of Macros (mostly thanks to Kino and Philip) that will split documents at various points (such as Page Breaks, Section Breaks and Section Headings).

What I need now, though, is a Macro that will split a document at page wraps (for want of a better term), regardless of whether or not a page concludes with a deliberately inserted Page Break.

If a Page Break is present, split there (and remove the Page Break). If no Page Break is present, split between two characters whose Page Numbers differ. Things might be a bit more complicated in this latter scenario than I have suggested, as one page may contain only an image or footnotes rather than "standard" text.

Hitherto, I would either manually insert Page Breaks where needed and then use the Split Document by Section Breaks Macro, or I would convert the Nisus document to a PDF document and then use an Automator-generated application to split the resulting PDF file into pages.

All of this is part of a page imposition scheme I have devised. The individual pages are reordered according to a Numbers spreadsheet I constructed that takes into account the number of pages in a document (with blank ones added if necessary) and the desired number of sheets per signature (which could depend on paper thickness, among other things). The reordered pages are combined into a single document for printing. The whole thing is controlled by an AppleScript script which calls the Numbers file and Nisus Macros. No doubt a single Nisus Macro could do the lot; its inclusion in the standard set would be a great asset.

For the moment, I'd be satisfied with a Split Document into Pages Macro. I hope someone can help.

Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
User avatar
xiamenese
Posts: 543
Joined: 2006-12-08 00:46:44
Location: London or Exeter, UK

Re: Split Document into Pages

Post by xiamenese »

As an aside, I've used this http://cheapimpostor.com on PDFs from NWP. Did the impositioning well, especially considering the price. I haven't used it for a long time, though, but your post prompted me to look it up to see if it is still being developed/maintained … it is.

:)

Mark
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Split Document into Pages

Post by phspaelti »

Hello Adrian,

I haven't tried to write a whole macro for this, but here would be my starting point.

Code: Select all

$doc = Document.active
$text = $doc.text
$pageRanges = Array.new
$x = 0
while $x < $text.length
    $range = $text.rangeOfPageAtIndex $x
    $pageRanges.push $range
    $x = $range.bound
end
With this approach you should be able to copy out the pages and save them with suitable names into a folder. But of course there are tons of questions about all of this. For one all sorts of automatic content would probably be altered (say lists which cross pages). Page numbers will be lost. If your text is justified, the last line would lose the justification. Hopefully floating content is anchored on the page it appears, or things will look weird. And so on.

So depending on what kind of result you are looking for this might require a lot more work.
philip
adryan
Posts: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Split Document into Pages

Post by adryan »

G'day, Mark, Philip et al

Thanks for pointing me in the direction of Cheap Impostor, Mark. I suspect I've already done most of the hard work for page imposition for my own present purposes, so I don't think I need to pay for more software, but I've filed it away in case I ever do.

And thanks for the hint and the valuable insights, Philip. They hit the nail right on the head, albeit meaning I will abandon the idea of splitting the document into pages along the lines I had hoped for.

I am revisiting this project after a long absence. I think one of the main reasons I split the document into single-page PDF files was to deal with the justification problem Philip alluded to. It also set in concrete things like page numbers and List Item numbers, such that they remained unchanged by reordering of the pages. The reason I now wanted to work with RTF files only was to facilitate margin adjustments for left and right pages in two-page spreads. I thought I needed to do this adjustment after the pages had been reordered.

Page numbers can be dealt with by using Tools > Automatic Content > Convert to Fixed Content. However, this does not work for List Item numbers. A List that spans multiple pages will be renumbered on all pages but the first on which it appears. So thanks for reminding me of this problem with Lists, Philip. This and your other provisos have prompted me to rethink my assumptions, to the extent I have now had The Great Insight…

…which is that pages retain their (left or right) sidedness when reordered for page imposition purposes.

This means that one can use Nisus Writer tools to do all the desired formatting on the original RTF document before converting it to a PDF file which can be split into single-page files for reordering for page imposition and printing purposes. No further work need be done on formatting or numbering.

So I think this gets me where I need to be. Thanks for grappling with the problem.

Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
Post Reply