Skip to content

Commit

Permalink
updated split image (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
amlanc1 committed Mar 5, 2024
1 parent b01bea1 commit dc58644
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion python/prohibition_web_svc/middleware/event_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from python.prohibition_web_svc.business.cryptography_logic import encryptPdf_method1
import img2pdf
import uuid
from split_image import split_image


def validate_update(**kwargs) -> tuple:
Expand Down Expand Up @@ -267,9 +268,17 @@ def save_event_pdf(**kwargs) -> tuple:
pdf_filename = f"/tmp/{filename}.pdf"
encrypted_pdf_filename = f"/tmp/{filename}_encrypted.pdf"
b64encoded = data.get("VI_form_png").split(",")[1]
extra_page_flag=data.get('incident_details_extra_page',False)
page_num=3 if extra_page_flag else 2
with open(f"/tmp/{filename}.png", "wb") as fh:
fh.write(b64decode(b64encoded))
pdf_bytes = img2pdf.convert(f"/tmp/{filename}.png")
split_image(f"/tmp/{filename}.png", page_num, 1, False, True,output_dir="/tmp")
# pdf_bytes = img2pdf.convert(f"/tmp/{filename}.png")
pdf_bytes=None
if extra_page_flag:
pdf_bytes = img2pdf.convert(f"/tmp/{filename}_0.png", f"/tmp/{filename}_1.png", f"/tmp/{filename}_2.png")
else:
pdf_bytes = img2pdf.convert(f"/tmp/{filename}_0.png", f"/tmp/{filename}_1.png")
with open(pdf_filename, "wb") as file:
file.write(pdf_bytes)
encryptPdf_method1(
Expand Down
1 change: 1 addition & 0 deletions python/prohibition_web_svc/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ PyMuPDF==1.23.3
pyaes==1.6.1
pbkdf2==1.3
img2pdf
split-image

0 comments on commit dc58644

Please sign in to comment.