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.

134 lines (133 loc) 4.71 kB
import { IRect, IMargin, DocController } from '../doc_controller'; import { IPdfBrick } from '../pdf_render/pdf_brick'; /** * Horizontal alignment types in onRenderHeader and onRenderFooter events */ export declare enum HorizontalAlign { NotSet = "notset", Left = "left", Center = "center", Right = "right" } /** * Vertical alignment types in onRenderHeader and onRenderFooter events */ export declare enum VerticalAlign { NotSet = "notset", Top = "top", Middle = "middle", Bottom = "bottom" } export interface IDrawRectOptions { /** * Horizontal alignment within the rectangle that limits the drawing area. * * Possible values: * * - `"center"` (default) * - `"left"` * - `"right"` */ horizontalAlign?: HorizontalAlign; /** * Vertical alignment within the rectangle that limits the drawing area. * * Possible values: * * - `"middle"` (default) * - `"top"` * - `"bottom"` */ verticalAlign?: VerticalAlign; /** * The distance between the content and the borders of the rectangle. This property applies only if the content is aligned to the left/right or top/bottom. */ margins?: IMargin; /** * An object with coordinates of the rectangle. */ rect?: IRect; } /** * An object that configures rendering a piece of text. */ export interface IDrawTextOptions extends IDrawRectOptions { /** * A text string to be drawn. */ text: string; /** * Font size in points. * * Default value: 14 */ fontSize?: number; /** * Enable this property to render the text string bold. * * Default value: `false` */ isBold?: boolean; } /** * An object that configures rendering an image. */ export interface IDrawImageOptions extends IDrawRectOptions { /** * An image width in pixels. Defaults to the [rectangle width](https://surveyjs.io/pdf-generator/documentation/api-reference/idrawimageoptions#rect). */ width?: number; /** * An image height in pixels. Defaults to the [rectangle height](https://surveyjs.io/pdf-generator/documentation/api-reference/idrawimageoptions#rect). */ height?: number; /** * 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; } /** * An object that describes a drawing area and enables you to draw an image or a piece of text within the area. You can access this object within functions that handle `SurveyPDF`'s [`onRenderHeader`](https://surveyjs.io/pdf-generator/documentation/api-reference/surveypdf#onRenderHeader) and [`onRenderFooter`](https://surveyjs.io/pdf-generator/documentation/api-reference/surveypdf#onRenderFooter) events. * * [View Demo](https://surveyjs.io/pdf-generator/examples/customize-header-and-footer-of-pdf-form/ (linkStyle)) */ export declare class DrawCanvas { packs: IPdfBrick[]; controller: DocController; protected _rect: IRect; protected _countPages: number; protected _pageNumber: number; constructor(packs: IPdfBrick[], controller: DocController, _rect: IRect, _countPages: number, _pageNumber: number); /** * A total number of pages in the document. */ get pageCount(): number; get countPages(): number; /** * The number of the page that contains the drawing area. Enumeration starts with 1. */ get pageNumber(): number; /** * An object with coordinates of a rectangle that limits the drawing area. This object contain the following fields: `xLeft`, `xRight`, `yTop`, `yBot`. */ get rect(): IRect; private alignRect; /** * Draws a piece of text within the drawing area. * @param textOptions An [`IDrawTextOptions`](https://surveyjs.io/pdf-generator/documentation/api-reference/idrawtextoptions) object that configures the drawing. */ drawText(textOptions: IDrawTextOptions): void; /** * Draws an image within the drawing area. * @param imageOptions An [`IDrawImageOptions`](https://surveyjs.io/pdf-generator/documentation/api-reference/idrawimageoptions) object that configures drawing. */ drawImage(imageOptions: IDrawImageOptions): Promise<void>; }