如何以编程方式操作 EPS 文件
我正在寻找有助于以编程方式操作 EPS(封装 PostScript)文件的库。 基本上,我想要做的是:
- 显示/隐藏 EPS 文件中预先存在的图层(打开和关闭它们)
- 在 EPS 文件中填充(颜色)命名形状
- 检索 EPS 文件中命名点的坐标
- 在新的图层上绘制形状 服务器上EPS 文件中的图层
- ,无需用户交互(编写 Adobe Illustrator 脚本不起作用)
我知道 EPS 文件格式是如何基于 PostScript 语言的,因此必须进行解释 - 对于从头开始创建简单的绘图,这是相当容易。 但为了实际修改现有文件,我想您需要一个解释文件并提供某种“DOM”进行操作的库。
我什至可以在 EPS 文件中命名形状和点吗?
编辑:假设我将图层保存在单独的 EPS 文件中。 或者更好的是:只是层的“数据”部分。 然后我可以连接这些东西来创建一个新的 EPS 文件吗? 并附加绘图命令? 填充现有的命名对象?
I am looking for libraries that would help in programatically manipulating EPS (Encapsulated PostScript) files. Basically, what I want to do is following:
- Show / Hide preexisting layers in the EPS file (toggle them on and off)
- Fill (color) named shapes in the EPS file
- Retrieve coordinates of named points in the EPS file
- draw shapes on a new layer in the EPS file
- on a server, without user interaction (scripting Adobe Illustrator won't work)
I am aware of how the EPS file format is based on the PostScript language and must therefore be interpreted - for creating simple drawings from scratch this is rather easy. But for actually modifying existing files, I guess you need a library that interprets the file and provides some kind of "DOM" for manipulation.
Can I even have named shapes and points inside an EPS file?
EDIT: Assuming I had the layers saved in separate EPS files. Or better still: Just the "data" part of the layers. Could I then concatenate this stuff to create a new EPS file? And append drawing commands? Fill existing named objects?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是极其困难的,原因如下:PS 文件是一个程序,其执行结果是在页面上放置像素。 PS 程序中的指令处于“使用当前笔和颜色画一条线”或“将坐标系旋转 90 度”的级别,但没有像矢量绘图中那样的图层或复杂对象的概念应用。
PS 文件的结构中很少有允许外部程序修改它们的约定:页面单独标记,字体资源和媒体尺寸在特殊注释中拼写出来。 对于嵌入式 Postscript (EPS) 来说尤其如此,它必须遵循这些准则,因为它们旨在由应用程序读取,但不适用于发送到打印机的通用 PS。 PS 程序的抽象级别比您需要的要低得多,现在可以为任意 PS 代码重构它。 原则上,PS 文件每次打印时可能会产生不同的输出,因为它可能会查询其执行环境并基于随机决策进行分支。
Adobe Illustrator 等应用程序发出遵循严格结构的 PS 代码。 有可能无需解释代码即可解析和操作这些内容。 我仍然建议重新考虑当前的架构:对于您所需要的东西来说,您的抽象级别太低了。
This is extremely difficult and here is why: a PS file is a program whose execution results in pixels put on a page. Instruction in a PS program are at the level of "draw a line using the current pen and color" or "rotate the coordinate system by 90 degrees" but there is no notion of layers or complex objects like you would see them in a vector drawing application.
There are very few conventions in the structure of PS files to allow external programs to modify them: pages are marked separately, font resources, and media dimensions are spelled out in special comments. This is especially true for Embedded Postscript (EPS) which must follow these guidelines because they are meant to be read by applications but not for general PS as it is sent to a printer. A PS program is a much lower level of abstraction than what you need and there is now way to reconstruct it for arbitrary PS code. In principle could a PS file result in different output every time it is printed because it may query its execution environment and branch based on random decisions.
Applications like Adobe Illustrator emit PS code that follow a rigid structure. There is a chance that these could be parsed and manipulated without interpreting the code. I would stil suggest to rethink the current architecture: you are at a too low level of abstraction for what you need.
PDF 不可操作,因为不可能更改 pdf 的任何现有部分(通常),只能添加内容。 EPS 与 PostScript 相同,只是它有一个边界标头。
做你想做的事情的问题是 PS 是一种编程语言,其输出(大部分)是某种图像。 所以问题可以表述为“如何在 Java 文件中的新图层上绘制形状”。 您可能需要即时生成完整的 PS,或者完全使用其他图像格式。
PDF is not manipulable since it is not possible to change any existing parts of a pdf (in general) only add stuff. EPS is the same as PostScript except that it has a boundary header.
Problem with doing what you want is that PS is a programming language whose output (mostly) is some kind of image. So the question could be stated as "how can I draw shapes on a new layer in the Java file". You probably need to generate the complete PS on the fly, or use another image format altogether.
我不知道有任何可用的库,但您也许可以基于 epstool
I am not aware of any available libraries for this but you may be able to build something to meet your needs based on epstool from Ghostscript/GSview
我认为最好的选择是从 EPS 生成 PDF,然后操作 PDF。 然后回到每股收益。 PDF 比 EPS 更“可操作”。
I think your best bet is to generate a PDF from the EPS and then manipulate the PDF. Then back to EPS. PDF is much more "manipulable" than is EPS.