0

I don't seem to be able to figure out why pymupdf tools for placing objects on pdf documents has the origin set at a seemingly random location. Notice that (0,0,100,100), which is x0 y1 x2 y2 (where y starts from top) starts from the middle of the page for the y axis. x axis appears fine. I cannot seem to find anything in the documentation about this.

import fitz
doc = fitz.open('PDF4.pdf')
page = doc.load_page(0)
box = page.new_shape()
box.draw_rect(fitz.Rect(0, 0, 100, 100)) # x0, y0-2505, x2, y2
box.finish(color=(0, 0, 0), fill=(0, 0, 1),fill_opacity = 0.25)
box.commit()
doc.save("x.pdf")

Notice box is on the top left

negfrequency
  • 1,801
  • 3
  • 18
  • 30

1 Answers1

0

This appears to solve this and reset the origin. This seems to have changed to snake casing from camel casing recently, making current solutions to this online fail.

if not page.is_wrapped:
    page.wrap_contents() 
negfrequency
  • 1,801
  • 3
  • 18
  • 30