Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file. The format
## [Unreleased]

### Fixed
- Skip unmatched optional capture groups in `Page.search()` when `main_group` selects them.
- Initialize PDFium's form environment in `get_page_image` so that filled AcroForm field content is included when rendering pages via `Page.to_image()`. ([#1367](https://github.com/jsvine/pdfplumber/issues/1367))
- Fix `make venv`, which created the virtual environment at `venv/` but then installed into `${VENV}` (default `.venv/`), causing the target to fail on a fresh checkout (h/t @soodoku). ([ec96f72](https://github.com/jsvine/pdfplumber/commit/ec96f72))
- Include the wrapped exception's class name in `PdfminerException`'s message when `pdfminer.six` raises an exception without one (e.g. `PDFPasswordIncorrect`), which previously surfaced as a blank error message.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ Many thanks to the following users who've contributed ideas, features, and fixes
- [Sebastian Cao](https://github.com/cycsmail)
- [Kaspar Naraghi](https://github.com/kaninaba94)
- [Siddharth Gaur](https://github.com/siddharthgaur1)
- [Jake Wang](https://github.com/jakezwang)

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion pdfplumber/utils/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def search(
gen = re.finditer(compiled, self.as_string)
# Remove zero-length matches (can happen, e.g., with optional
# patterns in regexes) and whitespace-only matches
filtered = filter(lambda m: bool(m.group(main_group).strip()), gen)
filtered = filter(lambda m: bool((m.group(main_group) or "").strip()), gen)
return [
self.match_to_dict(
m,
Expand Down
16 changes: 16 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,22 @@ def test_search_string(self):
results = page.search(r"10 Tuesday", layout=True)
assert len(results) == 0

def test_search_optional_main_group(self):
page = self.pdf_scotus.pages[0]
assert page.search(r"(sdfsd)?", main_group=1) == []

def test_search_alternative_main_group(self):
page = self.pdf_scotus.pages[0]
results = page.search(
r"Tuesday|(supreme\s+court)",
main_group=1,
case=False,
return_groups=False,
)
expected = page.search(r"supreme\s+court", case=False, return_groups=False)
assert len(expected) == 2
assert results == expected

def test_extract_text_lines(self):
page = self.pdf_scotus.pages[0]
results = page.extract_text_lines()
Expand Down