Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically manipulate an EPS file

Tags:

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?

like image 411
Daren Thomas Avatar asked Jan 09 '09 12:01

Daren Thomas


People also ask

What programs can edit EPS files?

Adobe Illustrator is a vector editor that can read and write EPS, AI, PDF, SVG, and many other formats. Illustrator is the most widely-used vector editor and many other tools have emulated its user interface. CorelDRAW is a vector editor that can read and write EPS, AI, PDF, SVG and many other formats.

Can you edit ESP files?

EPS files, if opened in a vector-based program such as Adobe Illustrator, or Corel Draw, will have the ability to be resized without loss of quality, and will also be able to be easily edited and manipulated.


1 Answers

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.

like image 199
Christian Lindig Avatar answered Sep 23 '22 18:09

Christian Lindig