All formats

Ghostscript.NET

LanguageC# (.NET Standard 2.0: .NET 6+, .NET Framework 4.6.1+)
LicenseAGPL-3.0 or commercial license from Artifex
Repositorygithub.com/ArtifexSoftware/Ghostscript.NET
DocumentationREADME, Ghostscript EPS options
Depends onGhostscript native library, SkiaSharp
Read / writeyes / yes (renders EPS; writes EPS with Ghostscript's eps2write)

Ghostscript.NET runs Ghostscript inside your .NET process. For EPS, GhostscriptRasterizer has an EPSClip property that crops the output to the %%BoundingBox, and GhostscriptProcessor runs any Ghostscript command line, including EPS to PDF and PDF to EPS conversions that keep vector graphics.

It runs on Windows and Linux. Ghostscript and Ghostscript.NET are AGPL-3.0; closed-source products need a commercial license from Artifex.

Installation#

Shell
dotnet add package Ghostscript.NET
dotnet add package Ghostscript.NativeAssets   # optional: bundle Ghostscript with the app

Basic usage: render EPS to PNG#

C#
using Ghostscript.NET;
using Ghostscript.NET.Rasterizer;
using SkiaSharp;

using var rasterizer = new GhostscriptRasterizer();
rasterizer.EPSClip = true;          // crop to the bounding box
rasterizer.TextAlphaBits = 4;
rasterizer.GraphicsAlphaBits = 4;
rasterizer.Open("logo.eps", GhostscriptVersionInfo.GetPreferredVersion(), false);

using SKBitmap bitmap = rasterizer.GetPage(dpi: 300, pageNumber: 1);
using var output = File.OpenWrite("logo.png");
bitmap.Encode(output, SKEncodedImageFormat.Png, 100);

How to convert EPS to PDF in C#

C#
using Ghostscript.NET.Processor;

using var processor = new GhostscriptProcessor();
processor.Process(new[]
{
    "-dBATCH", "-dNOPAUSE", "-dSAFER", "-dQUIET",
    "-dEPSCrop",                 // PDF page = bounding box
    "-sDEVICE=pdfwrite",
    "-sOutputFile=logo.pdf",
    "logo.eps",
});

How to convert a PDF page to EPS#

C#
using var processor = new GhostscriptProcessor();
processor.Process(new[]
{
    "-dBATCH", "-dNOPAUSE", "-dSAFER", "-dQUIET",
    "-sDEVICE=eps2write",
    "-dFirstPage=3", "-dLastPage=3",   // EPS holds one page
    "-sOutputFile=page3.eps",
    "report.pdf",
});

How to get the real bounding box of an EPS file#

The bbox device prints %%BoundingBox lines on stderr:

C#
using System.Text;
using Ghostscript.NET;
using Ghostscript.NET.Processor;

class Capture : GhostscriptStdIO
{
    public readonly StringBuilder Err = new();
    public override void StdIn(out string input, int count) => input = string.Empty;
    public override void StdOut(string output) { }
    public override void StdError(string error) => Err.Append(error);
}

var capture = new Capture();
using var processor = new GhostscriptProcessor();
processor.Process(new[] { "-dBATCH", "-dNOPAUSE", "-dSAFER", "-dQUIET",
                          "-sDEVICE=bbox", "logo.eps" }, capture);
Console.WriteLine(capture.Err);  // %%BoundingBox: 10 10 190 90 ...

Tips#