Introduction
Printing industry has many
standards and modern printing devices actually operate with colors using
specific colorspaces different from well-known sRGB or AdobeRGB. One of the
widely used colorspaces is CMYK [Cyan, Magenta, Yellow, blacK] and when you
have to convert a PDF page prepared for publishing in CMYK to jpeg or other
raster format, you have to apply a color transform because CMYK bitmaps don’t
have the level of support they should have gotten in software tools.
Luckily, PDF defines a standard
way to handle this conversion – ICC color profiles, these profiles define the
conversion rules and contain all data needed to perform the transformation.
Profiles are being created considering the target device or medium (or both),
e.g. a special kind of paper, printer model etc. There are lots of publicly
available color profiles, and some of them became more popular than others.
PDF standard supports content
drawn in, so-called, Device CMYK
colorspace – a “generic” CMYK colorspace that doesn’t have any associated
transformation data. It becomes transformed to RGB or any other colorspace
according to rules specified by the DEVICE used to present the content, hence
the naming Device CMYK. Sometimes a color
profile gets embedded into the file and special type of colorspace named ICCBasedColorspace is used to reference
it. It makes content color transformation independent from the device as it
defines its own transformation to the target colorspace for all colors that
belong to ICCBasedColorspace.
The code
/// <summary>
/// This program demonstrates how to use custom CMYK profile for
/// CMYK to RGB transformation.
/// </summary>
class Program
{
static void Main(string[] args)
{
string outputFileName = "output.png";
using (Stream stream = File.OpenRead("../../data/cmyk.pdf"),
profileStream = File.OpenRead("../../data/profile.icc"))
{
// set
global CMYK profile to be used
// for CMYK -> RGB conversion,
// it's also possible to pass
engine settings as a parameter
// during Document object creation.
EngineSettings.GlobalSettings.CMYKColorProfile =
new IccColorProfile(profileStream);
using (Document doc = new Document(stream))
{
Bitmap result = doc.Pages[0].Render(
new Resolution(96, 96),
new RenderingSettings());
result.Save(outputFileName);
}
}
Process.Start(outputFileName);
}
}
The complete example can be
found in our github
repository.
Results
Original PDF document, shown in PDF reader:
Pic. 1 Original PDF file in CMYK
|
Converted using Apitron PDF Rasterizer (default profile):
Pic. 2 Converted using default CMYK profile
|
Converted by Apitron PDF Rasterizer using custom profile set
using EngineSettings class:
Pic. 3 Converted using custom CMYK profile
|
Summary
Apitron PDF Rasterizer for
.NET is a powerful library that allows you to do more by doing less. You
can customize PDF to image conversion results by using its rich and smart API,
and if you need a base to start with, we have lots of ready to use samples. Nowadays, .NET is not limited to Windows
ecosystem and runs on iOS and Android (thanks to Xamarin) as well as any
Mono-aware platform, and our tools are not exclusion. Whenever you need any
help, just let us know and get a guaranteed reply from our techies.
No comments:
Post a Comment