Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF Generator for .NET (v7.x)  /  Image sizing to fill an area

Forum Thread - Image sizing to fill an area

 Feb 07 2019 6:34 AM
Is there any way to achieve the equivalent of CSS "object-fit: cover" for images?

I am adding images to a page (1 to 6, which the user decides). The layout is decided depending on the number of images. For example, if the user chose 4 images, each image occupies one quarter of a page (either portrait or landscape, again decided by the user). The images should fill their respective "bounding boxes" without getting distorted. The SetSize method of an image distorts the image and SetBounds method doesn't necessarily fill the box (it acts like object-fit: contain).

Is there any way to make the image fill a given area without getting distorted? I understand that this may crop the image, but that's OK.

I also wrote code to resize the image to fill an area by maintaining aspect ratio, but I don't see any option to restrict them to the area. I also tried adding the image to properly sized and placed ContentArea, but the image overflows the area.

Any help is highly appreciated.
 Feb 07 2019 9:58 AM
Posted by a ceTe Software moderator
The DynamicPDF API does not resample  images and adds them to the PDF as is. If you change the dimensions then it may appear distorted since the image resolution (DPI)  will get changed accordingly. If you want to fill some specific area in the PDF with image then setting dimensions is the suggested method. You can refer to the documentation on image resolution here.

If you are wanting to clip the image, so only a portion of the original image is shown, you will need to process the image yourself using GDI+ or some other image processing API.
ceTe Software Support Team.

All times are US Eastern Standard time. The time now is 12:57 PM.