This project has moved and is read-only. For the latest updates, please go here.

Reading Colorspace of PDF, AI, EPS before converting to JPG

Apr 25, 2015 at 7:06 PM
We have an application that we want to start to allow people to upload PDF, AI, and EPS files. So far so god but I can't figure out how to get the info such as colorspace of the file. We want to get this before processing and creating thumbnails so that we can provide appropriate alerts to the user, based on the colorspace of the file.

This is what we are using which has worked fine rasterized images but not postscript or vector based files. We have tried converting the file to a JPG first to but that ends up also converting it to an RGB file.

public string GetImageInfo(string vFilePath)

    // Read from file
    MagickImageInfo info = new MagickImageInfo();

  // Read from stream
    using (MemoryStream memStream = LoadMemoryStreamImage(vFilePath))
        info = new MagickImageInfo(memStream);

    // Read from byte array
    byte[] data = LoadImageBytes(vFilePath);
    info = new MagickImageInfo(data);

    info = new MagickImageInfo();

    using (MemoryStream memStream = LoadMemoryStreamImage(vFilePath))

    string ReturnInfo = "&Width=" + info.Width;
    ReturnInfo += "&Height=" + info.Height;
    ReturnInfo += "&ColorSpace=" + info.ColorSpace;
    ReturnInfo += "&Format=" + info.Format;
    ReturnInfo += "&ResolutionX=" + info.ResolutionX;
    ReturnInfo += "&ResolutionY=" + info.ResolutionY;

    return ReturnInfo;

The error it generates indicates
" w3wp.exe: UnableToCreateTemporaryFile ': No such file or directory @ error/pdf.c/ReadPDFImage/462"

I will appreciate any insight.
Apr 25, 2015 at 8:27 PM
After digging more into this I think I found how to make this work. Essentially I am converting the PDF file to a rasturizing like before but now am adding the DetermineColorType() method in the mix.

image.Format = MagickFormat.Jpg;
image.DetermineColorType(); // This keeps the resulting jpg file as the original colorspace of the postscript file.
image.Quality = 100;

The rasturized file now preserves the original color space of the postscript file which we can then retrieve later to do with what we need.

I don't quite understand what this did beyond that but at least it works :)