Skip to content

small resolution image to pdf can't convert to A4 size #1565

Answered by dlemstra
liugt34 asked this question in Help
Discussion options

You must be logged in to vote

You should set the density after you read the image. Setting it in the settings does nothing when you read those input files. Your code can be simplified to this:

using var images = new MagickImageCollection();

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

var names = new string[] { "d20220118150203.png", "map.png" };

foreach (var name in names)
{
    var image = new MagickImage(SRC + name);
    image.Density = new Density(72);

    if (image.Width > size.Width || image.Height > size.Height)
    {
        image.Resize(size);
    }

    //图片居中显示
    image.Extent(size, Gravity.Center);

    images.Add(image);
}

// Create pdf file with two pages
images.Write(DEST + "Merge.pdf");

Replies: 1 comment 1 reply

Comment options

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

Answer selected by liugt34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1562 on February 25, 2024 16:55.