PDFsharp & MigraDoc Foundation

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

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Problem with PdfImage
PostPosted: Tue May 24, 2011 9:57 am 
Offline

Joined: Tue May 24, 2011 9:40 am
Posts: 5
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?


Last edited by tom 88 on Tue May 24, 2011 11:57 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Tue May 24, 2011 11:51 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
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?

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue May 24, 2011 11:57 am 
Offline

Joined: Tue May 24, 2011 9:40 am
Posts: 5
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 =/


Top
 Profile  
Reply with quote  
PostPosted: Tue May 24, 2011 12:03 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue May 24, 2011 12:07 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue May 24, 2011 12:28 pm 
Offline

Joined: Tue May 24, 2011 9:40 am
Posts: 5
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)


Top
 Profile  
Reply with quote  
PostPosted: Tue May 24, 2011 1:25 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
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 280 times

_________________
Regards
Thomas Hoevel
PDFsharp Team
Top
 Profile  
Reply with quote  
PostPosted: Tue May 24, 2011 1:29 pm 
Offline

Joined: Tue May 24, 2011 9:40 am
Posts: 5
Thank you VERY much :)

Tested and works great!

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


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

All times are UTC


Who is online

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