create the api for the display list
This commit is contained in:
@@ -835,3 +835,39 @@ def replace_text_object(document_id: str, page_index: int, object_index: int, re
|
||||
os.remove(tmp_path)
|
||||
if os.path.exists(out_path):
|
||||
os.remove(out_path)
|
||||
|
||||
@router.get("/{document_id}/pages/{page_index}/display_list")
|
||||
def get_display_list(document_id: str, page_index: int):
|
||||
if not engine.is_available():
|
||||
raise HTTPException(status_code=501, detail="Engine not available")
|
||||
|
||||
doc_info = document_store.get_document(document_id)
|
||||
if not doc_info:
|
||||
raise HTTPException(status_code=404, detail="Document not found")
|
||||
|
||||
try:
|
||||
doc = doc_info["doc_instance"]
|
||||
page = doc.get_page(page_index)
|
||||
json_str = page.extract_display_list()
|
||||
return Response(content=json_str, media_type="application/json")
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
@router.get("/{document_id}/pages/{page_index}/xobjects/{name}")
|
||||
def get_image_xobject(document_id: str, page_index: int, name: str):
|
||||
if not engine.is_available():
|
||||
raise HTTPException(status_code=501, detail="Engine not available")
|
||||
|
||||
doc_info = document_store.get_document(document_id)
|
||||
if not doc_info:
|
||||
raise HTTPException(status_code=404, detail="Document not found")
|
||||
|
||||
try:
|
||||
doc = doc_info["doc_instance"]
|
||||
page = doc.get_page(page_index)
|
||||
img_bytes = page.extract_image_xobject(name)
|
||||
if not img_bytes:
|
||||
raise HTTPException(status_code=404, detail="Image not found")
|
||||
return Response(content=img_bytes, media_type="image/png")
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
Reference in New Issue
Block a user