3

I must be doing something wrong. I have tried rendering an image to a PDF to both a pdfContext in iOS and a PDF using PDFSharp. When I do it, it's blurry compared to when I open it up in Photoshop or Microsoft's picture preview. So maybe I don't understand what is going on with the image itself. Here is what I know:

Image size is 90 x 20 (w x h). The resolution is 264 ppi.

To draw it in PDFSharp, I do:

XImage image = XImage.FromGdiPlusImage(Properties.Resources.logo);
gphx.DrawImage(image, leftStartDefault, 50, image.PointWidth, image.PointHeight);

I have also tried image.PixelWidth, image.PixelHeight in the above code. Both produce the same blurry result.

In iOS, I do

UIImage *logo = [UIImage imageNamed:@"logo.png"];
[logo drawInRect:CGRectMake(self.frame.size.width - 90 - 60, 20, 90, 20)];

Both produce blurry results. I'm not sure why. I don't know if it's something I am missing with how to choose the size to draw. If I need to ask for a different resolution/size image from our graphics artist, or if it's the way I make the drawing call. If I draw the image at half the size, it is clearer.

e.g.

gphx.DrawImage(image, leftStartDefault, 50, 45, 10);

Any thoughts? thanks.

Mansfield
  • 14,445
  • 18
  • 76
  • 112
Crystal
  • 28,460
  • 62
  • 219
  • 393
  • Crystal look at this link it may add some helpful hints [Hot to render PDF's](http://stackoverflow.com/questions/518878/how-to-render-pdfs-using-c-sharp) – MethodMan Jan 10 '13 at 22:12

2 Answers2

2

I realize this is old and perhaps no longer an issue, but I had the same problem.

I found this thread on the PDFSharp forums which was of some use.

As far as I can tell, x pixels on an image in paint does not transfer the same way to y pixels in an image on a pdf (at least in my case). Having an image of 100x100px in paint would apply the same image to the pdf at approximately 153x153px. I have absolutely no idea why this happens, but once I figured out the the factor by which the image size was increased, it became a simple matter to "resize" the image for printing on the pdf.

Like so:

gfx.DrawImage(logo, 0, 0, ApplyTransform(logo.PointWidth), ApplyTransform(logo.PointHeight));

private static double ApplyTransform(double previous)
{
    return previous * .6538;
}

EDIT: Upon further research, I believe this is caused by pdf documents not having the concept of pixels in the first place.

Mansfield
  • 14,445
  • 18
  • 76
  • 112
  • Yes, PDF documents use absolute units such as point, inch and millimeter. The PointWidth of the image will return the expected print size in points, according to the images number of pixels and the specified PPI, which is a property embedded in the image format. – Oskar Berggren Jul 19 '15 at 19:49
  • 1
    I found that setting XImage.Interpolate to false worked for me when my barcode images were printing out blurry. – Zack Oct 15 '15 at 21:50
0

Probably, the PDF rasterizing libraries use different, than Photoshop, Windows Viewer ... algorithms of image interpolation, which incorrectly applies for the resulted view. Also they have used different ICC profiles, it also affects the rendering.

  • The XImage.Interpolate property can be set to false when adding images to the PdfPage, then they stop appearing blurry in the PDF. – Zack Oct 15 '15 at 21:51