jsvine / pdfplumber

Plumb a PDF for detailed information about each char, rectangle, line, et cetera — and easily extract text and tables.
MIT License
6.57k stars 659 forks source link

fix: calculate rotation using 0 when Rotate is None #811

Closed toshi1127 closed 1 year ago

toshi1127 commented 1 year ago

An error occurred when calculating rotation when Rotate was None. Fixed to calculate rotation using 0 when Rotate is None.

TypeError: unsupported operand type(s) for %: 'NoneType' and 'int'

self.rotation = _rotation % 360
File "/var/task/pdfplumber/page.py", line 54, in __init__
samkit-jain commented 1 year ago

Hi @toshi1127 Thanks for raising the PR. Could you please add a test case with the PDF for the issue that you are facing which fails otherwise but passes with your fix?

toshi1127 commented 1 year ago

@samkit-jain Thanks for reviewing.

Is it mandatory to add the PDF as a test case to merge this PR? We are developing SaaS, and we would like to avoid adding it as test data as much as possible, because an error occurred in a PDF uploaded by contractor.

If you insist, we will attempt to see if we can create a separate PDF to reproduce the error.

jsvine commented 1 year ago

Thank you, @toshi1127 and thank you @samkit-jain. Ideally, PRs come with proving test cases, but this change is simple/clear enough, and true to the specification*, that I think we can make an exception here. Merging.

* Per the spec (p. 146), rotation refers to "The number of degrees by which the page should be rotated clockwise when displayed or printed. The value must be a multiple of 90. Default value: 0."

jsvine commented 1 year ago

And I'm curious, @toshi1127: What's the SaaS product?

toshi1127 commented 1 year ago

@jsvine Thank you for the review ! I am using pdfplumber for the following product.

https://bakuraku.jp/denshichobo