import pdfplumber import os import time import subprocess def draw_boxes(page, boxes): im = debug_im(page) for box in boxes: im.draw_line(((box["x0"], page.height - box["y0"]), (box["x1"], page.height - box["y0"]))) im.draw_line(((box["x1"], page.height - box["y0"]), (box["x1"], page.height - box["y1"]))) im.draw_line(((box["x1"], page.height - box["y1"]), (box["x0"], page.height - box["y1"]))) im.draw_line(((box["x0"], page.height - box["y1"]), (box["x0"], page.height - box["y0"]))) if "debug_label" in box: im.draw.text( xy=(box["x0"], page.height-box["y0"]), text=str(box["debug_label"]), ) debug_show(im) def debug_im(page): return page.to_image(height=800) def debug_show(im, name=None): im.show() #im.save(f"/tmp/dnd-pdf-to-txt{'' if not name else '-'+name}.jpg") #if not DEBUG_NO_SHOW: # go(f"qlmanage -p /tmp/dnd-pdf-to-txt{'' if not name else '-'+name}.jpg &> /dev/null")