ngx-print
Version:
Plug n' Play Angular directive to print your stuff
188 lines (181 loc) • 7.52 kB
TypeScript
import * as _angular_core from '@angular/core';
import * as rxjs from 'rxjs';
import { Subject } from 'rxjs';
declare class PrintOptions {
printSectionId: string;
printTitle: string;
useExistingCss: boolean;
bodyClass: string;
printMethod: 'window' | 'tab' | 'iframe';
previewOnly: boolean;
closeWindow: boolean;
printDelay: number;
constructor(options?: Partial<PrintOptions>);
}
/** For example:
* {
* 'h2': { 'border': 'solid 1px' },
* 'h1': { 'color': 'red', 'border': '1px solid' },
* */
type PrintStyle = Record<string, Record<string, string>>;
/**
* Either a {@link PrintStyle} object, or a raw CSS string (e.g. `'h1 { color: red; }'`)
* to be injected into the print document's <style> tag as-is.
*/
type PrintStyleInput = PrintStyle | string;
declare class PrintBase {
private document;
private nonce;
private _iframeElement;
private _printStyle;
private _styleSheetFile;
protected printComplete: Subject<void>;
/**
* Sets the print styles based on the provided values.
*
* @param values - Either a key-value pairs object representing print styles, or a raw CSS string.
* @protected
*/
protected setPrintStyle(values: PrintStyleInput): void;
/**
* @returns the string that create the stylesheet which will be injected
* later within <style></style> tag.
*/
returnStyleValues(): string;
/**
* @returns string which contains the link tags containing the css which will
* be injected later within <head></head> tag.
*
*/
private returnStyleSheetLinkTags;
/**
* Sets the style sheet file based on the provided CSS list.
*
* @param {string} cssList - CSS file or list of CSS files.
* @protected
*/
protected setStyleSheetFile(cssList: string): void;
private syncFormValues;
/**
* Converts a canvas element to an image and returns its HTML string.
*
* @param {HTMLCanvasElement} canvasElm - The canvas element to convert.
* @returns {HTMLImageElement | null} - HTML Element of the image.
* @private
*/
private canvasToImageHtml;
/**
* Includes canvas contents in the print section via img tags.
*
* @private
* @param source
* @param clone
*/
private updateCanvasToImage;
/**
* Retrieves the HTML content of a specified printing section.
*
* @param {string} printSectionId - Id of the printing section.
* @returns {string | null} - HTML content of the printing section, or null if not found.
* @private
*/
private getHtmlContents;
/**
* Retrieves the HTML content of elements with the specified tag.
*
* @param {keyof HTMLElementTagNameMap} tag - HTML tag name.
* @returns {string} - Concatenated outerHTML of elements with the specified tag.
* @private
*/
private getElementTag;
protected notifyPrintComplete(): void;
/**
* Prints the specified content using the provided print options.
*
* @public
* @param printOptionInput - Options for printing.
*/
protected print(printOptionInput?: Partial<PrintOptions>): void;
protected printWithWindow(printOptions: PrintOptions): void;
private printWithIframe;
private prepareDocumentComponents;
private buildPrintDocument;
static ɵfac: _angular_core.ɵɵFactoryDeclaration<PrintBase, never>;
static ɵprov: _angular_core.ɵɵInjectableDeclaration<PrintBase>;
}
declare class NgxPrintDirective extends PrintBase {
/**
* Prevents the print dialog from opening on the window
*/
readonly previewOnly: _angular_core.InputSignal<boolean>;
readonly printSectionId: _angular_core.InputSignal<string>;
readonly printTitle: _angular_core.InputSignal<string>;
readonly useExistingCss: _angular_core.InputSignal<boolean>;
/**
* A delay in milliseconds to force the print dialog to wait before opened. Default: 0
*/
readonly printDelay: _angular_core.InputSignal<number>;
/**
* Whether to close the window after print() returns.
*/
readonly closeWindow: _angular_core.InputSignal<boolean>;
/**
* Class attribute to apply to the body element.
*/
readonly bodyClass: _angular_core.InputSignal<string>;
/**
* Which PrintMethod (iframe/window/tab) to use.
*/
readonly printMethod: _angular_core.InputSignal<"window" | "tab" | "iframe">;
readonly printStyle: _angular_core.InputSignal<PrintStyleInput>;
readonly styleSheetFile: _angular_core.InputSignal<string>;
readonly printCompleted: _angular_core.OutputEmitterRef<void>;
print(): void;
static ɵfac: _angular_core.ɵɵFactoryDeclaration<NgxPrintDirective, never>;
static ɵdir: _angular_core.ɵɵDirectiveDeclaration<NgxPrintDirective, "[ngxPrint]", never, { "previewOnly": { "alias": "previewOnly"; "required": false; "isSignal": true; }; "printSectionId": { "alias": "printSectionId"; "required": false; "isSignal": true; }; "printTitle": { "alias": "printTitle"; "required": false; "isSignal": true; }; "useExistingCss": { "alias": "useExistingCss"; "required": false; "isSignal": true; }; "printDelay": { "alias": "printDelay"; "required": false; "isSignal": true; }; "closeWindow": { "alias": "closeWindow"; "required": false; "isSignal": true; }; "bodyClass": { "alias": "bodyClass"; "required": false; "isSignal": true; }; "printMethod": { "alias": "printMethod"; "required": false; "isSignal": true; }; "printStyle": { "alias": "printStyle"; "required": false; "isSignal": true; }; "styleSheetFile": { "alias": "styleSheetFile"; "required": false; "isSignal": true; }; }, { "printCompleted": "printCompleted"; }, never, never, true, never>;
}
declare class NgxPrintModule {
static ɵfac: _angular_core.ɵɵFactoryDeclaration<NgxPrintModule, never>;
static ɵmod: _angular_core.ɵɵNgModuleDeclaration<NgxPrintModule, never, [typeof NgxPrintDirective], [typeof NgxPrintDirective]>;
static ɵinj: _angular_core.ɵɵInjectorDeclaration<NgxPrintModule>;
}
/**
* Service for handling printing functionality in Angular applications.
* Extends the base printing class (PrintBase).
*
* @export
* @class NgxPrintService
* @extends {PrintBase}
*/
declare class NgxPrintService extends PrintBase {
printComplete$: rxjs.Observable<void>;
/**
* Initiates the printing process using the provided print options.
*
* @param {PrintOptions} printOptions - Options for configuring the printing process.
* @memberof NgxPrintService
* @returns {void}
*/
print(printOptions?: Partial<PrintOptions>): void;
/**
* Sets the print style for the printing process.
*
* @param values - Either a dictionary representing the print styles, or a raw CSS string.
* @memberof NgxPrintService
* @setter
*/
set printStyle(values: PrintStyleInput);
/**
* Sets the stylesheet file for the printing process.
*
* @param {string} cssList - A string representing the path to the stylesheet file.
* @memberof NgxPrintService
* @setter
*/
set styleSheetFile(cssList: string);
static ɵfac: _angular_core.ɵɵFactoryDeclaration<NgxPrintService, never>;
static ɵprov: _angular_core.ɵɵInjectableDeclaration<NgxPrintService>;
}
export { NgxPrintDirective, NgxPrintModule, NgxPrintService, PrintOptions };
export type { PrintStyle, PrintStyleInput };
//# sourceMappingURL=ngx-print.d.ts.map