Hi,
I'm trying to add a CMYK TIFF image to a document as follows:
Code:
var document = new PdfDocument();
document.Options.ColorMode = PdfColorMode.Cmyk;
using (var image = CreateImageFromByteArray(tiffData))
{
var page = document.AddPage();
page.Size = PageSize.A3;
page.Orientation = PageOrientation.Portrait;
var gfx = XGraphics.FromPdfPage(page);
// maintain aspect ratio
double widthScale = page.Width/image.PointWidth;
double heightScale = page.Height/image.PointHeight;
double scale = Math.Min(widthScale, heightScale);
gfx.DrawImage(image, 0, 0, image.PointWidth*scale, image.PointHeight*scale);
}
CreateImageFromByteArray() is implemented as follows:
Code:
private static XImage CreateImageFromByteArray(byte[] imageData)
{
var stream = new MemoryStream(imageData);
stream.Write(imageData, 0, imageData.Length);
var tiffImage = Image.FromStream(stream);
return XImage.FromGdiPlusImage(tiffImage);
}
Everytime I feed it with the TIFF Image (can be viewed correctly with Windows Photo Viewer), I get the the exception "Image format not supported.", which is thrown in PdfImage.cs, at line 257.
What can I do to fix this? I need to use CMYK, since the generated PDF is intended for Printing. The used environment is ASP.NET.
Thanks in advance,
Wolfgang