问题描述
我正在编写一个可以验证PDF文件的程序。我正在使用iText java库来获取文件的内容,但是我在解析它时遇到了一些问题。我需要获得有关每个图像的色彩空间和DPI的信息。如何获取PDF格式的图像位置和尺寸信息?我试图浏览PDF的每个XObject但我卡住了,我找不到任何有关PDF文件宽度和高度的信息。
还有其他图书馆可以帮助我吗?
感谢您提供所有答案和提示。
I am writing a program that would validate PDF file. I am using iText java library to get content of a file, but I have some problems with parsing it. I need to get info about color space and DPI of each image. How can I get info about position and dimensions of image in PDF? I tried to browse each XObject of PDF but I stuck, I cannot find any information about width and height of file in PDF.Are there any other libraries which can help me?Thank You for all answers and tips.
推荐答案
PDF文件中的图像对象仅存储宽度和图像的高度(以像素为单位)。为了了解页面上图像的位置和大小,在PDF点中,您必须执行页面内容流,以创建虚拟渲染。使用Do运算符在页面上绘制图像,其位置和大小由执行Do运算符时的当前变换矩阵给出。
特定绘图实例的DPI计算为72 * imageSizeInPixels / imageSizeInPoints,imageSizeInPoints如上所述计算。
The image object in the PDF file stores only the Width and the Height of the image in pixels. In order to know the position and size of the image on the page, in PDF points, you have to execute the page content stream, to create a virtual rendering. The image is painted on the page using the 'Do' operator and its position and size are given by the current transformation matrix that is in place when the 'Do' operator is executed.
The DPI for a specific drawing instance is computed as 72*imageSizeInPixels/imageSizeInPoints, imageSizeInPoints being computed as described above.
这篇关于浏览PDF页面内容。色彩空间和DPI问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!