PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Wed Jun 19, 2019 8:50 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Tue Feb 26, 2019 1:38 pm 
Offline

Joined: Mon Feb 25, 2019 6:56 pm
Posts: 2
Hi,
I'm using PDFsharp along with the HTML Renderer (https://theartofdev.com/html-renderer/) library to save an MVC view to a PDF. The HTML has IMG tags with the image content inline as base 64 strings. The resulting PDF has the images present. However, they have been increased in size 20-30% and are blurry. I've been able to add CSS to the page to force the maximum size of the IMG to prevent scaling up too much. But the image is still blurry.

I'm trying to figure out if there is anything I can do with PDFsharp to prevent this behavior. I'm not sure if the problem is there or in the HTML Renderer. I see that there is an event handler available to manually handle image processing but have yet to get that to work.

Any help is appreciated.


Top
 Profile  
Reply with quote  
PostPosted: Tue Feb 26, 2019 2:51 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2945
Location: Cologne, Germany
Hi!

To prevent blurriness set "image.Interpolate = false;" for the image.
If you cannot do that in the image processing callback, then you'll have to modify the HtmlRenderer code.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Feb 26, 2019 4:03 pm 
Offline

Joined: Mon Feb 25, 2019 6:56 pm
Posts: 2
Thanks. I've got the HTML Renderer callback work now but still no luck on the image quality. Here's what I've tried:

byte[] imageData = Convert.FromBase64String(eventArgs.Src.Substring(5));
using (var ms = new MemoryStream(imageData))
{
XImage ximg = XImage.FromStream(ms);
ximg.Interpolate = false;

eventArgs.Handled = true;
eventArgs.Callback(ximg);
}

The XImage passed to callback is then supplied to PDFsharp as the image. Any ideas?


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

All times are UTC


Who is online

Users browsing this forum: Rocky48 and 6 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