Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get DPI information of PDF image Python

I have pdf file in which an image is embedded in it how i can get the DPI information of that particular image using python. i tried using "pdfimages" popler-util it gives me the height and width in pixels.

But how i can get the DPI of image from that.

like image 346
Gaurav Tanwar Avatar asked Oct 16 '25 09:10

Gaurav Tanwar


1 Answers

Like the PostScript format or the EPS format, a PDF file has no resolution because it is a vectorial format. All you can do is retrieving the image dimensions in pt (or pixels):

from PyPDF2 import PdfReader
import io


with (io.open(path, mode="rb") as f):
    input_pdf = PdfReader(f)
    media_box = input_pdf.pages[0].mediabox

min_pt = media_box.lower_left
max_pt = media_box.upper_right

pdf_width = max_pt[0] - min_pt[0]
pdf_height = max_pt[1] - min_pt[1]
like image 162
Laurent LAPORTE Avatar answered Oct 19 '25 01:10

Laurent LAPORTE



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!