ngx-printer
Version:
An easy to use service to print a window or parts of a window (div). Printing of Angular Templates or Components is possible.
383 lines (371 loc) • 11.4 kB
TypeScript
import * as rxjs from 'rxjs';
import * as i0 from '@angular/core';
import { TemplateRef, Type, EnvironmentInjector, OnInit, EventEmitter, ElementRef, Renderer2, OnDestroy, ModuleWithProviders } from '@angular/core';
declare enum ngxPrintMarkerPosition {
Topleft = 0,
TopRight = 1,
BottomLeft = 2,
BottomRight = 3
}
/**
* A class to store an item which can be printed
*/
declare class PrintItem {
/**
* HTML id of anchor
*/
id: string;
/**
* Optional name
*/
printDisplayName: string;
/**
* HTML Element
*/
nativeElement: HTMLElement;
constructor();
}
/**
* Config for service - used in forRoot
*/
declare class PrintServiceConfig {
/** Print in a new window or not */
printOpenWindow?: boolean;
/** Wait time before opening print dialog */
timeToWaitRender?: number;
/** Class name to be used when printing in current window */
renderClass?: string;
appRootName?: string;
markerPosition?: ngxPrintMarkerPosition;
printPreviewOnly?: boolean;
}
type Content<T> = string | HTMLElement | TemplateRef<T> | Type<T>;
/**
* Main print service
*/
declare class NgxPrinterService {
private envInjector;
private printWindowOpen;
/**
* @internal
*/
private _printItems;
$printItems: rxjs.Observable<PrintItem[]>;
private openNgxPrinter;
/**
* Wait time to render before open print dialog in ms
* Default is 200
*/
timeToWaitRender: number;
/**
* Class used in component when printing to current window
*/
renderClass: string;
/**
* Open new window to print or not
* Default is true
*/
printOpenWindow: boolean;
/**
* Name of root component
* Default is app-root
*/
appRootName: string;
/**
* Do not fire print event - just show preview
* Default is false
*/
printPreviewOnly: boolean;
appRoot: HTMLElement;
appRootDislaySetting: string;
$printWindowOpen: rxjs.Observable<boolean>;
eventadded: any[];
markerPosition: ngxPrintMarkerPosition;
constructor(config: PrintServiceConfig, envInjector: EnvironmentInjector);
/**
* Set global config from forRoot
* @param config
*/
private setRootConfigOptions;
/***
* Print a div identified by its id
* @example
* this.printerService.printDiv('printDiv');
*/
printDiv(divID: string): void;
/***
* Print an Element identified by its className using getElementsByClassName
* Prints the first one found
*/
printByClassName(className: string): void;
/**
* Print Angular TemplateRef or a Component or String
* @param contentToPrint
* @example
* this.printerService.printAngular(this.PrintTemplateTpl);
*/
printAngular(contentToPrint: any, context?: any): void;
/**
* Print single img
* @example
* this.printerService.printImg('assets/bratwurst.jpg');
*/
printImg(imgSrc: string): void;
/**
* Print an native Element (HTML Element)
* @param nativeElement
* @example
* this.printerService.printHTMLElement(this.PrintComponent.nativeElement);
*/
printHTMLElement(nativeElement: HTMLElement): void;
/**
* Create and render component
* @param contentToRender
*/
private createComponent;
/**
* Main print function
* @param printContent
*/
private print;
/**
* Print using a new window / tab
* @param divToPrint
*/
private printInNewWindow;
/**
* Print window in new tab
*/
private printTabWindow;
/**
* Print the whole current window
*/
printCurrentWindow(): void;
/**
* Listen to print event of window
* @param printWindow
*/
private registerPrintEvent;
/**
* Close tab or clean up dom
* @internal
*/
private cleanUp;
/**
* Hide an element before printing
* @param parentDiv
*/
private hideBeforePrint;
/**
* Search for Angular App Root
* @internal
*/
private getAppRoot;
/**
* Add a new item to print
* Used by directive
* @internal
* @param newPrintItem HTML id
*/
addPrintItem(newPrintItem: PrintItem): void;
/**
* Delete a print item from service
* Used by directive
* @internal
* @param idOfItemToRemove
*/
removePrintItem(idOfItemToRemove: string): void;
/**
* Gets a single print item from service
* Used by directive
* @internal
* @param idOfItemToFind
*/
getPrintItem(idOfItemToRemove: string): PrintItem;
/**
* Print a print Item
* @param printItemToPrint
*/
printPrintItem(printItemToPrint: PrintItem): void;
/**
* Print al list of print Items one after the other
* @param printItemToPrint
*/
printPrintItems(printItemsToPrint: PrintItem[], className?: string): void;
/**
* Create node or angular component and returns an array of nodes
* @param content
* @internal
*/
private resolveNgContent;
static ɵfac: i0.ɵɵFactoryDeclaration<NgxPrinterService, [{ optional: true; }, null]>;
static ɵprov: i0.ɵɵInjectableDeclaration<NgxPrinterService>;
}
/**
* Component used to render content when printed to current window
*/
declare class NgxPrinterComponent implements OnInit {
private elementRef;
private renderer;
private _renderClass;
get renderClass(): string;
set renderClass(value: string);
/**
* Display single image
*/
private _imgSrc;
get imgSrc(): string;
set imgSrc(value: string);
completed: EventEmitter<boolean>;
constructor(elementRef: ElementRef, renderer: Renderer2);
ngOnInit(): void;
/**
* Attach custom class to element
*/
private setCustomClass;
/**
* Add custom image
* @param source
*/
private addImage;
static ɵfac: i0.ɵɵFactoryDeclaration<NgxPrinterComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<NgxPrinterComponent, "ngx-printer", never, {}, { "completed": "completed"; }, never, ["*"], false, never>;
}
/**
* A directive to mark and store an HTML-Element as an item which
* can be printed
* An id has to be set
*/
declare class PrintItemDirective implements OnInit, OnDestroy {
private el;
private printerService;
/**
* Optional name to be shown in an component
*/
printName: string;
constructor(el: ElementRef, printerService: NgxPrinterService);
ngOnInit(): void;
ngOnDestroy(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<PrintItemDirective, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<PrintItemDirective, "[ngxPrintItem]", never, { "printName": { "alias": "printName"; "required": false; }; }, {}, never, never, false, never>;
}
/**
* Directly add function to a button to print an item
*/
declare class PrintItemButtonDirective implements OnInit {
private el;
private printerService;
/**
* Id of print item to be printed
*/
printItemId: string;
/**
* html id of div to be printed
*/
divID: string;
/**
* print item by class name
*/
className: string;
/**
* print current window
*/
printWindow: string;
constructor(el: ElementRef, printerService: NgxPrinterService);
ngOnInit(): void;
/**
* Check if at least one property is set
*/
private checkInputs;
/**
* print item from print items
*/
private prinPrintItem;
static ɵfac: i0.ɵɵFactoryDeclaration<PrintItemButtonDirective, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<PrintItemButtonDirective, "[ngxPrintItemButton]", never, { "printItemId": { "alias": "printItemId"; "required": false; }; "divID": { "alias": "divID"; "required": false; }; "className": { "alias": "className"; "required": false; }; "printWindow": { "alias": "printWindow"; "required": false; }; }, {}, never, never, false, never>;
}
/**
* Mark an div as printable and provide direct print function
*/
declare class PrintItemMarkerDirective implements OnInit {
private el;
private renderer2;
private printerService;
customClass: string;
directPrint: boolean;
imgPosition: ngxPrintMarkerPosition;
/**
* Data for an svg image used as background url
* @example
* backgroundImage = 'data:image/svg+xml;base64,PD9....'
*
*/
backgroundImage: string;
imgMainStyles: {
'background-color': string;
height: string;
width: string;
position: string;
cursor: string;
};
imgPositionTopLeft: {
left: string;
top: string;
};
imgPositionTopRight: {
right: string;
top: string;
};
imgPositionBottomLeft: {
left: string;
bottom: string;
};
imgPositionBottomRight: {
right: string;
bottom: string;
};
/**
* Event fired when marker clicked
* @emits
*/
printClicked: EventEmitter<any>;
constructor(el: ElementRef, renderer2: Renderer2, printerService: NgxPrinterService);
ngOnInit(): void;
/**
* Change and add div with Indicator
* @param el
* @param newIndicator
*/
private addIndicatorDiv;
/**
* Set the default css properties
* @param newIndicator
*/
private setCss;
/**
* Set image position
* @internal
* @param newIndicator
*/
private setPosition;
static ɵfac: i0.ɵɵFactoryDeclaration<PrintItemMarkerDirective, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<PrintItemMarkerDirective, "[ngxPrintItemMarker]", never, { "customClass": { "alias": "customClass"; "required": false; }; "directPrint": { "alias": "directPrint"; "required": false; }; "imgPosition": { "alias": "imgPosition"; "required": false; }; "backgroundImage": { "alias": "backgroundImage"; "required": false; }; }, { "printClicked": "printClicked"; }, never, never, false, never>;
}
/**
* Directive to mark an element so that it should NOT be printed
*/
declare class NoPrintDirective {
private el;
private renderer2;
constructor(el: ElementRef, renderer2: Renderer2);
static ɵfac: i0.ɵɵFactoryDeclaration<NoPrintDirective, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<NoPrintDirective, "[ngxNoPrint]", never, {}, {}, never, never, false, never>;
}
declare class NgxPrinterModule {
static forRoot(config: PrintServiceConfig): ModuleWithProviders<NgxPrinterModule>;
static ɵfac: i0.ɵɵFactoryDeclaration<NgxPrinterModule, never>;
static ɵmod: i0.ɵɵNgModuleDeclaration<NgxPrinterModule, [typeof NgxPrinterComponent, typeof PrintItemDirective, typeof PrintItemButtonDirective, typeof PrintItemMarkerDirective, typeof NoPrintDirective], never, [typeof NgxPrinterComponent, typeof PrintItemDirective, typeof PrintItemButtonDirective, typeof PrintItemMarkerDirective, typeof NoPrintDirective]>;
static ɵinj: i0.ɵɵInjectorDeclaration<NgxPrinterModule>;
}
export { NgxPrinterComponent, NgxPrinterModule, NgxPrinterService, NoPrintDirective, PrintItem, PrintItemButtonDirective, PrintItemDirective, PrintItemMarkerDirective, PrintServiceConfig, ngxPrintMarkerPosition };
export type { Content };