2.1.6 • Published 6 months ago

ngx-print-element v2.1.6

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

ngx-print-element

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

Logo

Installation

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,
    ]
})

Need to import css

@import '~ngx-print-element/styles.css';

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 id="demo" class="table table-bordered">
  <tr>
    <th>No</th>
    <th>Company</th>
    <th>Contact</th>
    <th>Country</th>
  </tr>
  <tr class="print-none" style="background: greenyellow"><!-- No print -->
    <td>01</td>
    <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
    <td>Germany</td>
  </tr>
  <tr>
    <td>02</td>
    <td>Centro comercial Moctezuma</td>
    <td>Francisco Chang</td>
    <td>Mexico</td>
  </tr>
  <tr>
    <td>03</td>
    <td>AIS Playground</td>
    <td>Nakhon Pathom</td>
    <td>Thailand</td>
  </tr>
  <tr class="print-none" style="background: greenyellow"> <!-- No print -->
    <td>04</td>
    <td>FPT Software</td>
    <td>Cau Giay</td>
    <td>Vietnamese</td>
  </tr>
</table>

1# The first way doesn't need configuration

<button [print]="['demo']">Print</button>

2# The second way needs configuration

<button [print]="['demo', config]">Print</button>
import { Component } from '@angular/core';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  public config = {
    printMode: '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; }', 'header, table, footer { margin: auto; text-align: center; }']
  }
}

Services

import { Component } from '@angular/core';
import { NgxPrintElementService } from 'ngx-print-element';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  constructor(public print: NgxPrintElementService) {}

  onPrint(id: string) {
    this.print.print(id).subscribe(console.log);
  }
}
<p id="demo">Angular-Print</p>
<button (click)="onPrint('demo')">Print</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

If you want donate for me!

Vietnam

MIT License. Copyright (c) 2022 DaiDH

2.1.2

6 months ago

2.1.1

6 months ago

2.1.4

6 months ago

2.1.3

6 months ago

2.1.6

6 months ago

2.1.5

6 months ago

2.1.4-beta.1

6 months ago

2.1.3-beta.1

6 months ago

2.1.2-beta.1

6 months ago

2.1.1-beta.1

6 months ago

2.1.6-beta.1

6 months ago

2.1.3-beta.2

6 months ago

2.1.5-beta.1

6 months ago

2.0.19-beta.1

12 months ago

2.0.19-beta.2

12 months ago

2.1.0

12 months ago

2.1.0-beta.1

12 months ago

2.0.19

12 months ago

2.0.18-beta.1

1 year ago

2.0.17

1 year ago

2.0.18

1 year ago

2.0.17-rc.1

1 year ago

2.0.17-rc.2

1 year ago

2.0.17-rc.3

1 year ago

2.0.15

2 years ago

2.0.16

2 years ago

2.0.15-rc.2

2 years ago

2.0.15-rc.3

2 years ago

2.0.15-rc.1

2 years ago

2.0.14-rc.1

2 years ago

2.0.13

2 years ago

2.0.14

2 years ago

2.0.12

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.11

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.9

2 years ago

2.0.10

2 years ago

2.0.8

2 years ago

2.0.7-rc

2 years ago

2.0.8-rc.1

2 years ago

2.0.7-rc.1

2 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago