How to programmatically manipulate an EPS file
Asked Answered
S

4

6

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?

Spelunker answered 9/1, 2009 at 12:39 Comment(2)
Are the EPS files generated by some program you control?Leanora
Actually, EPS ist the output format. It would be nice to have both input (template) format and output format the same, but this is not a necessity.Spelunker
T
7

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.

Terat answered 18/1, 2009 at 12:34 Comment(1)
Hi christian, Is there any way to find out the color information about the eps?Steffin
D
3

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.

Der answered 9/1, 2009 at 13:23 Comment(0)
C
1

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

Chinaware answered 9/1, 2009 at 12:53 Comment(0)
L
1

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.

Leanora answered 9/1, 2009 at 13:6 Comment(1)
You do not gain any additional information by converting the EPS to a PDF.Purity

© 2022 - 2024 — McMap. All rights reserved.