UNPKG

printmaker

Version:

Generate PDF documents and from JavaScript objects

62 lines (61 loc) 1.82 kB
import { PDFFont } from 'pdf-lib'; import { Box, Pos } from './box.js'; import { Color } from './colors.js'; import { Document } from './document.js'; import { GraphicsObject } from './graphics.js'; import { Page } from './page.js'; import { Block, Paragraph } from './text.js'; import { Obj } from './types.js'; /** * Frames are created during the layout process. They have a position relative to their parent, * a size, and drawable objects to be rendered. * Frames can contain children, e.g. for rows within a paragraph or in a column. */ export declare type Frame = { x: number; y: number; width: number; height: number; type?: string; objects?: DrawableObject[]; children?: Frame[]; }; export declare type DrawableObject = TextObject | AnchorObject | LinkObject | GraphicsObject; export declare type TextObject = { type: 'text'; x: number; y: number; text: string; font: PDFFont; fontSize: number; color?: Color; }; export declare type LinkObject = { type: 'link'; x: number; y: number; width: number; height: number; url: string; }; export declare type AnchorObject = { type: 'anchor'; name: string; x: number; y: number; }; export declare function layoutPages(def: Obj, doc: Document): Page[]; export declare function layoutPageContent(blocks: Block[], box: Box, doc: Document): { frame: { type: string; x: number; y: number; width: number; height: number; children: any[]; }; remainder: any; }; export declare function layoutBlock(block: Block, box: Box, doc: Document): Frame; export declare function layoutParagraph(paragraph: Paragraph, box: Box, doc: Document): Frame; export declare function createAnchorObject(name: string, pos?: Pos): AnchorObject;