From 3bf8bcc7d76bc0f1419335519c9e12e55a157687 Mon Sep 17 00:00:00 2001 From: Andre Herbst Date: Thu, 2 Oct 2025 16:58:47 +0200 Subject: [PATCH] DOC: add documentation about how to use negative page ranges in cat/rm/rotate Issue: #44 --- docs/user/subcommand-cat.md | 5 ++++- docs/user/subcommand-rm.md | 14 +++++++++----- docs/user/subcommand-rotate.md | 10 ++++++++++ pdfly/cat.py | 6 +++++- pdfly/rm.py | 8 ++++++++ pdfly/rotate.py | 10 ++++++++++ 6 files changed, 46 insertions(+), 7 deletions(-) diff --git a/docs/user/subcommand-cat.md b/docs/user/subcommand-cat.md index 190c7b8b..a8237473 100644 --- a/docs/user/subcommand-cat.md +++ b/docs/user/subcommand-cat.md @@ -16,6 +16,9 @@ pdfly cat --help range means all the pages of the file. PAGE RANGES are like Python slices. Remember, page indices start with zero. + When using page ranges that start with a negative value a + two-hyphen symbol -- must be used to separate them from + the command line options. Page range expression examples: : all pages. @@ -39,7 +42,7 @@ pdfly cat --help Examples - pdfly cat -o output.pdf head.pdf content.pdf :6 7: tail.pdf -1 + pdfly cat -o output.pdf head.pdf -- content.pdf :6 7: tail.pdf -1 Concatenate all of head.pdf, all but page seven of content.pdf, and the last page of tail.pdf, producing output.pdf. diff --git a/docs/user/subcommand-rm.md b/docs/user/subcommand-rm.md index ee36d4ce..f024562a 100644 --- a/docs/user/subcommand-rm.md +++ b/docs/user/subcommand-rm.md @@ -10,13 +10,17 @@ Usage: pdfly rm [OPTIONS] FILENAME FN_PGRGS... Remove pages from PDF files. - Page ranges refer to the previously-named file. + Page ranges refer to the previously-named file. A file not followed by a page range means all the pages of the file. PAGE RANGES are like Python slices. - + Remember, page indices start with zero. + When using page ranges that start with a negative value a + two-hyphen symbol -- must be used to separate them from + the command line options. + Page range expression examples: : all pages. -1 last page. @@ -44,7 +48,7 @@ Usage: pdfly rm [OPTIONS] FILENAME FN_PGRGS... Remove all pages except page seven from report.pdf, producing a single-page report.pdf. - + ╭─ Arguments ─────────────────────────────────────────────────────────────────────────────────────────────╮ │ * filename FILE [default: None] [required] │ │ * fn_pgrgs FN_PGRGS... filenames and/or page ranges [default: None] [required] │ @@ -68,6 +72,6 @@ pdfly rm document.pdf 4 Remove the first and last page of `document.pdf`, producing `output.pdf`. ``` -pdfly rm -o output.pdf document.pdf 1:-1 +pdfly rm -o output.pdf document.pdf 1:-1 -``` \ No newline at end of file +``` diff --git a/docs/user/subcommand-rotate.md b/docs/user/subcommand-rotate.md index ad66ed4e..ee1dea0d 100644 --- a/docs/user/subcommand-rotate.md +++ b/docs/user/subcommand-rotate.md @@ -13,12 +13,22 @@ pdfly rotate --help pdfly rotate --output output.pdf input.pdf 90 Rotate all pages by 90 degrees (clockwise) + pdfly rotate --output output.pdf input.pdf 90 :3 + Rotate first three pages by 90 degrees (clockwise) + + pdfly rotate --output output.pdf input.pdf 90 -- -1 + Rotate last page by 90 degrees (clockwise) + A file not followed by a page range (PGRGS) means all the pages of the file. PAGE RANGES are like Python slices. Remember, page indices start with zero. + When using page ranges that start with a negative value a + two-hyphen symbol -- must be used to separate them from + the command line options. + Page range expression examples: : all pages. -1 last page. diff --git a/pdfly/cat.py b/pdfly/cat.py index 4ed22bd2..dbc33954 100644 --- a/pdfly/cat.py +++ b/pdfly/cat.py @@ -8,6 +8,10 @@ Remember, page indices start with zero. + When using page ranges that start with a negative value a + two-hyphen symbol -- must be used to separate them from + the command line options. + Page range expression examples: : all pages. -1 last page. @@ -23,7 +27,7 @@ ::-1 all pages in reverse order. Examples - pdfly cat -o output.pdf head.pdf content.pdf :6 7: tail.pdf -1 + pdfly cat -o output.pdf head.pdf -- content.pdf :6 7: tail.pdf -1 Concatenate all of head.pdf, all but page seven of content.pdf, and the last page of tail.pdf, producing output.pdf. diff --git a/pdfly/rm.py b/pdfly/rm.py index fc859e6d..02af742d 100644 --- a/pdfly/rm.py +++ b/pdfly/rm.py @@ -8,6 +8,10 @@ Remember, page indices start with zero. + When using page ranges that start with a negative value a + two-hyphen symbol -- must be used to separate them from + the command line options. + Page range expression examples: : all pages. -1 last page. @@ -27,6 +31,10 @@ Remove pages 2 to 4 from document.pdf, producing output.pdf. + pdfly rm document.pdf -- -1 + + Removes the last page from document.pdf, modifying the original file. + pdfly rm document.pdf :-1 Removes all pages except the last one from document.pdf, modifying the original file. diff --git a/pdfly/rotate.py b/pdfly/rotate.py index 662e2594..df233c46 100644 --- a/pdfly/rotate.py +++ b/pdfly/rotate.py @@ -5,12 +5,22 @@ pdfly rotate --output output.pdf input.pdf 90 Rotate all pages by 90 degrees (clockwise) + pdfly rotate --output output.pdf input.pdf 90 :3 + Rotate first three pages by 90 degrees (clockwise) + + pdfly rotate --output output.pdf input.pdf 90 -- -1 + Rotate last page by 90 degrees (clockwise) + A file not followed by a page range (PGRGS) means all the pages of the file. PAGE RANGES are like Python slices. Remember, page indices start with zero. + When using page ranges that start with a negative value a + two-hyphen symbol -- must be used to separate them from + the command line options. + Page range expression examples: : all pages. -1 last page.