从 php/linux 获取 pdf 的布局模式(横向或纵向)
给定一个 PDF,如何使用 PHP lib 或 Linux 命令行工具获取 PDF 的布局模式(或相对宽度/高度)?
使用 http://www.tecnick.com/public/code/cp_dpage .php?aiocp_dp=tcpdf 可以在新的 PDF 上设置此变量,但适用于 adobe 中的现有 pdf。
考虑将 pdf 转换为 ps,或以其他方式使用 gs - 比如首先将其转换为图像,然后获取其宽度和高度。这是最好的方法吗?
Given a PDF, how can one get the layout mode of a PDF (or relative width/height) using a PHP lib or linux command line tool?
Using http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf which can set this variable on new PDFs, but for existing pdfs from adobe.
Thought of converting pdfs to ps, or using gs in some other way - like converting it to an image first, and getting the width and height of that. Is this the best way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我使用的解决方案是使用 Ghostscript 将第一页打印到图像,然后获取图像尺寸
The solution I'm using is to use ghostscript to print the first page to an image, then getting the image dimensions
您不能总是依赖第一页的结果与其他所有页面的结果相同。我已经见过足够多的混合格式 PDF,因此不想将任何代码基于该假设。
确定每一页(甚至每个嵌入的 {Trim,Media,Crop,Bleed}Box)的介质尺寸的更可靠方法是命令行工具 pdfinfo.exe(来自 http://www.foolabs.com/xpdf/download.html)。您可以使用“-box”参数运行该工具,并使用“-f 3”告诉它从第 3 页开始处理,使用“-l 8”告诉它在第 8 页停止处理。
输出示例:
You cannot always rely on the results from the first page to be the same for all the rest. I've seen enough mixed format PDFs out there in the wild to not want to base any code on that assumption.
A more reliable way to determine the media sizes for each page (and even each one of the embedded {Trim,Media,Crop,Bleed}Boxes) is the commandline tool pdfinfo.exe (part of the XPDF tools from http://www.foolabs.com/xpdf/download.html). You can run the tool with the "-box" parameter and tell it with "-f 3" to start at page 3 and with "-l 8" to stop processing at page 8.
Example output:
大枪,但没有其他建议。我使用 iText Java 库来处理 pdf 文件。
请注意,据我所知,不存在 PDF 布局模式或大小之类的东西。 PDF 是页面的集合,每个页面都有一个媒体框,定义要打印的页面的大小。但是,如果未定义,则该属性可以由页面从以前的页面继承。有关详细信息,请参阅 PDF 参考。
Big gun, but no other suggestions. I have used the iText Java library for processing pdf files.
Note that as far as I know there is no such thing as PDF layout mode, or size. The PDF is a collection of pages each of which has a media box defining the size of the page to be printed. However this property can be inherited by a page from previous pages if not defined. See PDF reference for details.