All formats

Magick.NET

LanguageC# (.NET and .NET Standard 2.0)
LicenseApache 2.0 (ImageMagick license for the native part; Ghostscript, needed to read PS, is AGPL-3.0)
Repositorygithub.com/dlemstra/Magick.NET
Documentationdocs in the repository
Depends onnative ImageMagick (bundled in the NuGet package); Ghostscript installed separately for reading PS
Read / writeyes (through Ghostscript) / yes (raster images wrapped in PostScript)

Magick.NET bundles ImageMagick in a NuGet package. ImageMagick doesn’t interpret PostScript itself: to read a .ps file it calls Ghostscript, which renders each page to a bitmap, and you get one MagickImage per page. Writing works without Ghostscript: ImageMagick wraps the pixels in a PostScript program (formats Ps, Ps2, Ps3; Ps3 compresses the image data).

Pick Magick.NET when you want PostScript pages as images to resize, crop or convert in the same pipeline as other images. To convert PS to PDF with vector content preserved, use Ghostscript.NET with the pdfwrite device: Magick.NET would rasterize the pages.

Installation#

Shell
dotnet add package Magick.NET-Q8-AnyCPU

Install Ghostscript with the same bitness as your process (64-bit for x64). If you don’t want a system install, copy gsdll64.dll and gswin64c.exe next to your app and point Magick.NET to the folder:

C#
MagickNET.SetGhostscriptDirectory(@"C:\MyApp\Ghostscript");

Basic usage: render all pages of a PostScript file to PNG#

C#
using ImageMagick;

var settings = new MagickReadSettings
{
    Density = new Density(150, 150),  // dpi; the default 72 looks blurry
};

using var pages = new MagickImageCollection();
pages.Read("in.ps", settings);

int n = 1;
foreach (var page in pages)
{
    page.Alpha(AlphaAction.Remove);   // flatten onto white
    page.Write($"page-{n:D3}.png");
    n++;
}

How to render only one page#

FrameIndex is 0-based:

C#
var settings = new MagickReadSettings
{
    Density = new Density(300),
    FrameIndex = 0,  // first page
    FrameCount = 1,
};
using var images = new MagickImageCollection();
images.Read("in.ps", settings);
images[0].Write("page1.png");

How to make a thumbnail of the first page#

C#
var settings = new MagickReadSettings { Density = new Density(72), FrameIndex = 0, FrameCount = 1 };
using var image = new MagickImage("in.ps", settings);
image.Thumbnail(200, 200);
image.Write("thumb.jpg");

How to save an image as PostScript#

C#
using var image = new MagickImage("photo.jpg");
image.Format = MagickFormat.Ps3;  // Level 3, compressed image data
image.Write("photo.ps");

MagickFormat.Ps writes Level 1 (largest, works everywhere), Ps2 Level 2.

Tips#