PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon Jul 15, 2024 11:51 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Wed Feb 25, 2015 8:31 am 
Offline

Joined: Tue Nov 25, 2014 8:27 am
Posts: 3
Hello,

in the wiki article http://www.pdfsharp.net/wiki/ColorsCMYK-sample.ashx?HL=cmyk you show how to print some primitive shapes into a PDF using the CMYK color space.
I have not yet found a way how to print images (not saved as physical files in the file system) from System.Drawing.Image into a PDF using the CMYK color space. Is there a way to do so after all? If yes, could you please add the necessary lines to the wiki entry from above?
The most confortable way would be telling PDFSharp to print an entire PDF converting RGB colors into the CMYK color space using a specific ICC profile for the conversion (well,... one may dream...)
How can i bring CMYK images from the memory into the PDF?

Regards,
f


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 10, 2015 10:21 am 
Offline

Joined: Tue Nov 25, 2014 8:27 am
Posts: 3
Hello again,
i found out, that embedding CMYK-Images into a PDF by using the command XGraphics.DrawImage(...) somehow converts the CMYK image (jpg) back into a RGB-Image.
Is there a way to embed CMYK images into a PDF without converting their CMYK colors (color space?) back into RGB colors (color space?) after all? Am i just too blind to find the possibility?

I use PDFSharp 1.31 (GDI) for generating PDFs (not upgraded yet because i have not found any reason to do so.)

Regards, funkl


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 10, 2015 11:03 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
Hi!

Theoretically JPEG files will be embedded as they are without any conversions.
However some code that worked fine with Windows XP no longer works with Windows 8.1.
Open a CMYK JPEG with Windows XP and Windows will indicate the image is CMYK. Do the same with Windows 8.1 and Windows will tell you it is RGB. :?

Probably we will have to add code to test whether a JPEG file is CMYK or RGB. With PDFsharp 1.50 beta this is not yet implemented.
Information about how we can tell RGB, grayscale, or CMYK from the JPEG file headers (if available) are welcome.

We didn't find many CMYK JPEG images. Maybe there are different flavors that behave differently.
If you think there is an error in PDFsharp, feel free to provide an SSCCE with some code and a CMYK JPEG image for investigation.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 10, 2015 12:35 pm 
Offline

Joined: Tue Nov 25, 2014 8:27 am
Posts: 3
The thing is, that i need to create PDFs converted to the CMYK color space (best case: by specifying an ICC profile for the color conversion).
My idea so far:
Code:
private void RenderImage(Image image, XGraphics graphics, double x, double y, double width, double height)
{
   Bitmap bitmap = new Bitmap(image);

   MemoryStream inStream = new MemoryStream();
   bitmap.Save(inStream, ImageFormat.Png);
   inStream.Position = 0;

   BitmapSource source = BitmapFrame.Create(inStream);

   FormatConvertedBitmap convertingImage = new FormatConvertedBitmap();
   convertingImage.BeginInit();
   convertingImage.Source = source;
   convertingImage.DestinationFormat = PixelFormats.Cmyk32;
   convertingImage.EndInit();

   BitmapEncoder encoder = new JpegBitmapEncoder();
   encoder.Frames.Add(BitmapFrame.Create(convertingImage));
   MemoryStream outStream = new MemoryStream();

   encoder.Save(outStream);
         
   XImage xImage = new XImage(outStream);
   xImage.Interpolate = false;
   graphics.DrawImage(xImage, x - 1, y - 1);
}

Writing the image like this results in some sort of "mashed" RGB image in the PDF. I already found some advice you offer in order to obtain a "regular" image, which i suppose would still be RGB.
When i use a FileStream instead of the MemoryStream in line 19, the image is exported as a CMYK image.
Is there eventually sg. wrong inside the XImage or the XGraphics?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 18 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group