Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Creating signatures with pdftk

961 views
Skip to first unread message

Peter Flynn

unread,
Aug 26, 2014, 4:03:19 PM8/26/14
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I need to create signatures for sewing and binding from a large A4
document. I used to use pstops and similar tools back in the days when
I was creating PS files, but now that I create PDF I really don't want
to convert back to PS to do the reimposition, and then convert back to
PDF, so I thought pdftk might help, but I can't find a way to specify
the papersize of the output file.

Signatures must be 5 sheets of A3, with two A4 page-images on each
side, so each signature folds to 20pp of A4. It's easy enough to
select the pages in pdftk so that they can be printed double-sided, eg

pdftk file.pdf cat 20 1 2 19 18 3 4 17 16 5 6 15 14 7 8 13 12 9 10 11

but I can't see how to make 20 and 1 into a single page of A3, 2 and
19 into the next page, 10 and 3 into the next page, and so on, and
output an A3 document.

Is this even possible? or do I have to go back to using pstops?

///Peter
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.14 (GNU/Linux)

iQEcBAEBAgAGBQJT/OgHAAoJEHt9ZfbX6inQSBkH/jCnNFwXYYXdWj2hr0KoLHJC
PD7JvWDO97wI70TTkOqsom1ePwD8b5QC/91T6KPqDNtEjetfmb2BAkvZpo/yVFY/
U5dkaAE8Nm22zYKOAcmHp6oO4945LajZ5HFWlc5B+fABIYUZWKYs/lTHLHsNV8kc
Uv7UFwyRGyjkfQCJ23LiNj8jybaxDm0ywG3Cl/RxMcuMH2Pn1AxWHozQE997yE/t
prbnToDl0eRPP1CCFzcOTJz9mADxTlKYXzLV4Es/cSRRteu6DfZRl3krG19vYo4r
aOENjdlkujBivk6wrWyqdLOtaqKiuRiMz4VJ4PPXvTalrzydVWno+eU1fkdewuk=
=Msyq
-----END PGP SIGNATURE-----

Lutrin

unread,
Aug 26, 2014, 8:16:20 PM8/26/14
to
On Tue, 26 Aug 2014 21:03:19 +0100, Peter Flynn ci disse:

> Signatures must be 5 sheets of A3, with two A4 page-images on each side,
> so each signature folds to 20pp of A4. It's easy enough to select the
> pages in pdftk so that they can be printed double-sided, eg
>
> pdftk file.pdf cat 20 1 2 19 18 3 4 17 16 5 6 15 14 7 8 13 12 9 10 11
[...]
in case your document has many many pages (500 or more, for instance) it
is a very tedious task calculating manually the signatures, so this
shellscript can help you (I wrote for myself some time ago for the same
task)
so, if you have a 600 pages long document and you need to create 600/20=30
signatures, of 20 pages, you need to type, after saved the following
script in a file
named *signatures-maker*

for i in `seq 20 20 600`; do ./signatures-maker $i 20; done

