@ceereals/vue-pdf
Version:
Vue PDF - Create PDF documents using Vue components
917 lines (812 loc) • 26.1 kB
TypeScript
import { Component } from 'vue';
import { ComponentOptionsMixin } from 'vue';
import { ComponentProvideOptions } from 'vue';
import { default as default_2 } from '@react-pdf/font';
import { DefineComponent } from 'vue';
import { DefineSetupFnComponent } from 'vue';
import { DocumentNode as DocumentNode_2 } from '@react-pdf/types';
import { LinkNode } from '@react-pdf/layout';
import { MaybeRefOrGetter } from 'vue';
import { Node as Node_2 } from '@react-pdf/types';
import { NoteNode } from '@react-pdf/layout';
import { PublicProps } from 'vue';
import { Readable } from 'node:stream';
import { Ref } from 'vue';
import { Style } from '@react-pdf/types';
import { SuspenseProps } from 'vue';
import { TextInstanceNode } from '@react-pdf/types';
import { TextNode } from '@react-pdf/types';
import { TspanNode } from '@react-pdf/layout';
import { VNode } from 'vue';
declare const __VLS_component: DefineComponent<PDFViewerProps, {
execute: ReturnType<typeof usePdf>["execute"];
[rootSymbol]: ReturnType<typeof usePdf>["root"];
}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<PDFViewerProps> & Readonly<{}>, {
enableProvideBridge: boolean;
showToolbar: boolean;
}, {}, {}, {}, string, ComponentProvideOptions, false, {}, HTMLIFrameElement>;
declare const __VLS_component_2: DefineComponent<PDFDownloadLinkProps, {
blob: Readonly<Ref<Blob | null, Blob | null>>;
isLoading: Readonly<Ref<boolean, boolean>>;
url: Readonly<Ref<string | undefined, string | undefined>>;
}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
click: (event: MouseEvent) => any;
}, string, PublicProps, Readonly<PDFDownloadLinkProps> & Readonly<{
onClick?: ((event: MouseEvent) => any) | undefined;
}>, {
label: string;
fileName: string;
}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
declare const __VLS_component_3: DefineComponent<PDFPrintProps, {
blob: Readonly<Ref<Blob | null, Blob | null>>;
isLoading: Readonly<Ref<boolean, boolean>>;
url: Readonly<Ref<string | undefined, string | undefined>>;
}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
click: (event: MouseEvent) => any;
}, string, PublicProps, Readonly<PDFPrintProps> & Readonly<{
onClick?: ((event: MouseEvent) => any) | undefined;
}>, {
label: string;
}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
declare function __VLS_template(): {
attrs: Partial<{}>;
slots: Readonly<{
default: () => VNode[];
}> & {
default: () => VNode[];
};
refs: {};
rootEl: HTMLIFrameElement;
};
declare function __VLS_template_2(): {
attrs: Partial<{}>;
slots: Readonly<PDFDownloadLinkSlots> & PDFDownloadLinkSlots;
refs: {};
rootEl: any;
};
declare function __VLS_template_3(): {
attrs: Partial<{}>;
slots: Readonly<PDFPrintSlots> & PDFPrintSlots;
refs: {};
rootEl: any;
};
declare type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
declare type __VLS_TemplateResult_2 = ReturnType<typeof __VLS_template_2>;
declare type __VLS_TemplateResult_3 = ReturnType<typeof __VLS_template_3>;
declare type __VLS_WithTemplateSlots<T, S> = T & {
new (): {
$slots: S;
};
};
declare type __VLS_WithTemplateSlots_2<T, S> = T & {
new (): {
$slots: S;
};
};
declare type __VLS_WithTemplateSlots_3<T, S> = T & {
new (): {
$slots: S;
};
};
declare type Bookmark = string | ExpandedBookmark;
export declare const Canvas: DefineSetupFnComponent<CanvasProps, {}, {}, CanvasProps & {}, PublicProps>;
declare interface CanvasProps {
/**
* Defines view styles
*/
style?: Style | Style[];
/**
* Painter function
*/
paint?: (painter?: any, availableWidth?: number, availableHeight?: number) => null;
/**
* Enables debug mode on view bounding box
* @default false
*/
debug?: boolean;
/**
* Renders component in all wrapped pages
* @default false
*/
fixed?: boolean;
/**
* Attach bookmark to element
*/
bookmark?: string | Bookmark;
}
export declare const Circle: DefineSetupFnComponent<CircleProps, {}, {}, CircleProps & {}, PublicProps>;
declare interface CircleProps {
/**
* The x-axis coordinate of the center of the circle.
*/
cx?: string | number;
/**
* The y-axis coordinate of the center of the circle.
*/
cy?: string | number;
/**
* The radius of the circle.
*/
r?: string | number;
}
export declare const ClipPath: DefineSetupFnComponent<ClipPathProps, {}, {}, ClipPathProps & {}, PublicProps>;
declare interface ClipPathProps {
id?: string;
}
export declare const Defs: DefineSetupFnComponent<Record<string, any>, {}, {}, Record<string, any> & {}, PublicProps>;
declare const Document_2: DefineSetupFnComponent<DocumentProps, {}, {}, DocumentProps & {}, PublicProps>;
export { Document_2 as Document }
declare interface DocumentNode extends Omit<DocumentNode_2, 'props' | 'children'> {
uid: string;
props?: DocumentNode_2['props'] & {
pdfVersion: string;
language: string;
};
children?: PDFNode[];
}
declare interface DocumentProps {
/**
* Sets title info on the document's metadata
*/
title?: string;
/**
* Sets author info on the document's metadata
*/
author?: string;
/**
* Sets subject info on the document's metadata
*/
subject?: string;
/**
* Sets keywords associated info on the document's metadata
*/
keywords?: string;
/**
* Sets creator info on the document's metadata
* @default 'vue-pdf'
*/
creator?: string;
/**
* Sets producer info on the document's metadata
* @default 'vue-pdf'
*/
producer?: string;
/**
* Sets PDF version for generated document
* @default '1.3'
*/
pdfVersion?: string;
/**
* Sets PDF default language
*/
language?: string;
/**
* Specifying how the document should be displayed when opened
* @default 'useNone'
*/
pageMode?: PageMode;
/**
* This controls how (some) PDF viewers choose to show pages
* @default 'singlePage'
*/
pageLayout?: PageLayout;
}
export declare const Ellipse: DefineSetupFnComponent<EllipseProps, {}, {}, EllipseProps & {}, PublicProps>;
declare interface EllipseProps {
/**
* The x position of the ellipse.
*/
cx?: string | number;
/**
* The y position of the ellipse.
*/
cy?: string | number;
/**
* The radius of the ellipse on the x axis.
*/
rx?: string | number;
/**
* The radius of the ellipse on the y axis.
*/
ry?: string | number;
}
declare interface ExpandedBookmark {
title: string;
top?: number;
left?: number;
zoom?: number;
fit?: true | false;
expanded?: true | false;
}
export declare const fontStore: default_2;
export declare const G: DefineSetupFnComponent<GProps, {}, {}, GProps & {}, PublicProps>;
declare interface GProps extends PresentationAttributes {
}
declare type HTTPMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
declare const Image_2: DefineSetupFnComponent<ImageProps, {}, {}, ImageProps & {}, PublicProps>;
export { Image_2 as Image }
declare interface ImageProps {
/**
* Source of the image.
* todo: add link
*/
src?: Source;
/**
* Alias of src.
* todo: add @see link
*/
source?: Source;
/**
* Defines view styles
*/
style?: Style | Style[];
/**
* Enables debug mode on view bounding box
* @default false
*/
debug?: boolean;
/**
* Renders component in all wrapped pages
* @default false
*/
fixed?: boolean;
/**
* Enables image caching between consecutive renders
* @default true
*/
cache?: boolean;
/**
* Attach bookmark to element
*/
bookmark?: string | Bookmark;
}
export declare const Line: DefineSetupFnComponent<LineProps, {}, {}, LineProps & {}, PublicProps>;
export declare const LinearGradient: DefineSetupFnComponent<LinearGradientProps, {}, {}, LinearGradientProps & {}, PublicProps>;
declare interface LinearGradientProps {
/**
* Defines the x coordinate of the starting point of the vector gradient.
*/
x1?: string | number;
/**
* Defines the x coordinate of the ending point of the vector gradient.
*/
x2?: string | number;
/**
* Defines the y coordinate of the starting point of the vector gradient.
*/
y1?: string | number;
/**
* Defines the y coordinate of the ending point of the vector gradient.
*/
y2?: string | number;
xlinkHref?: string;
gradientTransform?: string;
gradientUnits?: 'userSpaceOnUse' | 'objectBoundingBox';
}
declare interface LineProps {
/**
* Defines the x-axis coordinate of the line starting point.
*/
x1?: string | number;
/**
* Defines the x-axis coordinate of the line ending point.
*/
x2?: string | number;
/**
* Defines the y-axis coordinate of the line starting point.
*/
y1?: string | number;
/**
* Defines the y-axis coordinate of the line ending point.
*/
y2?: string | number;
}
export declare const Link: DefineSetupFnComponent<LinkProps, {}, {}, LinkProps & {}, PublicProps>;
declare interface LinkProps {
/**
* Valid URL or destination ID. ID must be prefixed with `#`
*/
src?: string;
/**
* Enable/disable page wrapping for element
* @default true
*/
wrap?: boolean;
/**
* Defines view styles
*/
style?: Style | Style[];
/**
* Enables debug mode on view bounding box
* @default false
*/
debug?: boolean;
/**
* Renders component in all wrapped pages
* @default false
*/
fixed?: boolean;
/**
* Attach bookmark to element
*/
bookmark?: string | Bookmark;
}
export declare const Note: DefineSetupFnComponent<NoteProps, {}, {}, NoteProps & {}, PublicProps>;
declare interface NoteProps {
/**
* Defines view styles
*/
style?: Style | Style[];
/**
* Renders component in all wrapped pages
* @default false
*/
fixed?: boolean;
}
export declare const Page: DefineSetupFnComponent<PageProps, {}, {}, PageProps & {}, PublicProps>;
declare type PageLayout = 'singlePage' | 'oneColumn' | 'twoColumnLeft' | 'twoColumnRight' | 'twoPageLeft' | 'twoPageRight';
declare type PageMode = 'useNone' | 'useOutlines' | 'useThumbs' | 'fullScreen' | 'useOC' | 'useAttachments';
declare interface PageProps {
/**
* Defines page size. If String, must be one of the available page sizes. Height is optional, if omitted it will behave as "auto"
* @default 'A4'
*/
size?: string | string[] | number | object;
/**
* Defines page orientation. Valid values: "portrait" or "landscape"
* @default 'portrait'
*/
orientation?: 'portrait' | 'landscape';
/**
* Enables page wrapping for this page
* @default true
*/
wrap?: boolean;
/**
* Defines page styles
*/
style?: Style | Style[];
/**
* Enables debug mode on page bounding box
* @default false
*/
debug?: boolean;
/**
* Enables setting a custom DPI for page contents
* @default 72
*/
dpi?: number;
/**
* Destination ID to be linked to
*/
id?: string;
/**
* Attach bookmark to element
*/
bookmark?: string | Bookmark;
}
export declare const Path: DefineSetupFnComponent<PathProps, {}, {}, PathProps & {}, PublicProps>;
declare interface PathProps extends PresentationAttributes {
style?: PresentationAttributes;
d?: string;
}
export declare const PDFDownloadLink: __VLS_WithTemplateSlots_2<typeof __VLS_component_2, __VLS_TemplateResult_2["slots"]>;
export declare interface PDFDownloadLinkEvents {
click: [event: MouseEvent];
}
export declare interface PDFDownloadLinkProps {
/**
* The file name of the pdf file
* @default 'document.pdf'
*/
fileName: string;
/**
* The label of the download link
* @default 'Download'
*/
label?: string;
}
export declare interface PDFDownloadLinkSlots {
/**
* @returns VNode[] Must return an array with a single `<Document>` component's VNode, if more than one is provided, only the first one will be used
*/
default: () => VNode[];
label?: (params: {
blob: Blob | null;
}) => VNode[] | string;
}
declare type PDFNode = (Node_2 | TextNode | LinkNode | TspanNode | NoteNode | TextInstanceNode) & {
parentNode: PDFNode | null;
uid: string;
};
export declare const PDFPrint: __VLS_WithTemplateSlots_3<typeof __VLS_component_3, __VLS_TemplateResult_3["slots"]>;
export declare interface PDFPrintEvents {
click: [event: MouseEvent];
}
export declare interface PDFPrintProps {
/**
* The label of the print link
* @default 'Print'
*/
label?: string;
}
export declare interface PDFPrintSlots {
/**
* @returns VNode[] Must return an array with a single `<Document>` component's VNode, if more than one is provided, only the first one will be used
*/
default: () => VNode[];
label?: (params: {
blob: Blob | null;
}) => VNode[] | string;
}
declare const pdfRender: (root: PdfRoot, { compress, signal }?: Partial<{
compress: boolean;
signal?: AbortSignal;
}>) => Promise<Readable>;
declare interface PdfRoot {
type: 'ROOT';
document: DocumentNode;
}
export declare const PDFSuspense: DefineComponent<SuspenseProps, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<SuspenseProps> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
export declare const PDFViewer: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
export declare interface PDFViewerProps {
/**
* Toggle the visibility of the toolbar
* @default true
* @deprecated Use `queryParams` instead to pass custom parameters to the PDF URL
*/
showToolbar?: boolean;
/**
* Enable the provide bridge to provide
* App provides to the Document context
* @default true
*/
enableProvideBridge?: boolean;
/**
* Additional query parameters to append to the PDF URL
* @default undefined
*/
queryParams?: Record<string, string | number | boolean>;
}
export declare const Polygon: DefineSetupFnComponent<PolygonProps, {}, {}, PolygonProps & {}, PublicProps>;
declare interface PolygonProps {
/**
* Defines the list of points (pairs of x,y absolute coordinates) required to draw the polygon.
*/
points?: string;
}
export declare const Polyline: DefineSetupFnComponent<PolylineProps, {}, {}, PolylineProps & {}, PublicProps>;
declare interface PolylineProps {
/**
* Defines the list of points (pairs of x,y absolute coordinates) required to draw the polyline.
*/
points?: string;
}
declare interface PresentationAttributes {
/**
* Provides a potential indirect value for the fill or stroke attributes.
*/
color?: string;
/**
* Defines the baseline used to align the box’s text and inline-level contents.
* @default auto
*/
dominantBaseline?: 'auto' | 'middle' | 'central' | 'hanging' | 'mathematical' | 'text-after-edge' | 'text-before-edge';
/**
* It defines the color of the inside of the graphical element it applies to.
*/
fill?: string;
/**
* It specifies the opacity of the color or the content the current object is filled with.
* @default 1
*/
fillOpacity?: string | number;
/**
* It indicates how to determine what side of a path is inside a shape.
* @default nonzero
*/
fillRule?: 'nonzero' | 'evenodd';
/**
* It specifies the transparency of an object or a group of objects.
* @default 1
*/
opacity?: string | number;
/**
* Defines the color used to paint the outline of the shape.
*/
stroke?: string;
/**
* Defines the width of the stroke to be applied to the shape.
* @default 1
*/
strokeWidth?: string | number;
/**
* Defines the opacity of the stroke of a shape.
* @default 1
*/
strokeOpacity?: string | number;
/**
* Defines the shape to be used at the end of open subpaths when they are stroked.
* @default butt
*/
strokeLinecap?: 'butt' | 'round' | 'square';
/**
* Defines the shape to be used at the corners of paths when they are stroked.
* @default miter
*/
strokeLinejoin?: 'butt' | 'round' | 'square' | 'miter' | 'bevel';
/**
* Defines the pattern of dashes and gaps used to paint the outline of the shape.
*/
strokeDasharray?: string;
/**
* Defines a list of transform definitions that are applied to an element and its children.
*/
transform?: string;
/**
* Defines the horizontal alignment of a string of text.
*/
textAnchor?: 'start' | 'middle' | 'end';
/**
* Lets you control the visibility of graphical elements.
* @default visible
*/
visibility?: 'visible' | 'hidden' | 'collapse';
}
export declare const RadialGradient: DefineSetupFnComponent<RadialGradientProps, {}, {}, RadialGradientProps & {}, PublicProps>;
declare interface RadialGradientProps {
/**
* Defines the x coordinate of the end circle of the radial gradient.
*/
cx?: string | number;
/**
* Defines the y coordinate of the end circle of the radial gradient.
*/
cy?: string | number;
/**
* Defines the radius of the start circle of the radial gradient.
*/
fr?: string | number;
/**
* Defines the x coordinate of the start circle of the radial gradient.
*/
fx?: string | number;
/**
* Defines the y coordinate of the start circle of the radial gradient.
*/
fy?: string | number;
xlinkHref?: string;
gradientTransform?: string;
gradientUnits?: 'userSpaceOnUse' | 'objectBoundingBox';
}
export declare const Rect: DefineSetupFnComponent<RectProps, {}, {}, RectProps & {}, PublicProps>;
declare interface RectProps {
/**
* The x coordinate of the rect.
*/
x?: string | number;
/**
* The y coordinate of the rect.
*/
y?: string | number;
/**
* The width of the rect.
*/
width?: string | number;
/**
* The height of the rect.
*/
height?: string | number;
/**
* The horizontal corner radius of the rect.
*/
rx?: string | number;
/**
* The vertical corner radius of the rect.
*/
ry?: string | number;
}
export declare const renderToBuffer: renderToBufferType;
declare type renderToBufferType = (document: Component | VNode, options?: Parameters<typeof pdfRender>[1]) => Promise<Buffer<ArrayBuffer>>;
export declare const renderToFile: renderToFileType;
declare type renderToFileType = (document: Component | VNode, filePath: string, options?: Parameters<typeof pdfRender>[1]) => Promise<Readable>;
export declare const renderToStream: renderToStreamType;
declare type renderToStreamType = (document: Component | VNode, options?: Parameters<typeof pdfRender>[1]) => Promise<Readable>;
declare const rootSymbol: unique symbol;
declare type Source = SourceURL | SourceBuffer_2 | SourceBlob | SourceDataBuffer | SourceURLObject | undefined;
declare type SourceAsync = Promise<Source>;
declare type SourceAsyncFactory = () => Promise<Source>;
declare type SourceBlob = Blob;
declare type SourceBuffer_2 = Buffer;
declare type SourceDataBuffer = {
data: Buffer;
format: 'png' | 'jpg';
};
declare type SourceFactory = () => Source;
export declare type SourceObject = Source | SourceFactory | SourceAsync | SourceAsyncFactory;
declare type SourceURL = string;
declare type SourceURLObject = {
uri: string;
method?: HTTPMethod;
body?: any;
headers?: any;
credentials?: 'omit' | 'same-origin' | 'include';
};
export declare const Stop: DefineSetupFnComponent<StopProps, {}, {}, StopProps & {}, PublicProps>;
declare interface StopProps {
/**
* Defines where the gradient stop is placed along the gradient vector.
*/
offset?: string | number;
/**
* Defines the color of the gradient stop.
*/
stopColor?: string;
/**
* Defines the opacity of the gradient stop.
* @default 1
*/
stopOpacity?: string | number;
}
export { Style }
export declare const Svg: DefineSetupFnComponent<SvgProps, {}, {}, SvgProps & {}, PublicProps>;
declare interface SvgProps {
/**
* The displayed width of the rectangular viewport
*/
width?: string | number;
/**
* The displayed height of the rectangular viewport
*/
height?: string | number;
/**
* The SVG viewport coordinates for the current SVG fragment
*/
viewBox?: string;
/**
* How the svg fragment must be deformed if it is displayed with a different aspect ratio
*/
preserveAspectRatio?: string;
/**
* Defines SVG styles
*/
style?: Style | Style[];
}
export declare const SvgText: DefineSetupFnComponent<SvgTextProps, {}, {}, SvgTextProps & {}, PublicProps>;
declare interface SvgTextProps {
/**
* The x coordinate of the starting point of the text baseline.
*/
x?: string | number;
/**
* The y coordinate of the starting point of the text baseline.
*/
y?: string | number;
}
declare const Text_2: DefineSetupFnComponent<TextProps, {}, {}, TextProps & {}, PublicProps>;
export { Text_2 as Text }
declare interface TextProps {
/**
* Enables/disables page wrapping for element
* @default true
*/
wrap?: boolean;
/**
* Defines view styles
*/
style?: Style | Style[];
/**
* Enables debug mode on view bounding box
* @default false
*/
debug?: boolean;
/**
* Renders component in all wrapped pages
* @default false
*/
fixed?: boolean;
/**
* Specify hyphenation callback at a text level
*/
hyphenationCallback?: (word: string) => string[];
/**
* Destination ID to be linked to
*/
id?: string;
/**
* Attach bookmark to element
*/
bookmark?: string | Bookmark;
/**
*
* Render dynamic text based on the context the element is rendered
*/
render?: (args: {
pageNumber: number;
totalPages: number;
subPageNumber: string;
subPageTotalPages: number;
}) => string;
}
export declare const Tspan: DefineSetupFnComponent<TspanProps, {}, {}, TspanProps & {}, PublicProps>;
declare interface TspanProps {
/**
* The x coordinate of the starting point of the text baseline.
*/
x?: string | number;
/**
* The y coordinate of the starting point of the text baseline.
*/
y?: string | number;
}
export declare function usePdf(doc: MaybeRefOrGetter<Component | VNode>): UsePdfReturn & PromiseLike<UsePdfReturn>;
export declare function usePdf(doc: MaybeRefOrGetter<Component | VNode>, options: UsePdfConfig): UsePdfReturn & PromiseLike<UsePdfReturn>;
declare interface UsePdfConfig {
/**
* If true, the pdf will be rendered immediately and updated
* @default true
*/
reactive?: boolean;
/**
* if true, the Pdf components can inject the application provided values
*/
enableProvideBridge?: boolean;
/**
*
* Will run immediately after the pdf is rendered
*/
onError?: (error: Error) => Promise<Error | undefined> | Error | undefined;
}
declare interface UsePdfReturn {
isLoading: Readonly<Ref<boolean>>;
isFinished: Readonly<Ref<boolean>>;
blob: Readonly<Ref<Blob | null>>;
url: Readonly<Ref<string | undefined>>;
error: Readonly<Ref<Error | null>>;
root: Readonly<Ref<PdfRoot>>;
/**
* Manually call the render function
* @param throwOnFailed false
*/
execute: (throwOnFailed?: boolean) => Promise<void>;
/**
* Unmount the current pdf
*/
unmount: () => void;
}
export declare const View: DefineSetupFnComponent<ViewProps, {}, {}, ViewProps & {}, PublicProps>;
declare interface ViewProps {
/**
* Enable/disable page wrapping for element
*/
wrap?: boolean;
/**
* Defines view styles
*/
style?: Style | Style[];
/**
* Enables debug mode on view bounding box
*/
debug?: boolean;
/**
* Render component in all wrapped pages
*/
fixed?: boolean;
/**
* Destination ID to be linked to
*/
id?: string;
/**
* Attach bookmark to element
*/
bookmark?: string | Bookmark;
/**
*
* Render dynamic text based on the context the element is rendered
*/
render?: (args: {
pageNumber: number;
subPageNumber: string;
}) => string;
}
export { }