pdfly icon indicating copy to clipboard operation
pdfly copied to clipboard

1-based ranges support

Open georgthegreat opened this issue 1 month ago • 7 comments

Please explain your intent Provide a better UX for pdfly cat.

Describe the solution you'd like Use 1-based ranges, not 0-based. Modern pdf viewer number pages from 1.

Additional context

Even pdfly cat --help shows that something is indeed wrong with the current approach:

 Page range expression examples:
     ...
     22    just the 23rd page.          :-1   all but the last page
     ...
     5:    from the sixth page onward.  -3:-1 third & second to last.

georgthegreat avatar Oct 26 '25 15:10 georgthegreat

Thinking of an even better approach one might consider: comma support, dash support and inclusive ranges.

So to cat pages 1 and 6 to 11 from a file one should type just that: pdfly cat -o out.pdf in.pdf 1,6-11. This is the range description used by PdfSam (the software I currently use to work with pdf files).

georgthegreat avatar Oct 26 '25 15:10 georgthegreat

Hi @georgthegreat

Thank you for reaching out with some interesting suggestions 👍

Use 1-based ranges, not 0-based.

This would be a backward-incomptible change, and I fear that it would bring quite some annoyance to our end-users when they upgrade pdfly... Yet it's true that all PDF viewers I know index pages starting at 1, so making pdfly pages indices starting at 1 would probably be a usability improvement. In fact, I just realized that I suggested the same idea in issue https://github.com/py-pdf/pdfly/issues/23 two years ago 🙂

I'd be curious to know what do you think about this @MartinThoma, as you originally implemented the pages ranges? 🙂

Thinking of an even better approach one might consider: comma support, dash support and inclusive ranges.

I think we could support bot the "Python ranges" syntax, and the more common "comma & dashes" syntaxes. That could probably make pdfly cat usage more intuitive.


Regarding those 2 suggestions, we should take care to make this page-indexing changes for ALL pdfly SUBCOMMANDS, of course.

@georgthegreat: would you like to contribute yourself some of those enhancements to pdfly? This project is 100% volunteer-based, so the best way to introduce such new usability features is to implement them 🙂

Lucas-C avatar Oct 27 '25 07:10 Lucas-C

@allcontributors please add @georgthegreat for ideas

Lucas-C avatar Oct 27 '25 07:10 Lucas-C

@Lucas-C

I've put up a pull request to add @georgthegreat! :tada:

allcontributors[bot] avatar Oct 27 '25 07:10 allcontributors[bot]

Maybe we should follow du cli interface and do something like pdfly cat --human-readable 1,5-8 .

As I am looking for pdfsam replacement, I will take a look on implementing this later on.

georgthegreat avatar Oct 27 '25 14:10 georgthegreat

As I am looking for pdfsam replacement, I will take a look on implementing this later on.

Thank you for volunteering! 👍

Maybe we should follow du cli interface and do something like pdfly cat --human-readable 1,5-8.

It's a good idea to take inspiration from existing standard tools 🙂 However du --human-readable is about making the output human-readable, it does not affect how it interprets CLI args.

Lucas-C avatar Oct 27 '25 16:10 Lucas-C

Let option naming to be the hardest thing to discuss inside the PR.

georgthegreat avatar Oct 27 '25 16:10 georgthegreat