2.1.8 • Published 10 months ago

ngx-print-element v2.1.8

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

ngx-print-element

This library is built to provide a solution for printing on html elements.\ This is the Github, Stackblitz .

Logo

Installation

Install ngx-print-element from npm:

npm install ngx-print-element@<version> --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: [
      'header, footer{ text-align: center; }',
      'body .bg-success{ background-color: #4dcf83 !important; }',
      'body .bg-danger{ background-color: #f96868 !important; }',
    ]
  }

  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>

API Documentation

FieldDescriptionTypeDefault
htmlTypedomObj,textstring'domObj'
printModetemplate,template-popupstringtemplate
popupPropertiesOptions window.openstringblank
pageTitlePrint titlestringblank
templateStringhtmlstringblank
stylesheetsSet the external style sheet for printingobject or object[]null
stylesSet the internal style sheet for printingstring or string[]null

Support versions

Author Information

To make this library more complete, please donate to me if you can!

Vietnam

MIT License. Copyright (c) 2022 DaiDH

2.1.8

10 months ago

2.1.7

10 months ago

2.1.7-rc.1

10 months ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.4

2 years ago

2.1.3

2 years ago

2.1.6

2 years ago

2.1.5

2 years ago

2.1.4-beta.1

2 years ago

2.1.3-beta.1

2 years ago

2.1.2-beta.1

2 years ago

2.1.1-beta.1

2 years ago

2.1.6-beta.1

2 years ago

2.1.3-beta.2

2 years ago

2.1.5-beta.1

2 years ago

2.0.19-beta.1

2 years ago

2.0.19-beta.2

2 years ago

2.1.0

2 years ago

2.1.0-beta.1

2 years ago

2.0.19

2 years ago

2.0.18-beta.1

3 years ago

2.0.17

3 years ago

2.0.18

3 years ago

2.0.17-rc.1

3 years ago

2.0.17-rc.2

3 years ago

2.0.17-rc.3

3 years ago

2.0.15

3 years ago

2.0.16

3 years ago

2.0.15-rc.2

3 years ago

2.0.15-rc.3

3 years ago

2.0.15-rc.1

3 years ago

2.0.14-rc.1

3 years ago

2.0.13

3 years ago

2.0.14

3 years ago

2.0.12

3 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.11

3 years ago

2.0.7

4 years ago

2.0.6

4 years ago

2.0.9

3 years ago

2.0.10

3 years ago

2.0.8

3 years ago

2.0.7-rc

3 years ago

2.0.8-rc.1

3 years ago

2.0.7-rc.1

3 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago