I am trying to take images and convert them to PDFs, however, when an image has a rotation value in its exif data, then my pdf also has a rotation value on the converted pdf.
Instead of having the rotation value on the pdf page, i want the image to be rotated as it is meant to be viewed based on the image’s exif, and not have any rotation value on the pdf page.
How do i accomplish this ?
I’m hoping to be able to do this only using img2pdf.
I am using this command:
pdf_bytes = img2pdf.convert(io.BytesIO(response.content), rotation=img2pdf.Rotation.ifvalid, first_frame_only=True)
And the input file is :
https://drive.google.com/file/d/1JyCBl5ulQmKIdQnVsvbNo7oNHX7oGIda/view?usp=sharing
The input file has a 90CW rotation as per exif data.
However, whether i generate the pdf using rotation=img2pdf.Rotation.ifvalid or not, the generated pdf is the same. Why does it not make any difference ?
My goal is for the image to be rotated as per exif and the pdf to not have any rotation value on the pdf page.
I am checking the page rotation of the output using this code:
from pypdf import PdfReader
with open('abc.pdf', 'rb') as input_pdf:
reader = PdfReader(input_pdf)
# Iterate through each page and get the rotation value
for page_num, page in enumerate(reader.pages):
# Get the rotation value of the page
rotation_value = page.get('/Rotate') or 0 # Default to 0 if not rotated
print(f"Page {page_num + 1} is rotated by {rotation_value} degrees.")
Output:
Page 1 is rotated by 90 degrees.
You need to sign in to view this answers