PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Wed May 08, 2024 3:27 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Adding CMYK TIFF Images
PostPosted: Wed Feb 20, 2013 5:06 pm 
Offline

Joined: Wed Feb 20, 2013 4:56 pm
Posts: 4
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


Top
 Profile  
Reply with quote  
PostPosted: Wed Feb 20, 2013 5:54 pm 
Offline
PDFsharp Guru
User avatar

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

You can try the GDI+ build to see if that works.

CMYK JPEG files should work.

CMYK TIFF files should also work - we tried a few files we had when we implemented it.
If your files work neither with the GDI+ build nor the WPF build, then we would need a sample file to check what Windows makes out of the file.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Feb 20, 2013 6:02 pm 
Offline

Joined: Wed Feb 20, 2013 4:56 pm
Posts: 4
Thanks for the quick reply!

I forgot to mention that I used the GDI+ build, and I am now trying the WPF variant to see, if this one works. I'll keep you updated!


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 21, 2013 7:55 am 
Offline

Joined: Wed Feb 20, 2013 4:56 pm
Posts: 4
The WPF build seems to work, thanks for your help!

I can send you the problematic TIFFs for testing the GDI+ build, if you want to have them.


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 21, 2013 9:22 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3097
Location: Cologne, Germany
Glad it works now.

If it works with the WPF build, it should be easy to fix for the GDI+ build.
I'll have a look at your files.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 25, 2013 1:43 pm 
Offline

Joined: Wed Feb 20, 2013 4:56 pm
Posts: 4
Hi,

I encountered a new problem with a TIFF (CMYK + Alpha): The WPF build is not able to draw the image and throws the exception: "Image format "Cmyk32" not supported." Does this mean, I cannot use Cmyk32 images, or is there a workaround available?

Thanks in advance!


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

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 65 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