
Security News
TC39 Advances 11 Proposals for Math Precision, Binary APIs, and More
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
ngx-print-element
Advanced tools
This library is built to provide a solution for printing on html elements.
This library is built to provide a solution for printing on html elements.
This is the stackblitz.
Install ngx-print-element
from npm
:
npm install ngx-print-element --save
Add wanted package to NgModule imports:
import { NgxPrintElementModule } from 'ngx-print-element';
@NgModule({
imports: [
NgxPrintElementModule,
]
})
Printing data sheet with id is up to you.
If there is an element you don't want to display you can add the class print-none
<table #tableRef ngxPrintElement>
<tr>
<th>No</th>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>01</td>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td class="bg-success">02</td>
<td class="bg-success">Centro comercial Moctezuma</td>
<td class="bg-success">Francisco Chang</td>
<td class="bg-success">Mexico</td>
</tr>
<tr>
<td>03</td>
<td>AIS Playground</td>
<td>Nakhon Pathom</td>
<td>Thailand</td>
</tr>
<tr class="print-none"> <!-- No print -->
<td class="bg-danger">04</td>
<td class="bg-danger">FPT Software</td>
<td class="bg-danger">Cau Giay</td>
<td class="bg-danger">Vietnamese</td>
</tr>
</table>
import { Component, ElementRef, ViewChild } from '@angular/core';
import { NgxPrintElementService } from 'ngx-print-element';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
@ViewChild('tableRef') tableElement: ElementRef<HTMLTableElement>;
public config: Config = {
printMode: 'template', // template-popup
popupProperties: 'toolbar=yes,scrollbars=yes,resizable=yes,top=0,left=0,fullscreen=yes',
pageTitle: 'Hello World',
templateString: '<header>I\'m part of the template header</header>{{printBody}}<footer>I\'m part of the template footer</footer>',
stylesheets: [{ rel: 'stylesheet', href: 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css' }],
styles: ['td { border: 1px solid black; color: green; }', 'table { border: 1px solid black; color: red }', 'header, table, footer { margin: auto; text-align: center; }']
}
constructor(public print: NgxPrintElementService) {}
onPrint1(el: ElementRef<HTMLTableElement>) {
this.print.print(el).subscribe(console.log);
}
onPrint2(el: ElementRef<HTMLTableElement>) {
this.print.print(el, this.config).subscribe(console.log);
}
onPrint3(el: ElementRef<HTMLTableElement>) {
this.print.print(el, { ...this.config, printMode: 'template-popup' }).subscribe(console.log);
}
}
<!-- default -->
<ngx-print-element #element="element">
<button (click)="element?.print(tableElement)">Print default</button>
</ngx-print-element>
<!-- default -->
<button (click)="onPrint1(tableElement)">Print default</button>
<!-- iframe -->
<button (click)="onPrint2(tableElement)">Template iframe</button>
<!-- window.open -->
<button (click)="onPrint3(tableElement)">Template new window</button>
Field | Description | Type | Default |
---|---|---|---|
htmlType | domObj ,text | string | 'domObj' |
printMode | template ,template-popup | string | template |
popupProperties | Options window.open | string | blank |
pageTitle | Print title | string | blank |
templateString | html | string | blank |
stylesheets | Set the external style sheet for printing | object or object[] | null |
styles | Set the internal style sheet for printing | string or string[] | null |
Support versions | |
---|---|
Angular 6 | 2.1.1 |
Author Information | |
---|---|
Author | DaiDH |
Phone | +84845882882 |
Country | Vietnam |
Bitcoin | Paypal | MbBank |
---|---|---|
![]() | ![]() | ![]() |
MIT License. Copyright (c) 2022 DaiDH
FAQs
This library is built to provide a solution for printing on html elements.
The npm package ngx-print-element receives a total of 0 weekly downloads. As such, ngx-print-element popularity was classified as not popular.
We found that ngx-print-element demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.