Skip to content

Commit

Permalink
fixed bugs introduced in my last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
g-raffy committed Nov 11, 2023
1 parent e23f822 commit 071d762
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/pymusco/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def extract_pdf_page_main_image(pdf_page: PyPDF2.PageObject, image_dir: Path, im
except NotImplementedError as e:
print(f"warning : NotImplementedError({str(e)}). Maybe pypdf2 is unable to decode this stream. Falling back to a resampling method.")
image = pdf_page_to_png(pdf_page, resolution=300)
saved_image_file_path = (image_dir / image_name).with_suffix('png')
saved_image_file_path = (image_dir / image_name).with_suffix('.png')
cv2.imwrite(saved_image_file_path, image)
print(f"resampled image saved to {saved_image_file_path}")

Expand Down Expand Up @@ -211,7 +211,7 @@ def extract_pdf_page_main_image(pdf_page: PyPDF2.PageObject, image_dir: Path, im
rotate_image(saved_image_file_path, -pdf_page['/Rotate'], saved_image_file_path)
else:
# this page doesn't contain a raster image, so we keep it in its original vectorial form
saved_image_file_path = (image_dir / image_name).with_suffix('pdf')
saved_image_file_path = (image_dir / image_name).with_suffix('.pdf')
with open(saved_image_file_path, 'wb') as pdf_file:
dst_pdf = PyPDF2.PdfWriter()
dst_pdf.add_page(pdf_page)
Expand All @@ -226,7 +226,7 @@ def extract_pdf_page(pdf_page: PyPDF2.PageObject, image_dir: Path, image_name: s
:param str image_name: the name of the saved file image, without file extension
:return str: the saved image file path with file extension
"""
saved_image_file_path = (image_dir / image_name).with_suffix('pdf')
saved_image_file_path = (image_dir / image_name).with_suffix('.pdf')
with open(saved_image_file_path, 'wb') as pdf_file:
dst_pdf = PyPDF2.PdfWriter()
dst_pdf.add_page(pdf_page)
Expand Down

0 comments on commit 071d762

Please sign in to comment.