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

Image stream works for PNG but not for JPG.
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3219
Page 1 of 1

Author:  hsj [ Tue Oct 27, 2015 11:53 am ]
Post subject:  Image stream works for PNG but not for JPG.

I have memory streams of JPG files that I need to put into PDFs. It works fine for PNG files but for JPG files it says "Image could not be read" in the resulting PDF.

I think I've isolated it to the MigraDoc not reading the JPG correctly when they're base64 encoded, apologies if it's my own stupid bug.

See attached sample project reproducing the issue.

Attachments:
File comment: VS2013 solution
pdfmigra-jpg-error.zip [109.65 KiB]
Downloaded 417 times

Author:  TH-Soft [ Tue Oct 27, 2015 1:01 pm ]
Post subject:  Re: Image stream works for PNG but not for JPG.

Hi!

Thanks for the sample project.

Your code works with the GDI build of MigraDoc. It does work with the WPF build of MigraDoc.

The problem occurs only with the Core build of MigraDoc. Should be fixed with the next beta version of PDFsharp 1.50.
As a quick fix, try one of the other builds.

Author:  hsj [ Wed Oct 28, 2015 10:02 am ]
Post subject:  Re: Image stream works for PNG but not for JPG.

Thanks a lot, I got it working.

However, when I loaded the images from our database it seems like MigraDoc doesn't like the specific JGP format. I attached a test image.

Is it the JPG handling in PDFSharp+MigraDoc that doesn't understand the image or is it possibly corrupt?

If I use this image instead of the image in the sample project I sent you yesterday I get no images and a broken layout.

Any idea what's going on?

Attachments:
jpgimg2.jpg
jpgimg2.jpg [ 15.72 KiB | Viewed 6925 times ]

Author:  Thomas Hoevel [ Wed Oct 28, 2015 10:16 am ]
Post subject:  Re: Image stream works for PNG but not for JPG.

hsj wrote:
Any idea what's going on?
I will check it.
The new image works with the GDI build, but not with the WPF build.

I will investigate what's special about the new image.

Author:  Thomas Hoevel [ Wed Oct 28, 2015 11:01 am ]
Post subject:  Re: Image stream works for PNG but not for JPG.

hsj wrote:
Any idea what's going on?


WPF report 0 DPI for your image. The MigraDoc code divides by zero and creates an invalid PDF.

There is a quick workaround: set the image resolution in your code (if you continue to use the WPF build):
Code:
image = paragraph.AddImage(@"..\..\..\jpgimg2.jpg");
image.Resolution = 96;

The GDI build return non-zero DPI and all is well. As mentioned before, switching to the GDI build is another option.


MigraDoc should not create invalid PDFs. I will discuss internally what we will do in this case, but it should work properly without setting the resolution.
I'm sorry for the inconvenience. Thank you for your valuable feedback.

JPEGs with 0 DPI must be very rare - this sort of problem was not reported before.

Author:  hsj [ Wed Oct 28, 2015 11:21 am ]
Post subject:  Re: Image stream works for PNG but not for JPG.

Awesome it's working now, thanks very much for your fast and effective response.

much obliged,
hsj

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