将 PDF 转换为 JPEG,不带投影/斜角
我正在为一家报纸网站开发 CMS 模块。 我让编辑们可以选择上传整份报纸的 .pdf
,然后将其转换为可翻页的数字在线报纸。
翻页技巧是用 flash 完成的,只是我在所有版本中使用的 .swf
。 我的问题是 .pdf
到 .jpg
转换。
这些 .pdf
是在 Adobe InDesign CS4 中完成的,大多数情况下包含具有投影或斜角等效果的图像。
我最初使用 .pdf
尝试了我的代码,其中仅包含文本或简单图像,并且运行良好。 当我尝试使用更复杂的 .pdf
(其中包括带有投影效果的旋转图像)时,事情变得棘手。
这是我的 Ghostscript 代码:
$result=exec("gs -sDEVICE=jpeg -sOutputFile=../ediciones/20090717/pages/page-%d.jpeg ../ediciones/20090717/20090717.pdf");
I am working on a CMS module for a newspaper site. I'm enabling the editors with the option to upload a .pdf
of the entire newspaper, which will then be converted into a page-flipping digital online newspaper.
The page-flipping trick is done with flash and is just an .swf
that I use for all the editions. My problem is with the .pdf
to .jpg
conversion.
These .pdf
s are done in Adobe InDesign CS4, and most of the times contain Images that have effects like dropshadows or bevels.
I initially tried my code out with .pdf
s that had only text or simple images in them and it worked fine. When I tried this out with more complex .pdf
s, which included rotated images with dropshadow effects, things got tricky.
Here is my ghostscript code:
$result=exec("gs -sDEVICE=jpeg -sOutputFile=../ediciones/20090717/pages/page-%d.jpeg ../ediciones/20090717/20090717.pdf");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑 gs 所做的是将 pdf 转换为支持 postscript 的相同数据模型。 Postscript 不支持透明度(Alpha 通道),因此无法以这种中间格式表示阴影。 然后,gs 渲染 jpg,显然没有透明度。
我认为您将不得不使用另一种策略将 pdf 转换为 jpg。
I have the suspect that what gs does is to convert the pdf into the same datamodel that supports postscript. Postscript does not support transparency (alpha channel), so there's no way to represent the drop shadows in this intermediate format. Then, gs renders the jpg, obviously with no trasparencies.
I think you will have to use another strategy to convert your pdfs to jpg.
问题解决了。
这与从 Adobe InDesign CS4 导出 PDF 的方式有关。
此导出的正确格式为:
其中一些配置我不知道它们是什么,但这是用于正确导出 PDF 并转换为 JPEG(dropshadow)的配置包括)。
据我了解,通过这种配置,在生成 PDF 之前会发生一个扁平化过程,从而节省了 Ghostscript 解释透明度的麻烦。
您现在可以在此处检查生成的 JPEG:
http://www.dengelz.com/clientes/北/ediciones/20090717/pages/page-1.jpg
Problem resolved.
It had to do with the way the PDFs were being exported from Adobe InDesign CS4.
The correct format for this export is:
A couple of these configurations I have no idea what they are, but this is the configuration that worked for the correct export of the PDFs, and conversion into JPEG (dropshadow included).
From what I understand, with this configuration, there is a Flattening process that happens before the PDF is generated, therefor saving Ghostscript the trouble of having to interpret transparency.
You can now check the generated JPEG here:
http://www.dengelz.com/clientes/norte/ediciones/20090717/pages/page-1.jpg