Ignore path constructors that do not begin with m #749
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have encountered a couple of PDFs (see jsvine/pdfplumber#636 (comment) and jsvine/pdfplumber#644 (comment)) that include a
("h", )
path — i.e., just theh
operator and no others. This causes this second statement here to throwValueError: not enough values to unpack (expected 2, got 1)
:pdfminer.six/pdfminer/converter.py
Lines 126 to 129 in 1bf3c42
Pull request
Although there may be narrower solutions to this particular problem (e.g., handling the specific edge-case of
("h",)
), this PR introduces what — at least to me — seems like the most generalized-yet-accurate solution, after reading the PDF Reference.Per Section 4.4.1, "path construction operators may be invoked in any sequence, but the first one invoked must be
m
orre
to begin a new subpath." Since pdfminer.six already converts allre
(rectangle) operators to their equivelentmlllh
representation, paths ingested by.paint_path(...)
that do not begin with them
operator are invalid.I am, however, open to other approaches 👍
How Has This Been Tested?
I have added a test to
tests/test_converter.py
. I have also examined all non-encrypted PDFs in thesamples/
directory. Of the 31,116 paths and subpaths in those 33 PDFs, all start with the “m” operator (or have been translated from the “re” operator to take that form).Checklist
works
version
is not necessary
verified that this is not necessary
CHANGELOG.md