UNPKG

survey-pdf

Version:

A UI component that uses SurveyJS form JSON schemas to render forms as PDF documents. It populates PDF fields with data collected using SurveyJS Form Library and lets you export your SurveyJS forms as editable or pre-filled PDFs.

83 lines (79 loc) 4.9 kB
/*! * surveyjs - SurveyJS PDF library v2.5.21 * Copyright (c) 2015-2026 Devsoft Baltic OÜ - http://surveyjs.io/ * License: MIT (http://www.opensource.org/licenses/mit-license.php) */ import { B as BaseImageUtils, _ as __awaiter, r as registerImageUtils } from './pdf-shared.mjs'; export { a as BooleanItemBrick, C as CheckItemBrick, b as CheckboxItemBrick, c as CompositeBrick, d as CustomBrick, D as DocController, e as DocOptions, f as DrawCanvas, g as DropdownBrick, E as EmptyBrick, h as EventHandler, F as FlatBoolean, i as FlatCheckbox, j as FlatComment, k as FlatCustomModel, l as FlatDropdown, m as FlatExpression, n as FlatFile, o as FlatHTML, p as FlatImage, q as FlatImagePicker, s as FlatMatrix, t as FlatMatrixDynamic, u as FlatMatrixMultiple, v as FlatMultipleText, w as FlatPanelDynamic, x as FlatQuestion, y as FlatQuestionDefault, z as FlatRadiogroup, A as FlatRanking, G as FlatRating, H as FlatRepository, I as FlatSelectBase, J as FlatSignaturePad, K as FlatSlider, L as FlatSurvey, M as FlatTextbox, N as HTMLBrick, O as HorizontalAlign, P as ImageBrick, Q as LinkBrick, R as PagePacker, S as PdfBrick, T as RadioItemBrick, U as RankingItemBrick, V as RowlineBrick, W as SurveyHelper, X as SurveyPDF, Y as TextBoldBrick, Z as TextBrick, $ as TextFieldBrick, a0 as TitlePanelBrick, a1 as VerticalAlign } from './pdf-shared.mjs'; import 'survey-core'; import 'jspdf'; class ImageUtils extends BaseImageUtils { _getImageInfo(url) { return __awaiter(this, void 0, void 0, function* () { const pxToPt = 72.0 / 96.0; const image = new Image(); image.crossOrigin = 'anonymous'; const response = yield new Promise((resolve, reject) => { image.onload = () => { const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); canvas.height = image.naturalHeight; canvas.width = image.naturalWidth; ctx === null || ctx === void 0 ? void 0 : ctx.drawImage(image, 0, 0); const dataUrl = canvas.toDataURL(); resolve({ data: dataUrl, width: image.naturalWidth * pxToPt, height: image.naturalHeight * pxToPt, id: this.getImageId() }); }; image.onerror = () => { reject(); }; image.src = url; }); return response; }); } getCoverCanvasOptions(imageWidth, imageHeight, targetWidth, targetHeight) { const aspectRatio = imageWidth / imageHeight; const targetAspectRatio = targetWidth / targetHeight; let drawWidth, drawHeight; if (targetAspectRatio > aspectRatio) { drawWidth = targetWidth; drawHeight = targetWidth / aspectRatio; } else { drawHeight = targetHeight; drawWidth = targetHeight * aspectRatio; } return { canvasWidth: targetWidth, canvasHeight: targetHeight, imageX: (targetWidth - drawWidth) / 2, imageY: (targetHeight - drawHeight) / 2, imageWidth: drawWidth, imageHeight: drawHeight }; } applyImageFit(imageInfo, imageFit, targetWidth, targetHeight) { const _super = Object.create(null, { applyImageFit: { get: () => super.applyImageFit } }); return __awaiter(this, void 0, void 0, function* () { if (imageFit == 'cover') { try { const image = new Image(); if (!imageInfo.width || !imageInfo.height || !imageInfo.data || !targetWidth || !targetHeight) return imageInfo; image.src = imageInfo.data instanceof Uint8Array ? URL.createObjectURL(new Blob([imageInfo.data])) : imageInfo.data; yield image.decode(); const canvasOptions = this.getCoverCanvasOptions(imageInfo.width, imageInfo.height, targetWidth, targetHeight); const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); canvas.width = canvasOptions.canvasWidth; canvas.height = canvasOptions.canvasHeight; ctx === null || ctx === void 0 ? void 0 : ctx.drawImage(image, canvasOptions.imageX, canvasOptions.imageY, canvasOptions.imageWidth, canvasOptions.imageHeight); return { data: canvas.toDataURL(), width: targetWidth, height: targetHeight }; } catch (_a) { return imageInfo; } } else { return _super.applyImageFit.call(this, imageInfo, imageFit, targetWidth, targetHeight); } }); } } registerImageUtils(new ImageUtils()); //# sourceMappingURL=survey.pdf.mjs.map