you will have (in the first column with square brackets the progressive
number of signature: (since text can be wrapped, select and open in your
editor to see rightly)

1] 20 1 2 19 18 3 4 17 16 5 6 15 14 7 8 13 12 9 10 11
2] 40 21 22 39 38 23 24 37 36 25 26 35 34 27 28 33 32 29 30 31
3] 60 41 42 59 58 43 44 57 56 45 46 55 54 47 48 53 52 49 50 51
4] 80 61 62 79 78 63 64 77 76 65 66 75 74 67 68 73 72 69 70 71
5] 100 81 82 99 98 83 84 97 96 85 86 95 94 87 88 93 92 89 90 91
6] 120 101 102 119 118 103 104 117 116 105 106 115 114 107 108 113
112 109 110 111
7] 140 121 122 139 138 123 124 137 136 125 126 135 134 127 128 133
132 129 130 131
8] 160 141 142 159 158 143 144 157 156 145 146 155 154 147 148 153
152 149 150 151
9] 180 161 162 179 178 163 164 177 176 165 166 175 174 167 168 173
172 169 170 171
10] 200 181 182 199 198 183 184 197 196 185 186 195 194 187 188 193
192 189 190 191
11] 220 201 202 219 218 203 204 217 216 205 206 215 214 207 208 213
212 209 210 211
12] 240 221 222 239 238 223 224 237 236 225 226 235 234 227 228 233
232 229 230 231
13] 260 241 242 259 258 243 244 257 256 245 246 255 254 247 248 253
252 249 250 251
14] 280 261 262 279 278 263 264 277 276 265 266 275 274 267 268 273
272 269 270 271
15] 300 281 282 299 298 283 284 297 296 285 286 295 294 287 288 293
292 289 290 291
16] 320 301 302 319 318 303 304 317 316 305 306 315 314 307 308 313
312 309 310 311
17] 340 321 322 339 338 323 324 337 336 325 326 335 334 327 328 333
332 329 330 331
18] 360 341 342 359 358 343 344 357 356 345 346 355 354 347 348 353
352 349 350 351
19] 380 361 362 379 378 363 364 377 376 365 366 375 374 367 368 373
372 369 370 371
20] 400 381 382 399 398 383 384 397 396 385 386 395 394 387 388 393
392 389 390 391
21] 420 401 402 419 418 403 404 417 416 405 406 415 414 407 408 413
412 409 410 411
22] 440 421 422 439 438 423 424 437 436 425 426 435 434 427 428 433
432 429 430 431
23] 460 441 442 459 458 443 444 457 456 445 446 455 454 447 448 453
452 449 450 451
24] 480 461 462 479 478 463 464 477 476 465 466 475 474 467 468 473
472 469 470 471
25] 500 481 482 499 498 483 484 497 496 485 486 495 494 487 488 493
492 489 490 491
26] 520 501 502 519 518 503 504 517 516 505 506 515 514 507 508 513
512 509 510 511
27] 540 521 522 539 538 523 524 537 536 525 526 535 534 527 528 533
532 529 530 531
28] 560 541 542 559 558 543 544 557 556 545 546 555 554 547 548 553
552 549 550 551
29] 580 561 562 579 578 563 564 577 576 565 566 575 574 567 568 573
572 569 570 571
30] 600 581 582 599 598 583 584 597 596 585 586 595 594 587 588 593
592 589 590 591

============================================================
#!/bin/bash
#
# usage:

# for i in `seq 16 16 160`; do ./signatures-maker $i 16; done
# or:
# for i in `seq 32 32 160`; do ./signatures-maker $i 32; done
#



pages=$1
consecutivesheets=$2

if [ $(( $pages % 4 )) -eq 0 ]
then

pages4="$(( $pages-($consecutivesheets/2) ))"
first="$(( $pages-$consecutivesheets+1 ))"
#echo "first is $first"

for ((x=$pages, y=$first;x>=$pages4, y<=$pages4;x--, y++)); do echo "$x
$y"; done | awk 'NR %2==1 {print $1, $2} NR % 2==0 { print $2, $1 }' | tr
'\n' ' ' | xargs
elif
[ $(( $pages / 4 )) -eq 0 ]
then
#echo "number $pages is not a multiple of 4"
val0="$(( 4-$pages ))"
else val1="$(( $pages/4 ))"
#echo "number $pages is not a multiple of 4"
val2="$(( $val1+1 ))"
val3="$(( $val2*4 ))"
val4="$(( $val3-$pages ))"
blankandpages="$(( $pages+$val4 ))"
pages4="$(( $blankandpages/2 ))"
#echo "adding $val4 blank pages" ; sleep 1s
for ((x=$blankandpages, y=1;x>=$pages4, y<=$pages4;x--, y++)); do echo "$x
$y "; done | awk 'NR %2==1 {print $1, $2} NR % 2==0 { print $2, $1 }' | tr
'\n' ' '| xargs
fi

exit 0
=======================================================================
> I can't see how to make 20 and 1 into a single page of A3, 2 and 19
> into the next page, 10 and 3 into the next page, and so on, and output an
> A3 document.
[...]
"In many ways" (as Gandalf the Wizard said once to Bilbo and once again to
Frodo):

Mainly, you can use the power of

*Multivalent.jar"
- - http://goo.gl/QGgvb (last free version with pdf tools included -
current Multivalent.jar hosted on sourceforge has no more pdf tools
inside)

you will pass to Multivalent the pdf file with pages reordered thaks to
pdftk (technically speaking: *shuffled for imposition*)

syntax:

java -cp path...to/Multivalent.jar tool.pdf.Impose -dim 2x1 -paper
42x29.7cm file.pdf

Impose tool will pick pages from pdf file with reordered pages, placing,
coupled, on an A3 horizontal sheet

this task, to say the truth, can be done also with the only Multivalent
tools (without pdftk, but I illustrated a way to obtain signatures of
pages automatically since you asked for a pdftk)

in fact Multivalent.jar can, at once, reorder and impose pages in
signatures:

syntax

assuming we want signatures of 20 pages (5 quarters) from a book of 100
pages:

java -cp path...to/Multivalent.jar tool.pdf.Impose -dim 2x1 -paper
42x29.7cm -verbose -layout
"20,1,2,19,18,3,4,17,16,5,6,15,14,7,8,13,12,9,10,11" file.pdf

sample input pdf file
- http://snipr.com/297dd8c (short url)
- http://www.pdfhost.net/index.php?
Action=Download&File=4687b84d2770bc5f67ab77e2322e9280

sample output with signatures of 20 pages (5 quarters) imposed in A3 format
- http://snipr.com/297ddcq (short url)
- http://www.pdfhost.net/index.php?
Action=Download&File=66070c985825e50daeb8aad18b9c5af1

as you can see, the 5 signatures are indeed:

20 1 2 19 18 3 4 17 16 5 6 15 14 7 8 13 12 9 10 11
40 21 22 39 38 23 24 37 36 25 26 35 34 27 28 33 32 29 30 31
60 41 42 59 58 43 44 57 56 45 46 55 54 47 48 53 52 49 50 51
80 61 62 79 78 63 64 77 76 65 66 75 74 67 68 73 72 69 70 71
100 81 82 99 98 83 84 97 96 85 86 95 94 87 88 93 92 89 90 91

the main advantage of Multivalent is its ability to add the needed blank
pages, if the total number of pages in pdf is not a multiple of choosen
signature

> Is this even possible?
[...]
it is possible as you can see

> or do I have to go back to using pstops?
[...]
no! it is a loss of time (and often of quality) passing from ps to return
to pdf from an existent pdf

--
Puppy Linux wiki: http://dokupuppylinux.info
Puppy Linux Forum: http://www.italianpuppy.org/
Windows me genuit, Ubuntu rapuere / tenet nunc Puppy Linux...
dropbox 2GB free - http://db.tt/Vc6IeN4

Peter Flynn

unread,
Aug 28, 2014, 5:05:23 PM8/28/14
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 08/27/2014 01:16 AM, Lutrin wrote:
> in case your document has many many pages (500 or more, for
> instance) it is a very tedious task calculating manually the
> signatures, so this shellscript can help you (I wrote for myself
> some time ago for the same task)

Thanks very much. I have a similar tool I wrote (strange that everyone
writes their own :-)

>> I can't see how to make 20 and 1 into a single page of A3, 2 and
>> 19 into the next page, 10 and 3 into the next page, and so on,
>> and output an A3 document.

> "In many ways" (as Gandalf the Wizard said once to Bilbo and once
> again to Frodo):
>
> Mainly, you can use the power of Multivalent.jar

I started using good old ps2ps because it has all this built in: it
only needs the cycle giving once.

pstops -pa3
"20:19L(29.7cm,0)+0L(29.7cm,21cm),1L(29.7cm,0)+18L(29.7cm,21cm),17L(29.7cm,0)+2L(29.7cm,21cm),3L(29.7cm,0)+16L(29.7cm,21cm),15L(29.7cm,0)+4L(29.7cm,21cm),5L(29.7cm,0)+14L(29.7cm,21cm),13L(29.7cm,0)+6L(29.7cm,21cm),7L(29.7cm,0)+12L(29.7cm,21cm),11L(29.7cm,0)+8L(29.7cm,21cm),9L(29.7cm,0)+10L(29.7cm,21cm)"
file.ps file-imposed.ps

> the main advantage of Multivalent is its ability to add the needed
> blank pages, if the total number of pages in pdf is not a multiple
> of choosen signature

Ultimately I did it using LaTeX and pdfpages. This too can add blank
pages, and has the advantage that pdfpages has an option for automatic
imposition (just tell it signature=20). 7 seconds and the job was done.

>> Is this even possible?
> [...] it is possible as you can see

Not using pdftk alone. Strange for such a powerful tool that it is
unable to handle signatures, and unable to output to a paper sizes
different from the input.

>> or do I have to go back to using pstops?
> [...] no! it is a loss of time (and often of quality) passing from
> ps to return to pdf from an existent pdf

The time wasn't an issue: pdftops took 5 seconds to make the PS file;
pstops took a second to reorder the pages, and pstopdf took another 10
seconds to recreate the PDF, all without loss, even preserving the
CMYK of the embedded bitmap images. But the LaTeX route was much faster.

///Peter

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.14 (GNU/Linux)

