4

Using PDFtk Server, I want to rotate a PDF file 90˚ and save it in-place, to overwrite the input file. I tried the following, but it fails, probably because it starts writing before the file is finished reading.

pdftk in.pdf cat 1-endright output - > in.pdf
Elliott B
  • 200

2 Answers2

5

in your operation bash overwrite in.pdf file before call pdftk. You can't do it that way. I would recommend something like

pdftk in.pdf cat 1-endright output in-new.pdf && mv in-new.pdf in.pdf

This command also protect you when converting fail - file would not be overwriten.

undefine
  • 1,106
1

Use moreutils sponge for this:

pdftk in.pdf cat 1-endright output - | sponge in.pdf

One bug I've found is that pdftk doesn't always return non-zero on error, meaning that in.pdf may be wiped (sponge doesn't wipe if zero exit status).

Tom Hale
  • 1,242