QuestPDF / QuestPDF

QuestPDF is a modern open-source .NET library for PDF document generation. Offering comprehensive layout engine powered by concise and discoverable C# Fluent API. Easily generate PDF reports, invoices, exports, etc.
https://www.questpdf.com
Other
12k stars 629 forks source link

The Image element should provide better control over its size #4

Closed MarcinZiabek closed 3 years ago

MarcinZiabek commented 3 years ago

Is your feature request related to a problem? Please describe. I want to decide which scaling rule is used in order to display the Image element. Depending on the scenario, the image element should preserve its aspect ratio and fit available width/height/space. There are also cases when the image should be scaled unproportionally.

Currently, the Image element changes its size according to provided rules: 1) It tries to fit the available space. 2) It always prevents its aspect ratio.

Describe the solution you'd like Provide a flag to decide how the image is going to be scaled: 1) To fit the available width. 2) To fit the available height. 3) To fit the available space (both width and height = safest). 4) To cover provided area without preserving its aspect ratio (also safe but usually not desired).

Additional context Important: this change needs to be properly documented. There are cases when a selected option may lead to infinite layouts. For example:

// Infinite layout example:

.Width(400) // constrained size: width and height
.Height(200)
.Image(data, ImageScaling.FitWidth); // image width aspect ratio 4x3

// Example 2:
.Row(row => 
{
    row.ConstantColumn(200)
       .Height(300)
       .Image(data, ImageScaling.FitHeight); // image width aspect ratio 4x3
})
MarcinZiabek commented 3 years ago

This functionality is ready and planned to be released with QuestPDF 2021.04

sokheangkhun commented 1 year ago

How can I achieve image fit to contain. For example, I set container height to 100 and if image width bigger than height it scale height to fit and crop width or I set container width to 100 and image's height bigger than its width. The Image fit the width and crop height.