iQEcBAEBAgAGBQJT/5mSAAoJEHt9ZfbX6inQAloIAJbNB8YLaEsjfwQuo18i2yWv
jH+26xRDvzqprqqxPp2vqnq9p3X8EbiWDF6QM6fdHV/LkeKud59TwEAtiVO67j2y
kvcFA7V/ZP3cwg83FfgKKEVt/KOScZnftbUgWrUzl/utVlGHOmGfkPuSKjZAUTGZ
zlksJRaq+bYb4L0Yvy9vWf7lpY7a1Ghao2VlOIWWHSTmmUNyoLgB/gC9usPvGOsY
me91F2YN8ZD6I+7o0HbkxGaEgue/qNOxMn4kMNvMfo6Wvr08j7BYzBLkZmXcczcd
uFUHYIXgINydzDqUSqOralkMJp0Pw/YcsIIRULnVoYHB/64MleM+hWAXGT7ppWA=
=TOOS
-----END PGP SIGNATURE-----

Lutrin

unread,
Aug 28, 2014, 6:58:39 PM8/28/14
to
On Thu, 28 Aug 2014 22:05:23 +0100, Peter Flynn ci disse:

> Ultimately I did it using LaTeX and pdfpages. This too can add blank
> pages, and has the advantage that pdfpages has an option for automatic
> imposition (just tell it signature=20). 7 seconds and the job was done.
[...]
pdfpages is a great tool, but not for small environment since it needs the
latex companion (not a little dependency)

>> Is this even possible?
> [...] it is possible as you can see

> Not using pdftk alone. Strange for such a powerful tool that it is
> unable to handle signatures, and unable to output to a paper sizes
> different from the input.
[...]
you can suggest to pdftk developer Sid Steward to add feature

- https://www.pdflabs.com/

since it now sells the GUI for pdftk, it can be a good addition to boost
sales
- https://www.pdflabs.com/tools/pdftk-pro/

to say the truth, there is a possible workaround to perform imposition
with only help of pdftk, but it involves to change the mediabox of any pdf
page into pdf file, to add a blank space alongside equivalent to original
mediabox of page and then use the multistamp features (present from pdftk
1.45 if I remember) to stamp conveniently the needed pages in the blank
added spaces so to have signatures you need , i started to write a script
but I abandoned the scripting after I discovered that altering the
mediabox values via sed, is not a reliable way to do what need to be done
(imposition) and that RIP processord of printers can produce mistakes
interpreting wrongly the pdf so made that remain malformed also after
repar with the pdftk itself or with qpdf

I abandoned pstools years ago, it may be a bad luck, but in my experiences
in printing industries, I unfortunately encountered many pdf that were
strangerly degraded passing from pstools, so I prefer act directly on pdf

tlvp

unread,
Aug 30, 2014, 2:34:27 AM8/30/14
to
On Tue, 26 Aug 2014 21:03:19 +0100, Peter Flynn wrote:

> I need to create signatures for sewing and binding from a large A4
> document. I used to use pstops and similar tools back in the days when
> I was creating PS files, but now that I create PDF I really don't want
> to convert back to PS to do the reimposition, and then convert back to
> PDF, so I thought pdftk might help, but I can't find a way to specify
> the papersize of the output file.
>
> Signatures must be 5 sheets of A3, with two A4 page-images on each
> side, so each signature folds to 20pp of A4. It's easy enough to
> select the pages in pdftk so that they can be printed double-sided, eg
>
> pdftk file.pdf cat 20 1 2 19 18 3 4 17 16 5 6 15 14 7 8 13 12 9 10 11
>
> but I can't see how to make 20 and 1 into a single page of A3, 2 and
> 19 into the next page, 10 and 3 into the next page, and so on, and
> output an A3 document.
>
> Is this even possible? or do I have to go back to using pstops?

Here at TLVP we do something like that "all the time", as follows, though
it's a matter of putting pp 2&3 of A5-size PDF files onto one side of an A4
sheet, and pp. 4&1 (in that order) onto the other. (That is, our signatures
are single-sheet, 4-page, duplex spreads. Modify accordingly for your use.)

We simply reorder our A5 text pages into the page order 2 3 4 1 6 7 8 5
(etc.) through to the end (maybe 78 79 80 77), open the reordered PDF file
in any (free) PDF reader software (Adobe, or any other), and then print to
A4 pages, full duplex, 2-up, using 100% as reduce/enlarge figure.

For your purposes, I guess you'd re-shuffle your set of 20 A4 pages at a
time from 1 ... 20 to 20 1 2 19 18 3 4 17 16 5 6 15 14 7 8 13 12 9 10 11
and then open your reordered PDF file in any (free) PDF reader software
(Adobe, or any other), and print to A3 pages, full duplex, 2-up, again
using 100% as reduce/enlarge figure.

So: pdftk to do the reshuffling, and then neither pdftk nor pstops but just
your favorite PDF reading software to do the full-duplex, 2-up, printing of
the reshuffled pages. More signatures? Just repeat. HTH. Cheers, -- tlvp
--
Avant de repondre, jeter la poubelle, SVP.
0 new messages