Skip to content

Commit

Permalink
Support styles (CSS) for the printing window
Browse files Browse the repository at this point in the history
  • Loading branch information
selemxmn committed Dec 3, 2018
1 parent 9b38429 commit 71cefdf
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions src/lib/ngx-print.directive.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,50 @@
import { Directive, HostListener, Input } from '@angular/core';
/**
*
*
* @export
* @class NgxPrintDirective
*/
@Directive({
selector: 'button[ngxPrint]'
})

export class NgxPrintDirective {

private _printStyle = [];

/**
*
*
* @type {string}
* @memberof NgxPrintDirective
*/
@Input() printSectionId: string;

/**
*
*
* @type {string}
* @memberof NgxPrintDirective
*/
@Input() windowTitle: string;
@Input() printTitle: string;

/**
*
*
* @memberof NgxPrintDirective
*/
@Input()
set printStyle(values: {[key: string]: {[key: string]: string}}) {
for (var key in values) {
if (values.hasOwnProperty(key)) {
this._printStyle.push((key + JSON.stringify(values[key])).replace(/['"]+/g, ''));
}
}
this.returnStyleValues();
}

/**
*
*
* @returns
* @memberof NgxPrintDirective
*/
private returnStyleValues() {
return this._printStyle.join(' ');
}

/**
*
Expand All @@ -41,7 +60,10 @@ export class NgxPrintDirective {
popupWin.document.write(`
<html>
<head>
<title>${this.windowTitle ? this.windowTitle : ''}</title>
<title>${this.printTitle ? this.printTitle : ''}</title>
<style>
${this.returnStyleValues()}
</style>
</head>
<body onload="window.print();window.close()">${printContents}</body>
</html>`
Expand Down

0 comments on commit 71cefdf

Please sign in to comment.