Rustam
Rustam

Reputation: 123

How can I tell ghostscript not to rasterize gradients in eps files?

I was searching for solution that would allow me to read, edit and save .eps files. I found out that ghostscript can give all of this opportunities. The algoritm I need is simple: read several .eps files, concatenate them in one big file and save new .eps file. I can do that already but there is a problem: new generated and saved files don't preserve gradients. Gradients are rasterized and shapes which use that gradients are converted to clipping masks. Is there a way to tell ghostscript not to rasterize gradients in eps?

I'm using latest 32 bit version of ghostscript library though my Windows is 64 bit (there were problems running solution on 64 bit version of ghostscript). Actually it's not so important but I'm writting using C# and Ghostscript.Net.

This is the sample code:

using (GhostscriptProcessor processor = new GhostscriptProcessor(lastInstalledVersion, true))
{
    List<string> switches = new List<string>();
    switches.Add("-o");
    switches.Add(@"-sOutputFile=" + outputFile);
    switches.Add("-sDEVICE=eps2write");
    switches.Add("-dUseCIEColor=true");
    switches.Add("-c");
    switches.Add("<</Install {0.5 0.5 scale}>> setpagedevice");
    switches.Add("-f");
    switches.Add(inputFile);

    processor.Process(switches.ToArray());
}

Upvotes: 1

Views: 297

Answers (1)

KenS
KenS

Reputation: 31139

The answer to the question you have asked is simple; you can't. The eps2write device is called that for a reason, it only produces level 2 PostScript, and the shfill operator, or type 2 pattern (shading dictionary in PDF) is a level 3 PostScript primitive.

However, there seems to be no good reason to run the exiting files through Ghostscript anyway. You say you already have a number of EPS files. The whole point of EPS files is that they can be treated as a 'black box', you do not need to know what's in them in order to concatenate them, rearrange them etc.

All you do is write some 'wrapper' PostScript that alters the CTM before including the EPS file in its entirety. You can work out what the arguments to scale and translate should be, because the EPS file will have a %%BoundingBox comment that tells you where it sits in user space. All you need to do is alter the scale, and offset the 0,0 origin (bottom left) using translate.

Note that the eps2write device, because it is limited to producing level 2 PostScript, also does not support some other features of PostScript beyond the original level 2 specification, such as CIDFonts.

Upvotes: 2

Related Questions