PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Problem with PdfImage
https://forum.pdfsharp.net/viewtopic.php?f=2&t=1663
Page 1 of 1

Author:  tom 88 [ Tue May 24, 2011 9:57 am ]
Post subject:  Problem with PdfImage

A nullReference exception occured to me when adding an image to the pdf file.
Code:
graphicsObj.DrawImage(imageObj, 0, 0);


PdfSharp.Pdf.Advanced - PdfImage line 890
Code:
arrayColorSpace.Elements.Add(colorPalette.Reference);


Apparantly colorPalette wasn't initialized earlier because of the following combination of states:
isBitonal = -1
isGray = false
usesCcittEncoding = false

At the moment, I just use the "DeviceGray" setting when this happens, but when added to the pdf, the image's color is inverted.

Any ideas on how this situation could be dealt with better?

Author:  Thomas Hoevel [ Tue May 24, 2011 11:51 am ]
Post subject:  Re: Problem with PdfImage

I have this "if" at line 883 above line 890:
Code:
if ((usesCcittEncoding && isBitonal == 0) ||
  (!usesCcittEncoding && isBitonal <= 0  && !isGray))

So with "usesCcittEncoding = true" and "isBitonal = -1" line 890 should not be executed.

Can you provide a sample image that causes this exception?

Author:  tom 88 [ Tue May 24, 2011 11:57 am ]
Post subject:  Re: Problem with PdfImage

woops usesCcittEncoding = false
*was true on first page of the tif*
I'll edit my earlier post

Unfortunately I'm not allowed to provide any internal documents =/

Author:  Thomas Hoevel [ Tue May 24, 2011 12:03 pm ]
Post subject:  Re: Problem with PdfImage

In line 655 we have
Code:
if (isBitonal == 0 && !isGray)


Maybe that should be "<= 0" here to match line 883.

If would be nice to have a sample to test with.

Author:  Thomas Hoevel [ Tue May 24, 2011 12:07 pm ]
Post subject:  Re: Problem with PdfImage

tom 88 wrote:
Unfortunately I'm not allowed to provide any internal documents =/

I don't care what the image shows. It just has to be the format that leads to the problem.

Which format? Which tool?

OT: Recently we found that greyscale JPEGs created with IrfanView cause problems while other greyscale JPEGs work fine.

Author:  tom 88 [ Tue May 24, 2011 12:28 pm ]
Post subject:  Re: Problem with PdfImage

Transformed the tif (originally came from fax) to 2 png files using CxImage libraries.
Afterwards I tried to add these png's to a new pdf document.

The one that caused problems looked pretty gray on the left side while the right side was of better quality.
=> this probably caused "isBitonal = -1" on line 645.

also changed the following to make it work (line 655)

Code:
if (isBitonal == 0 && !isGray)

to
Code:
if (paletteData.Length > 0)

Author:  Thomas Hoevel [ Tue May 24, 2011 1:25 pm ]
Post subject:  Re: Problem with PdfImage

I cleaned up the code. Now I create the palette when it is needed.
That should solve the problem.

Please find attached the current version of the file.

Attachments:
PdfImage.zip [9.79 KiB]
Downloaded 279 times

Author:  tom 88 [ Tue May 24, 2011 1:29 pm ]
Post subject:  Re: Problem with PdfImage

Thank you VERY much :)

Tested and works great!

Keep up the great work, it's a brilliant piece of software.

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