-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: convert pdf to image concurrently
- Loading branch information
1 parent
8d29ffb
commit c26232f
Showing
4 changed files
with
108 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
pkg/component/operator/document/v0/transformer/execution/get_page_numbers.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from io import BytesIO | ||
import json | ||
import sys | ||
import base64 | ||
import pdfplumber | ||
|
||
if __name__ == "__main__": | ||
try: | ||
json_str = sys.stdin.buffer.read().decode('utf-8') | ||
params = json.loads(json_str) | ||
pdf_string = params["PDF"] | ||
decoded_bytes = base64.b64decode(pdf_string) | ||
pdf_file_obj = BytesIO(decoded_bytes) | ||
|
||
pdf = pdfplumber.open(pdf_file_obj) | ||
|
||
output = { | ||
"page_numbers": len(pdf.pages) | ||
} | ||
|
||
print(json.dumps(output)) | ||
except Exception as e: | ||
print(json.dumps({"error": str(e)})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters