UNPKG

survey-pdf

Version:

survey.pdf.js is a SurveyJS PDF Library. It is a easy way to export SurveyJS surveys to PDF. It uses JSON for survey metadata.

299 lines (298 loc) 10.7 kB
import { IHTMLRenderType } from './flat_layout/flat_html'; import { LocalizableString } from 'survey-core'; import './jspdf_plugins/acroform.js'; import './jspdf_plugins/from_html.js'; export interface IPoint { /** * An X-coordinate for the left element edge. */ xLeft: number; /** * A Y-coordinate for the top element edge. */ yTop: number; } /** * An interface that describes a rectangle. */ export interface IRect extends IPoint { /** * An X-coordinate for the right element edge. */ xRight: number; /** * A Y-coordinate for the bottom element edge. */ yBot: number; } export interface ISize { width: number; height: number; } export interface IMarginLR { /** * A left margin. */ left?: number; /** * A right margin. */ right?: number; } /** * An interface that describes margins. */ export interface IMargin extends IMarginLR { /** * A top margin. */ top?: number; /** * A bottom margin. */ bot?: number; } /** * PDF document configuration. Pass it as the second argument to the `SurveyPDF` constructor: * * ```js * const surveyPdf = new SurveyPDF.SurveyPDF(surveyJson, pdfDocOptions); * * // In modular applications: * import { SurveyPDF } from "survey-pdf"; * const surveyPdf = new SurveyPDF(surveyJson, pdfDocOptions); * ``` */ export interface IDocOptions { /** * Page orientation. * * Possible values: * * - `"p"` (default) - Portrait orientation. * - `"l"` - Landscape orientation. * * @see format */ orientation?: 'p' | 'l'; /** * Page format. * * Possible values: * * - `"a0"` - `"a10"` (`"a4"` is default) * - `"b0"` - `"b10"` * - `"c0"` - `"c10"` * - `"dl"` * - `"letter"` * - `"government-letter"` * - `"legal"` * - `"junior-legal"` * - `"ledger"` * - `"tabloid"` * - `"credit-card"` * - Array<number> - custom page size in millimeters, for example, `[210, 297]`. * * @see orientation */ format?: string | number[]; /** * Font size in points. * * Default value: 14 * * @see fontName */ fontSize?: number; /** * Font name. * * Possible values: * * - `"Helvetica"` (default) * - `"Courier"` * - `"Times"` * - `"Symbol"` * - `"ZapfDingbats"` * - [Custom font name](https://surveyjs.io/Documentation/Pdf-Export?id=Customization-ChangeFonts#use-custom-font) * * [View Demo](https://surveyjs.io/pdf-generator/examples/change-font-in-pdf-form/ (linkStyle)) * @see fontSize */ fontName?: string; base64Normal?: string; base64Bold?: string; /** * Specifies whether to apply a custom font to [HTML questions](https://surveyjs.io/form-library/examples/questiontype-html/). * * Default value: `false` * * [View Demo](https://surveyjs.io/pdf-generator/examples/change-font-in-pdf-form/ (linkStyle)) * @see htmlRenderAs */ useCustomFontInHtml?: boolean; /** * Page margins. Set this property to an object with the following fields: `top`, `bot`, `left`, `right`. */ margins?: IMargin; /** * Specifies how to render [HTML questions](https://surveyjs.io/Documentation/Library?id=questionhtmlmodel) into PDF. * * Possible values: * * - `"standard"` - Render HTML questions as selectable text. * - `"image"` - Render HTML questions as images. * - `"auto"` (default) - Select between the `"standard"` and `"image"` modes automatically based on the HTML content. * * You can override this property for an individual HTML question. Set the question's `renderAs` property to `"standard"` or `"image"` in the survey JSON schema. * @see useCustomFontInHtml */ htmlRenderAs?: IHTMLRenderType; /** * Specifies how to render [Matrix](https://surveyjs.io/Documentation/Library?id=questionmatrixmodel), [Matrix Dropdown](https://surveyjs.io/Documentation/Library?id=questionmatrixdropdownmodel), and [Matrix Dynamic](https://surveyjs.io/Documentation/Library?id=questionmatrixdynamicmodel) questions into PDF. * * Possible values: * * - `"list"` - Render matrix-like questions as lists. * - `"auto"` (default) - Render matrix-like questions as tables if they fit into the available space. Otherwise, render the questions as lists. * * You can override this property for an individual matrix-like question. Set the question's `renderAs` property to `"list"` in the survey JSON schema. */ matrixRenderAs?: 'auto' | 'list'; useLegacyBooleanRendering?: boolean; /** * Specifies how to render read-only questions. * * Possible values: * * - `"text"` - Render read-only questions as plain text and custom primitives. * - `"acroform"` - Use Adobe AcroForms to render questions that support them as interactive form elements switched to their native read-only state. Other questions are rendered in `"text"` mode. * - `"auto"` (default) - Prefer the `"text"` mode but use `"acroform"` for [File Upload](https://surveyjs.io/form-library/documentation/api-reference/file-model) questions and links. */ readonlyRenderAs?: 'auto' | 'text' | 'acroform'; textFieldRenderAs?: 'singleLine' | 'multiLine'; /** * Specifies whether to compress the PDF document. Compressed documents do not support [custom fonts](https://surveyjs.io/Documentation/Pdf-Export?id=Customization-ChangeFonts#use-custom-font). * * Default value: `false` */ compress?: boolean; /** * 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. */ applyImageFit?: boolean; /** * Specifies whether the PDF document contains text in right-to-left languages. * * Default value: `false` */ isRTL?: boolean; /** * Specifies whether to include only selected choices when PDF Generator renders a [Multi-Select Dropdown (Tag Box)](https://surveyjs.io/form-library/examples/how-to-create-multiselect-tag-box/) question. * * Default value: `false` (include all choices) */ tagboxSelectedChoicesOnly?: boolean; } export declare class DocOptions implements IDocOptions { static readonly MM_TO_PT: number; static readonly FONT_SIZE = 14; protected _orientation: 'l' | 'p'; protected _format: string | number[]; protected _fontSize: number; protected _fontName: string; static SEGOE_NORMAL: string; static SEGOE_BOLD: string; protected _base64Normal: string; protected _base64Bold: string; protected _useCustomFontInHtml: boolean; protected _margins: IMargin; protected _htmlRenderAs: IHTMLRenderType; protected _matrixRenderAs: 'auto' | 'list'; protected _readonlyRenderAs: 'auto' | 'text' | 'acroform'; protected _compress: boolean; protected _applyImageFit: boolean; protected _useLegacyBooleanRendering: boolean; protected _isRTL: boolean; protected _tagboxSelectedChoicesOnly: boolean; constructor(options: IDocOptions); get leftTopPoint(): IPoint; get fontSize(): number; get fontName(): string; get base64Normal(): string; get base64Bold(): string; get useCustomFontInHtml(): boolean; get margins(): IMargin; get format(): string | number[]; get orientation(): 'l' | 'p'; get htmlRenderAs(): IHTMLRenderType; get matrixRenderAs(): 'auto' | 'list'; get readonlyRenderAs(): 'auto' | 'text' | 'acroform'; get compress(): boolean; get applyImageFit(): boolean; get useLegacyBooleanRendering(): boolean; get isRTL(): boolean; get tagboxSelectedChoicesOnly(): boolean; } /** * The `DocController` object includes an API that allows you to configure the resulting PDF document. You can access this object within functions that handle the `SurveyPDF`'s [`onRender...`](https://surveyjs.io/pdf-generator/documentation/api-reference/surveypdf#onRenderFooter) events. * * [View Demo](https://surveyjs.io/pdf-generator/examples/how-to-use-adorners-in-pdf-forms/ (linkStyle)) */ export declare class DocController extends DocOptions { private _doc; private _helperDoc; private _fontStyle; private marginsStack; constructor(options?: IDocOptions); static customFonts: { [name: string]: { normal: string; bold: string; italic: string; bolditalic: string; }; }; static addFont(fontName: string, base64: string, fontStyle: 'normal' | 'bold' | 'italic' | 'bolditalic'): void; get doc(): any; get helperDoc(): any; get fontName(): string; set fontName(fontName: string); get fontSize(): number; set fontSize(fontSize: number); get fontStyle(): string; set fontStyle(fontStyle: string); measureText(text?: string | LocalizableString | number, fontStyle?: string, fontSize?: number): ISize; /** * The width of one character in pixels. */ get unitWidth(): number; /** * The heigth of one character in pixels. */ get unitHeight(): number; pushMargins(left?: number, right?: number): void; popMargins(): void; /** * The width of a PDF page in pixels. */ get paperWidth(): number; /** * The height of a PDF page in pixels. */ get paperHeight(): number; getNumberOfPages(): number; addPage(): void; getCurrentPageIndex(): number; setPage(index: number): void; }