PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Jul 02, 2024 5:18 pm

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
PostPosted: Tue Oct 27, 2015 11:53 am 
Offline

Joined: Tue Oct 27, 2015 11:12 am
Posts: 3
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 418 times
Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 27, 2015 1:01 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 951
Location: CCAA
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.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 28, 2015 10:02 am 
Offline

Joined: Tue Oct 27, 2015 11:12 am
Posts: 3
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 6932 times ]
Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 28, 2015 10:16 am 
Offline
PDFsharp Guru
User avatar

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

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 28, 2015 11:01 am 
Offline
PDFsharp Guru
User avatar

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

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 28, 2015 11:21 am 
Offline

Joined: Tue Oct 27, 2015 11:12 am
Posts: 3
Awesome it's working now, thanks very much for your fast and effective response.

much obliged,
hsj


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 36 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