【问题标题】:Get DPI information of PDF image Python获取PDF图像Python的DPI信息
【发布时间】:2018-06-13 10:27:01
【问题描述】:

我有一个 pdf 文件,其中嵌入了一个图像,我如何使用 python 获取该特定图像的 DPI 信息。 我尝试使用“pdfimages”popler-util 它给了我以像素为单位的高度和宽度。

但是我如何从中获得图像的 DPI。

【问题讨论】:

    标签: python resolution dpi


    【解决方案1】:

    与 PostScript 格式或 EPS 格式一样,PDF 文件没有分辨率,因为它是矢量格式。您所能做的就是以 pt(或像素)为单位检索图像尺寸:

    from PyPDF2 import PdfFileReader
    
    
    with io.open(path, mode="rb") as f:
        input_pdf = PdfFileReader(f)
        media_box = input_pdf.getPage(0).mediaBox
    
    min_pt = media_box.lowerLeft
    max_pt = media_box.upperRight
    
    pdf_width = max_pt[0] - min_pt[0]
    pdf_height = max_pt[1] - min_pt[1]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-31
      • 2018-09-17
      相关资源
      最近更新 更多