From 6ef62c97914a9c88a889875cb1af710c1da439d1 Mon Sep 17 00:00:00 2001 From: Jeremy Singer-Vine Date: Wed, 2 Oct 2024 21:11:38 -0400 Subject: [PATCH] Add `name` property to `image` objects (#1201) h/t @djr2015 --- CHANGELOG.md | 7 +++++++ README.md | 1 + pdfplumber/page.py | 1 + tests/test_convert.py | 6 +++--- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d416296..38f1b12f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/). +## [0.11.5] - 2024-10-02 + +### Added + +- Add `name` property to `image` objects (h/t @djr2015). ([#1201](https://github.com/jsvine/pdfplumber/discussions/1201)) + + ## [0.11.4] - 2024-08-18 ### Fixed diff --git a/README.md b/README.md index 1d14d27e..829d6f3d 100644 --- a/README.md +++ b/README.md @@ -274,6 +274,7 @@ Additionally, both `pdfplumber.PDF` and `pdfplumber.Page` provide access to seve |`bits`| The number of bits per color component; e.g., 8 corresponds to 255 possible values for each color component (R, G, and B in an RGB color space).| |`stream`| Pixel values of the image, as a `pdfminer.pdftypes.PDFStream` object.| |`imagemask`| A nullable boolean; if `True`, "specifies that the image data is to be used as a stencil mask for painting in the current color."| +|`name`| "The name by which this image XObject is referenced in the XObject subdictionary of the current resource dictionary." [🔗](https://ghostscript.com/~robin/pdf_reference17.pdf#page=340) | |`mcid`| The [marked content](https://ghostscript.com/~robin/pdf_reference17.pdf#page=850) section ID for this image if any (otherwise `None`). *Experimental attribute.*| |`tag`| The [marked content](https://ghostscript.com/~robin/pdf_reference17.pdf#page=850) section tag for this image if any (otherwise `None`). *Experimental attribute.*| |`object_type`| "image"| diff --git a/pdfplumber/page.py b/pdfplumber/page.py index 096ee1ba..0dd51d9c 100644 --- a/pdfplumber/page.py +++ b/pdfplumber/page.py @@ -64,6 +64,7 @@ "stroke", "stroking_color", "stream", + "name", "mcid", "tag", ] diff --git a/tests/test_convert.py b/tests/test_convert.py index 78731bff..2508b7ed 100644 --- a/tests/test_convert.py +++ b/tests/test_convert.py @@ -178,7 +178,7 @@ def test_csv(self): assert c.split("\r\n")[9] == ( "char,1,45.83,58.826,656.82,674.82,117.18,117.18,135.18,12.996," '18.0,12.996,,,,,,,TimesNewRomanPSMT,,,"(1, 0, 0, 1, 45.83, 660.69)"' - ',,DeviceRGB,"(0, 0, 0)",,,,18.0,,,,,,,Y,,1,' + ',,,DeviceRGB,"(0, 0, 0)",,,,18.0,,,,,,,Y,,1,' ) io = StringIO() @@ -245,7 +245,7 @@ def test_cli_csv(self): assert res.decode("utf-8").split("\r\n")[9] == ( "char,1,45.83,58.826,656.82,674.82,117.18,117.18,135.18,12.996," '18.0,12.996,,,,,,,TimesNewRomanPSMT,,,"(1, 0, 0, 1, 45.83, 660.69)"' - ',,DeviceRGB,"(0, 0, 0)",,,,18.0,,,,,,,Y,,1,' + ',,,DeviceRGB,"(0, 0, 0)",,,,18.0,,,,,,,Y,,1,' ) def test_cli_csv_exclude(self): @@ -271,7 +271,7 @@ def test_cli_csv_exclude(self): assert res.decode("utf-8").split("\r\n")[9] == ( "char,1,45.83,58.826,656.82,674.82,117.18,117.18,135.18,12.996," "18.0,12.996,,,,,,,TimesNewRomanPSMT," - ',,"(0, 0, 0)",,,18.0,,,,,,Y,,1,' + ',,,"(0, 0, 0)",,,18.0,,,,,,Y,,1,' ) def test_cli_csv_include(self):