PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.de/

How to develop PDFSharp?
http://forum.pdfsharp.de/viewtopic.php?f=2&t=836
Page 1 of 1

Author:  kanski [ Mon Aug 17, 2009 2:30 pm ]
Post subject:  How to develop PDFSharp?

Hello group

Recently I had to print image in CMYK color space. I didn't find support in WPF version so I wrote my own function that should be called instead of PdfSharp.Pdf.Advanced.PdfImage.ReadTrueColorMemoryBitmap (code below). Is there any way to extend the basic functionality? The PdfImage class is sealed.
BTW BitmapSource.CopyPixels requires SecurityPermissionFlag.UnmanagedCode
Code:
private void readCmykMemoryBitmap() {
   Debug.Assert(this.image.wpfImage.Format == PixelFormats.Cmyk32,"Only CMYK support");
   int _nOfChannels = 4;

   int height = this.image.PixelHeight;
   int width = this.image.PixelWidth;

   byte[] _destImageData = new byte[_nOfChannels * width * height];

   int _stride = _nOfChannels * width;
   this.image.wpfImage.CopyPixels(_destImageData,_stride,0);

   FlateDecode fd = new FlateDecode();

   byte[] imageDataCompressed = fd.Encode(_destImageData);

   Stream = new PdfStream(imageDataCompressed,this);
   Elements[Keys.Length] = new PdfInteger(imageDataCompressed.Length);
   Elements[Keys.Filter] = new PdfName("/FlateDecode");
   Elements[Keys.Width] = new PdfInteger(width);
   Elements[Keys.Height] = new PdfInteger(height);
   Elements[Keys.BitsPerComponent] = new PdfInteger(8);
   Elements[Keys.ColorSpace] = new PdfName("/DeviceCMYK");
   if(image.Interpolate)
      Elements[Keys.Interpolate] = PdfBoolean.True;
}

Author:  johnsonroom [ Sat Oct 10, 2009 3:39 pm ]
Post subject:  Re: How to develop PDFSharp?

I used your code to embed Tiff with CMYK color into a pdf.
But after I generate and saved the pdf, and then open it, acrobat reader report error!
Would you please give me hand?
Thanks,
johnsonroom@gmail.com.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/