5

I need a program/sdk/software to convert pdf file to images.I require the following features in that converter:

Check if the pdf file is colored or BW. If the pdf file is BW, an option to convert the pdf file to .tiff images. If the pdf file is Colored, an option to convert the pdf file to .png images. This conversion should be fast and if possible, should have multi-threading option. It can be a free tool (open source) or a paid solution that I can integrate with Visual Studio 2010 C#. Meaning a command line interface would work.

5

To check whether the PDF is colored or BW, you can use Ghostscript (free, open-source, cross-platform):

Example commandline:

gs -o - -sDEVICE=inkcov /path/to/your.pdf

Example output:

Page 1
0.00000  0.00000  0.00000  0.02230 CMYK OK
Page 2
0.02360  0.02360  0.02360  0.02360 CMYK OK
Page 3
0.02525  0.02525  0.02525  0.00000 CMYK OK
Page 4
0.00000  0.00000  0.00000  0.01982 CMYK OK

You can see here that the page 4 is using no color, while pages 1+2+3 do. This case is particularly 'nasty' for people who want to save on color ink: because all the C, M, Y (and K) values are exactly the same for each of the pages 1-3, they possibly could appear to the human eye not as color pages, but as ("rich") grayscale anyway (if each single pixel is mixed with these color values).

Other ideas: How do I know if PDF pages are color or black-and-white?


To convert a PDF to TIFF, you can use GhostScript (free, open-source, cross-platform):

on Windows:

gswin32c -dNOPAUSE -q -g300x300 -sDEVICE=tiffg4 -dBATCH -sOutputFile=output_file_name.tif input_file_name.pdf

on *nix:

gs -dNOPAUSE -q -g300x300 -sDEVICE=tiffg4 -dBATCH -sOutputFile=output_file_name.tif input_file_name.pdf

Other ideas: Best way to convert pdf files to tiff files


To convert a PDF to PNG, you can use ImageMagick (free, open-source, cross-platform):

convert foo.pdf pages-%03d.png
2

If you are interested in a commercial SDK for this type of conversion and image manipulation you can try using LEADTOOLS Imaging SDK. Please note I am an employee of this tool

You can use our ImageColorTypeCommand to check if the image is Black and White, Grayscale, or Color. You can implement this in C# using the following:

using (RasterCodecs codecs = new RasterCodecs())
{
   RasterImage image = codecs.Load(@"path to file");
   ImageColorTypeCommand command = new ImageColorTypeCommand();
   command.Run(image);
   Console.WriteLine("Color Type = " + command.ColorType.ToString() + "\n" + "Confidence = " + command.Confidence.ToString());
}

Once you know what the ImageColorType is can simply save the file specifying the output format like this:

if(command.ColorType == ImageColorType.BlackAndWhite)
{
   codecs.Save(image, @"Save path for output", RasterImageFormat.Tif, 0);
}
else
{
   codecs.Save(image, @"Save path for output", RasterImageFormat.Png, 0);
}

A little more information about the classes used in code can be found here:

RasterCodecs

RasterImage

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.