extract detail from pdf

This commit is contained in:
j 2024-06-09 14:47:36 +01:00
commit 5bd561e64f
3 changed files with 75 additions and 5 deletions

View file

@ -93,6 +93,24 @@ class EpubHandler(OMLHandler):
self.set_header('Content-Type', content_type)
self.write(z.read(filename))
class CropHandler(OMLHandler):
def get(self, id, page, left, top, right, bottom):
from media.pdf import crop
with db.session():
item = Item.get(id)
path = item.get_path()
print(path, page, left, top, right, bottom)
data = crop(path, page, left, top, right, bottom)
if data:
self.set_header('Content-Type', 'image/jpeg')
self.set_header('Content-Length', str(len(data)))
self.write(data)
return
self.set_status(404)
return
def serve_static(handler, path, mimetype, include_body=True, disposition=None):
handler.set_header('Content-Type', mimetype)
size = os.stat(path).st_size