I'm creating a workflow for booklet printing with 2 pages on an open spread:
- Use R to create the page sequence
- Use pdftk to repaginate the pdf
- Use lp to print the 2-up booklet
I've written a loop for repaginating pdfs for booklet/saddle stitch sequence. For an 8-pg booklet, the print sequence should be "8 1 2 7 6 3 4 5". I can create the sequence in the following loop but don't know how to output it into a single line with each page number separated with a space.
p <- 16 # number of pages in a saddle stitch, multiple of 4
p.seq <- c(1:p) # page sequence
p2 <- p/2
for (i in 1:p2) {
ifelse(p.seq[i] %% 2 == 0, # true if even number
print(paste(i, p - i + 1, sep=" ")),
print(paste(p - i + 1, i, sep=" "))
)
}
Tried to use cat(..., append=TRUE) instead of print, but that stops the loop.
Try this
If you want to be able to save the result (i.e. not just
print/cated on the console), you could write a functionf:You could use it in a bash script then
A more fail-safe version of the R function could be
Alternatively, to store a
forloop result, you could initialize a listresthat you canunlistafterwards.to
catit: