PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon Jun 17, 2024 10:28 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
PostPosted: Tue Jun 18, 2013 9:48 am 
Offline

Joined: Tue Jun 18, 2013 7:48 am
Posts: 8
Hi,

i'm using MigraDoc to generate Product data sheets as PDF.
When i add an Image with paragraph.AddImage(Stream stream), this returns an Image with massive jpeg artefacts.
I'm using neither rescaling nor resizing.
Is this function AddImage modifying the stream before adding to image, and if so, is there any way to set / change the quality?

Searching for any threads solving my issue returned with no result.

Thanks in advance,

FEN

(width, height and stream are properties of the image object)
Code:
Row rowImage = table.AddRow();
rowImage.Height = XUnit.FromCentimeter(9.6).Point;

Paragraph paragraphImage = new Paragraph();

Image img = paragraphImage.AddImage(stream);
if (img != null)
{
   img.Width = width; //px
   img.Height = height; //px
}
rowImage[0].Add(paragraphImage);



Original picture and screenshot of the generated PDF are attached. (Why it is not allowed to attach pdf documents?)


Attachments:
Screenshot_ProductDataSheetImage.png
Screenshot_ProductDataSheetImage.png [ 198.83 KiB | Viewed 10129 times ]
ProductDataSheetImage.jpg
ProductDataSheetImage.jpg [ 19.66 KiB | Viewed 10129 times ]
Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 18, 2013 11:27 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
Hi!
FEN wrote:
Is this function AddImage modifying the stream before adding to image, and if so, is there any way to set / change the quality?
MigraDoc stores all images in the PDF file as they are.
What you see is the quality of your image, but scaled by 3x or 4x or so - and smoothed by Adobe Reader.
A 20 kiB JPEG will never look good when viewed full screen.

You can try "image.Interpolate = false;" for the image to disable smoothing by Adobe Reader.
See also:
viewtopic.php?p=2471#p2471

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 19, 2013 3:24 pm 
Offline

Joined: Tue Jun 18, 2013 7:48 am
Posts: 8
Hi Thomas,

i attached another screenshot with a view of the original picture size on website and pdf. As you can see, the quality of the image in pdf is worse than the image on website, because of jpeg artefacts. I wonder about the artefacts, because you said, MigraDoc stores all images in the PDF files as they are. :( Disabling Interpolation has no effect.


Attachments:
ImageWebSite_ImagePdf.PNG
ImageWebSite_ImagePdf.PNG [ 76.9 KiB | Viewed 10117 times ]
Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 19, 2013 3:35 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
Hi!
FEN wrote:
When i add an Image with paragraph.AddImage(Stream stream), this returns an Image with massive jpeg artefacts.
The original MigraDoc only allows adding images from a filename, not from a stream.
You are using a modified version of MigraDoc.

Images from a stream may be recompressed - and the dithered images lead to massive artefacts.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 20, 2013 1:09 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
FEN wrote:
When i add an Image with paragraph.AddImage(Stream stream), this returns an Image with massive jpeg artefacts.
To avoid recompression the implementation of "paragraph.AddImage(Stream stream)" must store the stream internally in order to have the original JPEG data copied to the PDF.

Or simply save the stream to a temporary file and pass the filename to AddImage.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Fri Jun 21, 2013 8:13 am 
Offline

Joined: Tue Jun 18, 2013 7:48 am
Posts: 8
Hi Thomas,

thanks for your helpful answer. :D I'll try it out.


Top
 Profile  
Reply with quote  
PostPosted: Wed Sep 18, 2013 3:17 pm 
Offline

Joined: Wed Sep 18, 2013 3:02 pm
Posts: 1
Hi Thomas,
Could you explain further "Images from a stream may be recompressed"? Like the original poster, I want to use a Stream input for an image, but Migradoc doesn't allow this. I could use a temp file, but it is an extra step since my graphic is created and painted in the application. I would like to understand why Migradoc is written without AddImage(Stream stream), and what the risk is for me to add an extension.

Thank you,

Greg


Top
 Profile  
Reply with quote  
PostPosted: Wed Sep 18, 2013 3:54 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
G Fichter wrote:
I would like to understand why Migradoc is written without AddImage(Stream stream), and what the risk is for me to add an extension.
MigraDoc was designed to persist documents in text files (MGDDL). Filenames will persist, streams will not.
You can use streams if you don't need persistence.

_________________
Regards
Thomas Hoevel
PDFsharp Team


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