【发布时间】:2015-01-25 19:08:34
【问题描述】:
当我使用 pdfbox 提取图像时,某些 PDF 的图像 dpi 不正确。当我使用 Photoshop 或 Acrobat Reader Pro 提取图像时,我可以使用 windows 照片查看器看到图像的 dpi 为 200,但是当我使用 pdfbox 提取图像时,dpi 为 72。
为了提取图像,我使用以下代码: Not able to extract images from PDFA1-a format document
当我检查日志时,我看到一个不寻常的条目: 2015-01-23-main--DEBUG-org.apache.pdfbox.util.TIFFUtil:
<?xml version="1.0" encoding="UTF-8"?><javax_imageio_jpeg_image_1.0>
<JPEGvariety>
<app0JFIF majorVersion="1" minorVersion="2" resUnits="0" Xdensity="1" Ydensity="1" thumbWidth="0" thumbHeight="0"/>
</JPEGvariety>
<markerSequence>
<dqt>
<dqtable elementPrecision="0" qtableId="0"/>
<dqtable elementPrecision="0" qtableId="1"/>
</dqt>
<dht>
<dhtable class="0" htableId="0"/>
<dhtable class="0" htableId="1"/>
<dhtable class="1" htableId="0"/>
<dhtable class="1" htableId="1"/>
</dht>
<sof process="0" samplePrecision="8" numLines="0" samplesPerLine="0" numFrameComponents="3">
<componentSpec componentId="1" HsamplingFactor="2" VsamplingFactor="2" QtableSelector="0"/>
<componentSpec componentId="2" HsamplingFactor="1" VsamplingFactor="1" QtableSelector="1"/>
<componentSpec componentId="3" HsamplingFactor="1" VsamplingFactor="1" QtableSelector="1"/>
</sof>
<sos numScanComponents="3" startSpectralSelection="0" endSpectralSelection="63" approxHigh="0" approxLow="0">
<scanComponentSpec componentSelector="1" dcHuffTable="0" acHuffTable="0"/>
<scanComponentSpec componentSelector="2" dcHuffTable="1" acHuffTable="1"/>
<scanComponentSpec componentSelector="3" dcHuffTable="1" acHuffTable="1"/>
</sos>
</markerSequence>
</javax_imageio_jpeg_image_1.0>
我试图用谷歌搜索,但我可以通过这个日志找出 pdfbox 的含义。这是什么意思?
您可以从此链接下载一个包含此问题的示例 pdf: http://myslams.com/test/1.pdf
我什至尝试过 itext,但它正在提取 96 dpi 的图像。
我做错了吗?还是pdfbox和itext有这个限制?
【问题讨论】:
-
通常 dpi 在 PDF 中的位图上下文中没有意义。
-
你是说我上面提到的示例pdf包含位图图像。
-
从 PDF 中提取图像之后期望图像具有 DPI 值是没有意义的。如果你想知道图像的 DPI当它还在 PDF 中时,你需要阅读这个问题的答案:Getting Image DPI in PDF files using iText你不应该声称 iText 和 PdfBox 给了你错误DPI。是你对 DPI 的理解是错误的。
-
另外,当您发布示例 PDF 时,请确保它没有显示:在此服务器上找不到请求的 URL /test/1.pdf。
-
@bruno 由于机密性原因,我不得不删除 pdf 文件。抱歉...明天将提供示例 PDF 文件。