Skip to content
\n

If I remove the Resize and Extend methods then the images look sharp as original in PDF but then images are not centered in PDF. The Extend does not work without Resize and Resize produces a blurry image. Spends several hours to understand what's is causing blur in resized(downsized) images without any luck.

\n

I have attached demo images and outputs, the output.pdf has centered but blurry images, the output-no-resize-no-extend.pdf has perfect quality images as I need the to images are no longer centered on the PDF page.

\n

images.zip
\noutput.pdf
\noutput-no-resize-no-extend.pdf

","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"

When you resize the image you will make it smaller. When you want the best quality image you should only Extent the image. You should calculate what the width and height should be to have the same aspect ratio as the page size. You can calculate that with the following method (there might be a better method to do this):

\n
var fromPageSize = MagickGeometry.FromPageSize(\"a4\");\n\nvar width = image.Width / (double)fromPageSize.Width;\nvar height = image.Height / (double)fromPageSize.Height;\nvar max = Math.Max(width, height);\nvar newWidth = (int)(fromPageSize.Width * max);\nvar newHeight = (int)(fromPageSize.Height * max);\n\nimage.Extent(newWidth, newHeight, Gravity.Center);
","upvoteCount":1,"url":"https://github.com/dlemstra/Magick.NET/discussions/1034#discussioncomment-1399037"}}}
Discussion options

You must be logged in to vote

When you resize the image you will make it smaller. When you want the best quality image you should only Extent the image. You should calculate what the width and height should be to have the same aspect ratio as the page size. You can calculate that with the following method (there might be a better method to do this):

var fromPageSize = MagickGeometry.FromPageSize("a4");

var width = image.Width / (double)fromPageSize.Width;
var height = image.Height / (double)fromPageSize.Height;
var max = Math.Max(width, height);
var newWidth = (int)(fromPageSize.Width * max);
var newHeight = (int)(fromPageSize.Height * max);

image.Extent(newWidth, newHeight, Gravity.Center);

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@sefakpsz
Comment options

Answer selected by tomasr78
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants