pdf links

PDF Rendering
Convert PDF to Image (.NET)
Convert PDF to image on Android (Xamarin)
Convert PDF to image on iOS (Xamarin)
Convert PDF to image in Windows Store apps (.NET)
Convert PDF to image in Windows Phone apps (.NET)
PDF to image in Universal Windows Store apps (.NET)
Free PDF Viewer control for Windows Forms (.NET)
How to integrate PDF Viewer control in WPF app (.NET)
Creating WPF PDF Viewer supporting bookmarks (.NET)
Cross-platform PDF Viewer using GTK# (MONO)
Silverlight PDF viewer control (Silverlight 5)
Multithreaded PDF rendering (.NET)
Convert pdf to image in Silverlight app (C# sample)
How to set fallback fonts for PDF rendering (C#)
Avoiding the out-of-memory exception on rendering (C#)
PDF viewer single page application (WebAPI, AngularJS)
PDF viewer control for Windows 10 universal applications
Use custom ICC profile for CMYK to RGB conversion
PDF layers - separate images, text, annotations, graphics

PDF Forms Creation PDF Security
Conversion to PDF/A
Other topics
PDF Document Manipulation PDF Content Generation
Fixed and Flow layout document API (.NET)
Creation of grids and tables in PDF (C# sample)
How to create interactive documents using Actions (C# sample)
Text flow effects in PDF (C# sample)
How to generate ordered and bulleted lists in PDF (C# sample)
Convert HTML to PDF using flow layout API (C# sample)
How to use custom fonts for PDF generation (.NET)
Create document with differently sized pages (C#)
Create PDF documents using MONO (C#/MONO/Windows/OSX)
How to use background images for content elements (C#/PDF Kit/FlowLayout)
Add transparent images to PDF document (C#)
Draw round rect borders in PDF documents(C#)
ICC color profiles and and ICC based colors in PDF (C#)
How to use bidirectional and right to left text in PDF (C#)
Create PDF documents from XML templates (C# sample)
How to resize PDF pages and use custom stamps (C#)
Add header and footer to PDF page (.NET sample)
How to use clipping mask for drawing on PDF page
Fill graphics path with gradient brushes in PDF (Shadings)
Apitron PDF Kit and Rasterizer engine settings
Add layers to PDF page (optional content, C# sample)
How to create free text annotation with custom appearance
PDF Content Extraction PDF Navigation
PDF to TIFF conversion
Contact us if you have a PDF related question and we'll cover it in our blog.

2016-05-16

Convert PDF to image using ICC color profile for CMYK to RGB transformation

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.

If you use Apitron PDF Rasterizer and would like to apply a custom CMYK to RGB color profile instead of default one, you can do it easily using the EngineSettings class. The next section contains a code sample demonstrating it.

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

Pic. 1 Original PDF file in CMYK


Converted using Apitron PDF Rasterizer (default profile):


Pic. 2 Converted using default CMYK 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

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