GemBox Support Forum

Image too big for single word page


I’m trying to add a png image to a word page. As of now the image is cut off at the bottom. Since custom sized pages arent an option, I’d like to split the image onto two pages and am clueless how I would do that.

Thanks in advance!


GemBox.Document cannot split the image, for that, you would need to use some image processing code.

But, you could resize the image to fit the page.
For example, like this:

var document = new DocumentModel();

var section = new Section(document);

var picture = new Picture(document, "image.png");
section.Blocks.Add(new Paragraph(document, picture));

var pictureSize = picture.Layout.Size;
var pageSetup = section.PageSetup;
var pageMargins = pageSetup.PageMargins;

var ratioX = (pageSetup.PageWidth - pageMargins.Left - pageMargins.Right) / pictureSize.Width;
var ratioY = (pageSetup.PageHeight - pageMargins.Top - pageMargins.Bottom) / pictureSize.Height;
var ratio = Math.Min(ratioX, ratioY);

if (ratio < 1)
    picture.Layout.Size = new Size(pictureSize.Width * ratio, pictureSize.Height * ratio);

I hope this helps.