Rescue Paperjet v1 implementation
This commit is contained in:
parent
7ff5c8130d
commit
db9e2ca51b
83 changed files with 6186 additions and 3894 deletions
|
|
@ -28,28 +28,28 @@ async def verify_coords(req: VerifyCoordsRequest):
|
|||
|
||||
try:
|
||||
doc = pymupdf.open(filepath)
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=500, detail=str(error)) from error
|
||||
|
||||
if req.page < 0 or req.page >= len(doc):
|
||||
doc.close()
|
||||
raise HTTPException(status_code=400, detail="Invalid page number")
|
||||
|
||||
page = doc[req.page]
|
||||
|
||||
|
||||
# Canonical space is defined as relative to the unrotated CropBox.
|
||||
# PyMuPDF naturally draws relative to the current rotation.
|
||||
# By temporarily setting rotation to 0, we can draw directly using canonical coordinates.
|
||||
original_rotation = page.rotation
|
||||
if original_rotation != 0:
|
||||
page.set_rotation(0)
|
||||
|
||||
|
||||
rect = pymupdf.Rect(req.x, req.y, req.x + req.width, req.y + req.height)
|
||||
page.draw_rect(rect, color=(1, 0, 0), width=2, fill=(1, 0, 0), fill_opacity=0.3)
|
||||
|
||||
|
||||
if original_rotation != 0:
|
||||
page.set_rotation(original_rotation)
|
||||
|
||||
|
||||
pdf_bytes = doc.write()
|
||||
doc.close()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue