diff --git a/rmrl/render.py b/rmrl/render.py index 475b1da..6b18c6f 100644 --- a/rmrl/render.py +++ b/rmrl/render.py @@ -439,9 +439,17 @@ def merge_pages(basepage, rmpage, changed_page, expand_pages): # MediaBox, so one must be taken from the parent. The # rM adds a bit to the width AND the height on this # file. - bpage_box = list(map(float, basepage.CropBox - or basepage.MediaBox - or basepage.Parent.MediaBox)) + # Sometimes the direct parent does not have a MediaBox. + # In this situation, look one extra level above. + box_data = basepage.CropBox or basepage.MediaBox or basepage.Parent.MediaBox + if not box_data and hasattr(basepage.Parent,'Parent'): + box_data = basepage.Parent.Parent.MediaBox + + # If we still can't find it, raise an exception that describes the problem + if not box_data: + raise TypeError("Could not find the dimensions of the base PDF page.") + + bpage_box = list(map(float, box_data)) # Fix any malformed PDF that has a CropBox extending outside of # the MediaBox, by limiting the area to the intersection.