gettalong / hexapdf

Versatile PDF creation and manipulation for Ruby
https://hexapdf.gettalong.org
Other
1.24k stars 70 forks source link

[Proposal] Add commandline "rotate" flag? #229

Closed rubyFeedback closed 1 year ago

rubyFeedback commented 1 year ago

Trying:

hexapdf rotate foobar.pdf

results in:

Error while parsing command line:
    Invalid command: rotate

Would it be worthwhile to add a rotate functionality?

I am thinking of something like:

hexapdf rotate foobar.pdf 90°
hexapdf rotate foobar.pdf 90
hexapdf rotate=90 foobar.pdf

Or something like that. We probably only need to rotate in one direction, as after 360° we should be back at the beginning (not that Annalena Baerbock understands what 360° rotation entails to ...). So in other words, a commandline functionality to have this feature available.

We can probably do so within hexapdf as-is, such as via:

https://hexapdf.gettalong.org/examples/graphics.html

But I am asking whether that commandline functionality may make sense. (It's not a huge deal, we can just put the desired functionality from hexapdf into a standalone .rb file and then call that, but perhaps "rotate" may be useful to add to hexapdf's toolset arsenal).

rubyFeedback commented 1 year ago

I just checked on qpdf; it works there via something like:

qpdf foobar.pdf  out.pdf --rotate=90 # 90° rotation

(Interestingly, when we need a value between 90 and 45, it's a bit harder to do from the commandline. Perhaps one day we can autogenerate working GUIs from commandline scripts.)

gettalong commented 1 year ago

This is already possible for any command that takes a pages specification argument, e.g. hexapdf modify. See https://hexapdf.gettalong.org/documentation/hexapdf.1.html#pages-specification for details.

Small example:

$ hexapdf modify -i 1-er input.pdf output.pdf
gettalong commented 1 year ago

@rubyFeedback Oh, btw, page rotation in PDF only works for multiples of 90 degrees.