rschroll / rmrl

Render reMarkable documents to PDF
GNU General Public License v3.0
119 stars 21 forks source link

`basepage.CropBox or basepage.MediaBox or basepage.Parent.MediaBox` returns `None` #11

Open flomlo opened 3 years ago

flomlo commented 3 years ago

Hi,

the renderer crashes when used on the supplied buggy.zip (called via python -m rmrl buggy.zip) resulting in the following error:

Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/florian/.local/lib/python3.9/site-packages/rmrl/__main__.py", line 53, in <module>
    sys.exit(main())
  File "/home/florian/.local/lib/python3.9/site-packages/rmrl/__main__.py", line 44, in main
    stream = render(source,
  File "/home/florian/.local/lib/python3.9/site-packages/rmrl/render.py", line 149, in render
    merge_pages(basepage, rmpage, i in changed_pages, expand_pages)
  File "/home/florian/.local/lib/python3.9/site-packages/rmrl/render.py", line 442, in merge_pages
    bpage_box = list(map(float, basepage.CropBox
TypeError: 'NoneType' object is not iterable

Apparently, in this particular case, neither basepage.CropBox, nor basepage.MediaBox nor basepage.parent.CropBox exist.

I'm trying to debug it myself, but am not particularly confident right now. Could you provide me some hints?

Thank you very much :)

flomlo commented 3 years ago

I'm the author of this particular .pdf, maybe I accidentally fucked up some LuaLaTex stuff and made the resulting .pdf very weird. Feel free to request modified versions if it helps with the debugging.

Oh, for most of my ~300 other files on my remarkable it runs totally fine.

flomlo commented 3 years ago

if I understand the comment above https://github.com/rschroll/rmrl/blob/89b5cc38ef45251b96bd3d1c3618429b6b46db92/rmrl/render.py#L442 correctly then we need to load CropBox if existent, otherwise MediaBox.

I would suggest the following fix:

    bpage_box = list(map(float, basepage.inheritable.CropBox
                                or basepage.inheritable.MediaBox))

This seems to work fine on my ~300 files.

I'll generate a pull request if you think this is a valid replacement.