diff --git a/src/doc_controller.ts b/src/doc_controller.ts index a6b2964..76e70fc 100644 --- a/src/doc_controller.ts +++ b/src/doc_controller.ts @@ -193,7 +193,15 @@ export interface IDocOptions { compress?: boolean; /** - * Specifies whether to apply the [`imageFit`](https://surveyjs.io/Documentation/Library?id=questionimagemodel#imageFit) property to exported [Image](https://surveyjs.io/Documentation/Library?id=questionimagemodel) questions. + * Specifies whether to apply `imageFit` settings specified in the survey JSON schema to exported images. + * + * Default value: `false` + * + * This property applies the following settings: + * + * - [`imageFit`](https://surveyjs.io/form-library/documentation/api-reference/add-image-to-survey#imageFit) to exported [Image](https://surveyjs.io/form-library/documentation/api-reference/add-image-to-survey) questions + * - [`imageFit`](https://surveyjs.io/form-library/documentation/api-reference/image-picker-question-model#imageFit) to exported [Image Picker](https://surveyjs.io/form-library/documentation/api-reference/image-picker-question-model) questions + * - [`logoFit`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#logoFit) to an exported logo in the survey header * * If you enable the `applyImageFit` property, the quality of images may be lower because they pass through several conversions. If `applyImageFit` is disabled, exported images fill the entire container and do not preserve their aspect ratio, but their quality remains the same because they are exported as is. */ diff --git a/src/event_handler/draw_canvas.ts b/src/event_handler/draw_canvas.ts index f0ba616..d9ea7da 100644 --- a/src/event_handler/draw_canvas.ts +++ b/src/event_handler/draw_canvas.ts @@ -90,6 +90,14 @@ export interface IDrawImageOptions extends IDrawRectOptions { * A string value with a base64-encoded image to be drawn. */ base64: string; + /** + * Specifies how to resize the image to fit it into its container. + * + * Default value: `"contain"` if [`applyImageFit`](https://surveyjs.io/pdf-generator/documentation/api-reference/idocoptions#applyImageFit) is enabled or `undefined` if not. + * + * Refer to the [`object-fit`](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit) CSS property description for information on accepted values. + */ + imageFit?: string; } /** @@ -245,10 +253,12 @@ export class DrawCanvas { height: imageOptions.height }; const imageRect: IRect = this.alignRect(imageOptions, imageSize); + this.controller.pushMargins(0, 0); this.packs.push(await SurveyHelper.createImageFlat( SurveyHelper.createPoint(imageRect, true, true), null, this.controller, { link: imageOptions.base64, width: imageRect.xRight - imageRect.xLeft, - height: imageRect.yBot - imageRect.yTop })); + height: imageRect.yBot - imageRect.yTop, objectFit: imageOptions.imageFit }, !!imageOptions.imageFit || this.controller.applyImageFit)); + this.controller.popMargins(); } } \ No newline at end of file