From 342995cefc2706c745a639e52b4fe5daa8d4f3c8 Mon Sep 17 00:00:00 2001 From: mlonghin7 Date: Sun, 6 Jul 2025 20:31:28 +0200 Subject: [PATCH 01/15] add rm docs --- docs/user/subcommand-rm.md | 72 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 docs/user/subcommand-rm.md diff --git a/docs/user/subcommand-rm.md b/docs/user/subcommand-rm.md new file mode 100644 index 00000000..7aca3d1b --- /dev/null +++ b/docs/user/subcommand-rm.md @@ -0,0 +1,72 @@ +# meta + +Remove pages from PDF files. + +## Usage + +``` +Usage: pdfly rm [OPTIONS] FILENAME FN_PGRGS... + + Remove pages from PDF files. + + 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. + + Page range expression examples: + + : all pages. -1 last page. + 22 just the 23rd page. :-1 all but the last page. + 0:3 the first three pages. -2 second-to-last page. + :3 the first three pages. -2: last two pages. + 5: from the sixth page onward. -3:-1 third & second to last. + + The third, "stride" or "step" number is also recognized. + + ::2 0 2 4 ... to the end. 3:0:-1 3 2 1 but not 0. + 1:10:2 1 3 5 7 9 2::-1 2 1 0. + ::-1 all pages in reverse order. + + Examples + pdfly rm -o output.pdf document.pdf 2:5 + + Remove pages 2 to 4 from document.pdf, producing output.pdf. + + pdfly rm document.pdf :-1 + + Removes all pages except the last one from document.pdf, modifying the original file. + + pdfly rm report.pdf :6 7: + + 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] │ +╰─────────────────────────────────────────────────────────────────────────────────────────────────────────╯ +╭─ Options ───────────────────────────────────────────────────────────────────────────────────────────────╮ +│ * --output -o PATH [default: None] [required] │ +│ --verbose --no-verbose show page ranges as they are being read [default: no-verbose] │ +│ --help Show this message and exit. │ +╰─────────────────────────────────────────────────────────────────────────────────────────────────────────╯ +``` + +## Examples + +Remove the 5th page of the pdf, modifying the original file + +``` +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 + +``` \ No newline at end of file From 6c5c1f248f36ef12d06109b26296ef6a553c44fc Mon Sep 17 00:00:00 2001 From: mlonghin7 Date: Sun, 6 Jul 2025 20:35:00 +0200 Subject: [PATCH 02/15] fix rm docs --- docs/user/subcommand-rm.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/user/subcommand-rm.md b/docs/user/subcommand-rm.md index 7aca3d1b..f9439ef0 100644 --- a/docs/user/subcommand-rm.md +++ b/docs/user/subcommand-rm.md @@ -5,6 +5,7 @@ Remove pages from PDF files. ## Usage ``` +$ pdfly rm --help Usage: pdfly rm [OPTIONS] FILENAME FN_PGRGS... Remove pages from PDF files. From 8f8b1a93fc62071b7503eda76c174415c5298ba0 Mon Sep 17 00:00:00 2001 From: mlonghin7 Date: Sun, 6 Jul 2025 20:38:15 +0200 Subject: [PATCH 03/15] add compress docs --- docs/user/subcommand-compress.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 docs/user/subcommand-compress.md diff --git a/docs/user/subcommand-compress.md b/docs/user/subcommand-compress.md new file mode 100644 index 00000000..88c38c94 --- /dev/null +++ b/docs/user/subcommand-compress.md @@ -0,0 +1,29 @@ +# meta + +Compress a PDF. + +## Usage + +``` +$ pdfly compress --help + Usage: pdfly compress [OPTIONS] PDF OUTPUT + + Compress a PDF. + +╭─ Arguments ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ * pdf FILE [default: None] [required] │ +│ * output PATH [default: None] [required] │ +╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ +╭─ Options ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ --help Show this message and exit. │ +╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ +``` + +## Examples + +Compress the `document.pdf` and output `document_compressed.pdf` + +``` +pdfly compress document.pdf document_compressed.pdf + +``` From 40f9e60cd2ba3e3c549da2c129f4acbefd26b463 Mon Sep 17 00:00:00 2001 From: mlonghin7 Date: Sun, 6 Jul 2025 20:48:10 +0200 Subject: [PATCH 04/15] add uncompress --- docs/user/subcommand-uncompress.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 docs/user/subcommand-uncompress.md diff --git a/docs/user/subcommand-uncompress.md b/docs/user/subcommand-uncompress.md new file mode 100644 index 00000000..4958ac44 --- /dev/null +++ b/docs/user/subcommand-uncompress.md @@ -0,0 +1,26 @@ +# meta + +Module for uncompressing PDF content streams. +## Usage + +``` +$ pdfly ucompress --help + Module for uncompressing PDF content streams. + + ╭─ Arguments ───────────────────────────────────────────╮ + │ * pdf FILE [default: None] [required] │ + │ * output PATH [default: None] [required] │ + ╰───────────────────────────────────────────────────────╯ + ╭─ Options ─────────────────────────────────────────────╮ + │ --help Show this message and exit. │ + ╰───────────────────────────────────────────────────────╯ + +``` + +## Examples + +Uncompress `document_compressed.pdf` and output `document.pdf`. + +``` +pdfly uncompress document_compressed.pdf document.pdf +``` \ No newline at end of file From 0652e35042a3787cf90b9d1e490d4c691a17b336 Mon Sep 17 00:00:00 2001 From: mlonghin7 Date: Sun, 6 Jul 2025 20:48:18 +0200 Subject: [PATCH 05/15] fix compress and remove --- docs/user/subcommand-compress.md | 17 ++++++++--------- docs/user/subcommand-rm.md | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/docs/user/subcommand-compress.md b/docs/user/subcommand-compress.md index 88c38c94..24b2f135 100644 --- a/docs/user/subcommand-compress.md +++ b/docs/user/subcommand-compress.md @@ -10,18 +10,17 @@ $ pdfly compress --help Compress a PDF. -╭─ Arguments ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ -│ * pdf FILE [default: None] [required] │ -│ * output PATH [default: None] [required] │ -╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ -╭─ Options ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ -│ --help Show this message and exit. │ -╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ -``` +╭─ Arguments ───────────────────────────────────────────╮ +│ * pdf FILE [default: None] [required] │ +│ * output PATH [default: None] [required] │ +╰───────────────────────────────────────────────────────╯ +╭─ Options ─────────────────────────────────────────────╮ +│ --help Show this message and exit. │ +╰───────────────────────────────────────────────────────╯ ## Examples -Compress the `document.pdf` and output `document_compressed.pdf` +Compress the file `document.pdf` and output `document_compressed.pdf` ``` pdfly compress document.pdf document_compressed.pdf diff --git a/docs/user/subcommand-rm.md b/docs/user/subcommand-rm.md index f9439ef0..df443d8f 100644 --- a/docs/user/subcommand-rm.md +++ b/docs/user/subcommand-rm.md @@ -58,14 +58,14 @@ Usage: pdfly rm [OPTIONS] FILENAME FN_PGRGS... ## Examples -Remove the 5th page of the pdf, modifying the original file +Remove the 5th page of `document.pdf`, modifying the original file. ``` pdfly rm document.pdf 4 ``` -Remove the first and last page of document.pdf, producing output.pdf +Remove the first and last page of `document.pdf`, producing `output.pdf`. ``` pdfly rm -o output.pdf document.pdf 1:-1 From 7680fd308a14a8947b618354f1b1fdda97780b6e Mon Sep 17 00:00:00 2001 From: mlonghin7 Date: Sun, 6 Jul 2025 20:49:40 +0200 Subject: [PATCH 06/15] fix compress --- docs/user/subcommand-compress.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/user/subcommand-compress.md b/docs/user/subcommand-compress.md index 24b2f135..77bc6f07 100644 --- a/docs/user/subcommand-compress.md +++ b/docs/user/subcommand-compress.md @@ -17,6 +17,7 @@ $ pdfly compress --help ╭─ Options ─────────────────────────────────────────────╮ │ --help Show this message and exit. │ ╰───────────────────────────────────────────────────────╯ +``` ## Examples From 3f7eb2a147889ac249d1785ac2c25bfd06e73c68 Mon Sep 17 00:00:00 2001 From: mlonghin7 Date: Sun, 6 Jul 2025 20:53:42 +0200 Subject: [PATCH 07/15] add pagemeta doc --- docs/user/subcommand-pagemeta.md | 57 ++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 docs/user/subcommand-pagemeta.md diff --git a/docs/user/subcommand-pagemeta.md b/docs/user/subcommand-pagemeta.md new file mode 100644 index 00000000..cbf143ec --- /dev/null +++ b/docs/user/subcommand-pagemeta.md @@ -0,0 +1,57 @@ +# meta + +Give details about a PDF's single page. + +## Usage + +``` +$ pdfly pagemeta --help + Usage: pdfly pagemeta [OPTIONS] PDF PAGE_INDEX + + Give details about a single page. + + +╭─ Arguments ──────────────────────────────────────────────────────────────────╮ +│ * pdf FILE [default: None] [required] │ +│ * page_index INTEGER [default: None] [required] │ +╰──────────────────────────────────────────────────────────────────────────────╯ +╭─ Options ────────────────────────────────────────────────────────────────────╮ +│ --output -o [json|text] output format [default: text] │ +│ --help Show this message and exit. │ +╰──────────────────────────────────────────────────────────────────────────────╯ +``` + +## Examples + +Get the metadata of the 101st page of `document.pdf` in text format. +``` +pdfly pagemeta document.pdf 100 + /home/user/.../document.pdf, page index 100 + + ┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ + ┃ Attribute ┃ Value ┃ + ┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ + │ mediabox │ (0.0, 0.0, 504.0, 661.5): with=504.0 x height=661.5 │ + │ cropbox │ (0.0, 0.0, 504.0, 661.5): with=504.0 x height=661.5 │ + │ artbox │ (0.0, 0.0, 504.0, 661.5): with=504.0 x height=661.5 │ + │ bleedbox │ (0.0, 0.0, 504.0, 661.5): with=504.0 x height=661.5 │ + │ annotations │ 8 │ + └─────────────┴─────────────────────────────────────────────────────┘ + All annotations: + 1. /Link at [232.05524, 385.79007, 343.6091, 396.29007] + 2. /Link at [157.63988, 209.99002, 243.69913, 220.49002] + 3. /Link at [72, 178.19678, 249.65918, 188.69678] + 4. /Link at [196.12769, 152.40353, 361.02328, 162.90353] + 5. /Link at [360.97717, 139.80353, 432, 150.30353] + 6. /Link at [72, 127.20352, 213.9915, 137.70352] + 7. /Link at [179.64218, 448.3905, 220.08231, 458.8905] + 8. /Link at [282.84, 347.99005, 340.83148, 358.49005] +``` + +Get the same metadata in `json` format. + +``` +pdfly pagemeta document.pdf 100 -o json + + {"mediabox":[0.0,0.0,504.0,661.5],"cropbox":[0.0,0.0,504.0,661.5],"artbox":[0.0,0.0,504.0,661.5],"bleedbox":[0.0,0.0,504.0,661.5],"annotations":19} +``` \ No newline at end of file From 5a721778f353b014214860c1ec1c82ebd9c3a699 Mon Sep 17 00:00:00 2001 From: mlonghin7 Date: Sun, 6 Jul 2025 21:01:23 +0200 Subject: [PATCH 08/15] add extract-text docs --- docs/user/subcommand-extract-text.md | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 docs/user/subcommand-extract-text.md diff --git a/docs/user/subcommand-extract-text.md b/docs/user/subcommand-extract-text.md new file mode 100644 index 00000000..9bb58fac --- /dev/null +++ b/docs/user/subcommand-extract-text.md @@ -0,0 +1,31 @@ +# meta + +Extract text from a PDF file. +## Usage + +``` +$ pdfly extract-text --help + Usage: pdfly extract-text [OPTIONS] PDF + + Extract text from a PDF file. + + +╭─ Arguments ──────────────────────────────────────────────────────────────────╮ +│ * pdf FILE [default: None] [required] │ +╰──────────────────────────────────────────────────────────────────────────────╯ +╭─ Options ────────────────────────────────────────────────────────────────────╮ +│ --help Show this message and exit. │ +╰──────────────────────────────────────────────────────────────────────────────╯ + +``` + +## Examples + +Extract the 10th page of `document.pdf` and extract the text inside of it, redirecting the output text into `page.txt`. + +``` +pdfly cat document.pdf 9 -o page.pdf + +pdfly extract-text page.pdf + +``` From cad5835ac143ef0d934574450df2938b79b5fabe Mon Sep 17 00:00:00 2001 From: mlonghin7 Date: Sun, 6 Jul 2025 21:03:16 +0200 Subject: [PATCH 09/15] add extract-images docs --- docs/user/subcommand-extract-images.md | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 docs/user/subcommand-extract-images.md diff --git a/docs/user/subcommand-extract-images.md b/docs/user/subcommand-extract-images.md new file mode 100644 index 00000000..5c440e99 --- /dev/null +++ b/docs/user/subcommand-extract-images.md @@ -0,0 +1,36 @@ +# meta + +Extract text from a PDF file. +## Usage + +``` +$ pdfly extract-images --help + Usage: pdfly extract-images [OPTIONS] PDF + + Extract images from PDF without resampling or altering. + + Adapted from work by Sylvain Pelissier + http://stackoverflow.com/questions/2693820/extract-images-from-pdf-without-res + ampling-in-python + +╭─ Arguments ──────────────────────────────────────────────────────────────────╮ +│ * pdf FILE [default: None] [required] │ +╰──────────────────────────────────────────────────────────────────────────────╯ +╭─ Options ────────────────────────────────────────────────────────────────────╮ +│ --help Show this message and exit. │ +╰──────────────────────────────────────────────────────────────────────────────╯ + +``` + +## Examples + +Extract the first page of `document.pdf` and extract the images present in it. + +``` +pdfly cat document.pdf 9 -o page.pdf + +pdfly extract-text page.pdf + Extracted 1 images: + - 0-Im0.png + +``` \ No newline at end of file From 747cd644a26dedd1739af7bd7a3ed251ddcf5ef7 Mon Sep 17 00:00:00 2001 From: mlonghin7 Date: Sun, 6 Jul 2025 21:09:02 +0200 Subject: [PATCH 10/15] add booklet docs --- docs/user/subcommand-booklet.md | 44 +++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 docs/user/subcommand-booklet.md diff --git a/docs/user/subcommand-booklet.md b/docs/user/subcommand-booklet.md new file mode 100644 index 00000000..8f82e8a9 --- /dev/null +++ b/docs/user/subcommand-booklet.md @@ -0,0 +1,44 @@ +# meta + +Reorder and two-up PDF pages for booklet printing. + +## Usage + +``` +$ pdfly booklet --help + Usage: pdfly booklet [OPTIONS] FILENAME OUTPUT + + Reorder and two-up PDF pages for booklet printing. + + If the number of pages is not a multiple of four, pages are + added until it is a multiple of four. This includes a centerfold + in the middle of the booklet and a single page on the inside + back cover. The content of those pages are from the + centerfold-file and blank-page-file files, if specified, otherwise + they are blank pages. + + Example: + pdfly booklet input.pdf output.pdf + +╭─ Arguments ──────────────────────────────────────────────────────────────────╮ +│ * filename FILE [default: None] [required] │ +│ * output FILE [default: None] [required] │ +╰──────────────────────────────────────────────────────────────────────────────╯ +╭─ Options ────────────────────────────────────────────────────────────────────╮ +│ --blank-page-file -b FILE page added if input is odd number of pages │ +│ [default: None] │ +│ --centerfold-file -c FILE double-page added if input is missing >= 2 │ +│ pages │ +│ [default: None] │ +│ --help Show this message and exit. │ +╰──────────────────────────────────────────────────────────────────────────────╯ + +``` + +## Examples + +Organize `document.pdf` into the booklet `booklet.pdf`. +``` +pdfly booklet document.pdf booklet.pdf + +``` From aed2aee893d432b800da3128b1331409128082da Mon Sep 17 00:00:00 2001 From: mlonghin7 Date: Sun, 6 Jul 2025 21:10:31 +0200 Subject: [PATCH 11/15] fix titles --- docs/user/subcommand-booklet.md | 2 +- docs/user/subcommand-compress.md | 2 +- docs/user/subcommand-extract-images.md | 2 +- docs/user/subcommand-extract-text.md | 2 +- docs/user/subcommand-pagemeta.md | 2 +- docs/user/subcommand-rm.md | 2 +- docs/user/subcommand-uncompress.md | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/user/subcommand-booklet.md b/docs/user/subcommand-booklet.md index 8f82e8a9..2a5c2f6b 100644 --- a/docs/user/subcommand-booklet.md +++ b/docs/user/subcommand-booklet.md @@ -1,4 +1,4 @@ -# meta +# booklet Reorder and two-up PDF pages for booklet printing. diff --git a/docs/user/subcommand-compress.md b/docs/user/subcommand-compress.md index 77bc6f07..196098c9 100644 --- a/docs/user/subcommand-compress.md +++ b/docs/user/subcommand-compress.md @@ -1,4 +1,4 @@ -# meta +# compress Compress a PDF. diff --git a/docs/user/subcommand-extract-images.md b/docs/user/subcommand-extract-images.md index 5c440e99..162965bb 100644 --- a/docs/user/subcommand-extract-images.md +++ b/docs/user/subcommand-extract-images.md @@ -1,4 +1,4 @@ -# meta +# extract-images Extract text from a PDF file. ## Usage diff --git a/docs/user/subcommand-extract-text.md b/docs/user/subcommand-extract-text.md index 9bb58fac..8961aeac 100644 --- a/docs/user/subcommand-extract-text.md +++ b/docs/user/subcommand-extract-text.md @@ -1,4 +1,4 @@ -# meta +# extract-text Extract text from a PDF file. ## Usage diff --git a/docs/user/subcommand-pagemeta.md b/docs/user/subcommand-pagemeta.md index cbf143ec..5b34e916 100644 --- a/docs/user/subcommand-pagemeta.md +++ b/docs/user/subcommand-pagemeta.md @@ -1,4 +1,4 @@ -# meta +# pagemeta Give details about a PDF's single page. diff --git a/docs/user/subcommand-rm.md b/docs/user/subcommand-rm.md index df443d8f..0a604d29 100644 --- a/docs/user/subcommand-rm.md +++ b/docs/user/subcommand-rm.md @@ -1,4 +1,4 @@ -# meta +# rm Remove pages from PDF files. diff --git a/docs/user/subcommand-uncompress.md b/docs/user/subcommand-uncompress.md index 4958ac44..60d8735a 100644 --- a/docs/user/subcommand-uncompress.md +++ b/docs/user/subcommand-uncompress.md @@ -1,4 +1,4 @@ -# meta +# uncompress Module for uncompressing PDF content streams. ## Usage From 6a14d5a01e986f27886ed3307fe24519ca8e99ab Mon Sep 17 00:00:00 2001 From: mlonghin7 Date: Sun, 6 Jul 2025 21:14:31 +0200 Subject: [PATCH 12/15] add 2-up docs, fix wording booklet --- docs/user/subcommand-2-up.md | 32 ++++++++++++++++++++++++++++++++ docs/user/subcommand-booklet.md | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 docs/user/subcommand-2-up.md diff --git a/docs/user/subcommand-2-up.md b/docs/user/subcommand-2-up.md new file mode 100644 index 00000000..2f5d33e4 --- /dev/null +++ b/docs/user/subcommand-2-up.md @@ -0,0 +1,32 @@ +# 2-up + +Create a booklet-style PDF from a single input. + +## Usage + +``` +$ pdfly 2-up --help + Usage: pdfly 2-up [OPTIONS] PDF OUT + + Create a booklet-style PDF from a single input. + + Pairs of two pages will be put on one page (left and right) + + usage: python 2-up.py input_file output_file + +╭─ Arguments ──────────────────────────────────────────────────────────────────╮ +│ * pdf FILE [default: None] [required] │ +│ * out PATH [default: None] [required] │ +╰──────────────────────────────────────────────────────────────────────────────╯ +╭─ Options ────────────────────────────────────────────────────────────────────╮ +│ --help Show this message and exit. │ +╰──────────────────────────────────────────────────────────────────────────────╯ +``` + +## Examples + +Convert `document.pdf` into the booklet `booklet.pdf`. +``` +pdfly 2-up document.pdf booklet.pdf + +``` diff --git a/docs/user/subcommand-booklet.md b/docs/user/subcommand-booklet.md index 2a5c2f6b..f1116157 100644 --- a/docs/user/subcommand-booklet.md +++ b/docs/user/subcommand-booklet.md @@ -37,7 +37,7 @@ $ pdfly booklet --help ## Examples -Organize `document.pdf` into the booklet `booklet.pdf`. +Convert `document.pdf` into the booklet `booklet.pdf`. ``` pdfly booklet document.pdf booklet.pdf From 09573436910a6d1df0ae83eb56ee062ea2851a68 Mon Sep 17 00:00:00 2001 From: mlonghin7 Date: Sun, 6 Jul 2025 21:17:02 +0200 Subject: [PATCH 13/15] add update-offsets docs --- docs/user/subcommand-update-offsets.md | 56 ++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 docs/user/subcommand-update-offsets.md diff --git a/docs/user/subcommand-update-offsets.md b/docs/user/subcommand-update-offsets.md new file mode 100644 index 00000000..2b7237b5 --- /dev/null +++ b/docs/user/subcommand-update-offsets.md @@ -0,0 +1,56 @@ +# update-offsets + +Updates offsets and lengths in a simple PDF file. + +## Usage + +``` +$ pdfly update-offsets --help + Usage: pdfly update-offsets [OPTIONS] FILE_IN FILE_OUT + + Updates offsets and lengths in a simple PDF file. + + The PDF specification requires that the xref section at the end + of a PDF file has the correct offsets of the PDF's objects. + It further requires that the dictionary of a stream object + contains a /Length-entry giving the length of the encoded stream. + + When editing a PDF file using a text-editor (e.g. vim) it is + elaborate to compute or adjust these offsets and lengths. + + This command tries to compute /Length-entries of the stream dictionaries + and the offsets in the xref-section automatically. + + It expects that the PDF file has ASCII encoding only. It may + use ISO-8859-1 or UTF-8 in its comments. + The current implementation incorrectly replaces CR (0x0d) by LF (0x0a) in + binary data. + It expects that there is one xref-section only. + It expects that the /Length-entries have default values containing + enough digits, e.g. /Length 000 when the stream consists of 576 bytes. + + Example: + update-offsets --verbose --encoding ISO-8859-1 issue-297.pdf + issue-297.out.pdf + +╭─ Arguments ──────────────────────────────────────────────────────────────────╮ +│ * file_in FILE [default: None] [required] │ +│ * file_out PATH [default: None] [required] │ +╰──────────────────────────────────────────────────────────────────────────────╯ +╭─ Options ────────────────────────────────────────────────────────────────────╮ +│ --encoding TEXT Encoding used to read and write the │ +│ files, e.g. UTF-8. │ +│ [default: ISO-8859-1] │ +│ --verbose --no-verbose Show progress while processing. │ +│ [default: no-verbose] │ +│ --help Show this message and exit. │ +╰──────────────────────────────────────────────────────────────────────────────╯ + +``` + +## Examples + +Update the offsets of `document.pdf` with UTF-8 encoding and write the output to `document.out.pdf`. +``` +pdfly update-offsets document.pdf --verbose --encoding UTF-8 document.out.pdf +``` \ No newline at end of file From 42628e06e85c1d1e9d4baa2685d2548bb09f0a70 Mon Sep 17 00:00:00 2001 From: mlonghin7 Date: Sun, 6 Jul 2025 21:30:34 +0200 Subject: [PATCH 14/15] fix docs --- docs/user/subcommand-2-up.md | 2 +- docs/user/subcommand-booklet.md | 2 +- docs/user/subcommand-compress.md | 7 ++- docs/user/subcommand-extract-images.md | 16 +++--- docs/user/subcommand-extract-text.md | 12 ++--- docs/user/subcommand-pagemeta.md | 12 ++--- docs/user/subcommand-rm.md | 72 +++++++++++++------------- docs/user/subcommand-uncompress.md | 5 +- 8 files changed, 63 insertions(+), 65 deletions(-) diff --git a/docs/user/subcommand-2-up.md b/docs/user/subcommand-2-up.md index 2f5d33e4..11bab2c1 100644 --- a/docs/user/subcommand-2-up.md +++ b/docs/user/subcommand-2-up.md @@ -25,7 +25,7 @@ $ pdfly 2-up --help ## Examples -Convert `document.pdf` into the booklet `booklet.pdf`. +Convert `document.pdf` into a booklet and write the output in `booklet.pdf`. ``` pdfly 2-up document.pdf booklet.pdf diff --git a/docs/user/subcommand-booklet.md b/docs/user/subcommand-booklet.md index f1116157..7147401d 100644 --- a/docs/user/subcommand-booklet.md +++ b/docs/user/subcommand-booklet.md @@ -37,7 +37,7 @@ $ pdfly booklet --help ## Examples -Convert `document.pdf` into the booklet `booklet.pdf`. +Convert `document.pdf` into a booklet and write the output in `booklet.pdf`. ``` pdfly booklet document.pdf booklet.pdf diff --git a/docs/user/subcommand-compress.md b/docs/user/subcommand-compress.md index 196098c9..ba2c181b 100644 --- a/docs/user/subcommand-compress.md +++ b/docs/user/subcommand-compress.md @@ -5,9 +5,9 @@ Compress a PDF. ## Usage ``` -$ pdfly compress --help - Usage: pdfly compress [OPTIONS] PDF OUTPUT - +$ pdfly compress --help + Usage: pdfly compress [OPTIONS] PDF OUTPUT + Compress a PDF. ╭─ Arguments ───────────────────────────────────────────╮ @@ -18,7 +18,6 @@ $ pdfly compress --help │ --help Show this message and exit. │ ╰───────────────────────────────────────────────────────╯ ``` - ## Examples Compress the file `document.pdf` and output `document_compressed.pdf` diff --git a/docs/user/subcommand-extract-images.md b/docs/user/subcommand-extract-images.md index 162965bb..1095b58e 100644 --- a/docs/user/subcommand-extract-images.md +++ b/docs/user/subcommand-extract-images.md @@ -4,15 +4,15 @@ Extract text from a PDF file. ## Usage ``` -$ pdfly extract-images --help - Usage: pdfly extract-images [OPTIONS] PDF - - Extract images from PDF without resampling or altering. - - Adapted from work by Sylvain Pelissier +$ pdfly extract-images --help + Usage: pdfly extract-images [OPTIONS] PDF + + Extract images from PDF without resampling or altering. + + Adapted from work by Sylvain Pelissier http://stackoverflow.com/questions/2693820/extract-images-from-pdf-without-res - ampling-in-python - + ampling-in-python + ╭─ Arguments ──────────────────────────────────────────────────────────────────╮ │ * pdf FILE [default: None] [required] │ ╰──────────────────────────────────────────────────────────────────────────────╯ diff --git a/docs/user/subcommand-extract-text.md b/docs/user/subcommand-extract-text.md index 8961aeac..e39c3766 100644 --- a/docs/user/subcommand-extract-text.md +++ b/docs/user/subcommand-extract-text.md @@ -4,11 +4,11 @@ Extract text from a PDF file. ## Usage ``` -$ pdfly extract-text --help - Usage: pdfly extract-text [OPTIONS] PDF - - Extract text from a PDF file. - +$ pdfly extract-text --help + Usage: pdfly extract-text [OPTIONS] PDF + + Extract text from a PDF file. + ╭─ Arguments ──────────────────────────────────────────────────────────────────╮ │ * pdf FILE [default: None] [required] │ @@ -21,7 +21,7 @@ $ pdfly extract-text --help ## Examples -Extract the 10th page of `document.pdf` and extract the text inside of it, redirecting the output text into `page.txt`. +Extract the text from the 10th page of `document.pdf`, redirecting the output into `page.txt`. ``` pdfly cat document.pdf 9 -o page.pdf diff --git a/docs/user/subcommand-pagemeta.md b/docs/user/subcommand-pagemeta.md index 5b34e916..d8f11690 100644 --- a/docs/user/subcommand-pagemeta.md +++ b/docs/user/subcommand-pagemeta.md @@ -5,12 +5,12 @@ Give details about a PDF's single page. ## Usage ``` -$ pdfly pagemeta --help - Usage: pdfly pagemeta [OPTIONS] PDF PAGE_INDEX - - Give details about a single page. - - +$ pdfly pagemeta --help + Usage: pdfly pagemeta [OPTIONS] PDF PAGE_INDEX + + Give details about a single page. + + ╭─ Arguments ──────────────────────────────────────────────────────────────────╮ │ * pdf FILE [default: None] [required] │ │ * page_index INTEGER [default: None] [required] │ diff --git a/docs/user/subcommand-rm.md b/docs/user/subcommand-rm.md index 0a604d29..ee36d4ce 100644 --- a/docs/user/subcommand-rm.md +++ b/docs/user/subcommand-rm.md @@ -6,44 +6,44 @@ Remove pages from PDF files. ``` $ pdfly rm --help -Usage: pdfly rm [OPTIONS] FILENAME FN_PGRGS... - - Remove pages from PDF files. - +Usage: pdfly rm [OPTIONS] FILENAME FN_PGRGS... + + Remove pages from PDF files. + 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. - - Page range expression examples: - - : all pages. -1 last page. - 22 just the 23rd page. :-1 all but the last page. - 0:3 the first three pages. -2 second-to-last page. - :3 the first three pages. -2: last two pages. - 5: from the sixth page onward. -3:-1 third & second to last. - - The third, "stride" or "step" number is also recognized. - - ::2 0 2 4 ... to the end. 3:0:-1 3 2 1 but not 0. - 1:10:2 1 3 5 7 9 2::-1 2 1 0. - ::-1 all pages in reverse order. - - Examples - pdfly rm -o output.pdf document.pdf 2:5 - - Remove pages 2 to 4 from document.pdf, producing output.pdf. - - pdfly rm document.pdf :-1 - - Removes all pages except the last one from document.pdf, modifying the original file. - - pdfly rm report.pdf :6 7: + A file not followed by a page range means all the pages of the file. + + PAGE RANGES are like Python slices. - Remove all pages except page seven from report.pdf, - producing a single-page report.pdf. + Remember, page indices start with zero. + + Page range expression examples: + + : all pages. -1 last page. + 22 just the 23rd page. :-1 all but the last page. + 0:3 the first three pages. -2 second-to-last page. + :3 the first three pages. -2: last two pages. + 5: from the sixth page onward. -3:-1 third & second to last. + + The third, "stride" or "step" number is also recognized. + + ::2 0 2 4 ... to the end. 3:0:-1 3 2 1 but not 0. + 1:10:2 1 3 5 7 9 2::-1 2 1 0. + ::-1 all pages in reverse order. + + Examples + pdfly rm -o output.pdf document.pdf 2:5 + + Remove pages 2 to 4 from document.pdf, producing output.pdf. + + pdfly rm document.pdf :-1 + + Removes all pages except the last one from document.pdf, modifying the original file. + + pdfly rm report.pdf :6 7: + + Remove all pages except page seven from report.pdf, + producing a single-page report.pdf. ╭─ Arguments ─────────────────────────────────────────────────────────────────────────────────────────────╮ │ * filename FILE [default: None] [required] │ diff --git a/docs/user/subcommand-uncompress.md b/docs/user/subcommand-uncompress.md index 60d8735a..5acca177 100644 --- a/docs/user/subcommand-uncompress.md +++ b/docs/user/subcommand-uncompress.md @@ -5,8 +5,8 @@ Module for uncompressing PDF content streams. ``` $ pdfly ucompress --help - Module for uncompressing PDF content streams. - + Module for uncompressing PDF content streams. + ╭─ Arguments ───────────────────────────────────────────╮ │ * pdf FILE [default: None] [required] │ │ * output PATH [default: None] [required] │ @@ -14,7 +14,6 @@ $ pdfly ucompress --help ╭─ Options ─────────────────────────────────────────────╮ │ --help Show this message and exit. │ ╰───────────────────────────────────────────────────────╯ - ``` ## Examples From 1c229546f87d014855e9a056c3b3ca176f205696 Mon Sep 17 00:00:00 2001 From: mlonghin7 Date: Sun, 6 Jul 2025 21:51:37 +0200 Subject: [PATCH 15/15] add pages to index --- docs/index.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/index.rst b/docs/index.rst index 3646bcbf..bd5f1f50 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -16,6 +16,15 @@ pdfly is a command line tool to get information about PDF documents and to manip user/subcommand-meta user/subcommand-cat user/subcommand-x2pdf + user/subcommand-extract-images + user/subcommand-2-up + user/subcommand-booklet + user/subcommand-rm + user/subcommand-pagemeta + user/subcommand-extract-text + user/subcommand-compress + user/subcommand-uncompress + user/subcommand-update-offsets .. toctree::