Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ngx-printer

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngx-printer

A simple service to print the window or parts of a window (div). Printing of Angular Templates or Components is possible.

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
636
decreased by-48.12%
Maintainers
1
Weekly downloads
 
Created
Source

A simple service to print the window or parts of a window (div). Printing of Angular Templates or Components is possible.

See DEMO App for examples.

Usage

  1. Add to main app.module imports
  2. Use the NgxPrinterService where you like via DI (private printerService: NgxPrinterService)
  3. Use the the functions provided by the service

Options

The service prints by opening a new window. There is an option printWindowOpen to change this behavoir. Set printWindowOpen=false;

You can also set this option in .forRoot while importing the module to the app.module

    imports: [
    BrowserModule,
    NgxPrinterModule.forRoot({printOpenWindow: true})
  ],

Functions

Print current window

this.printerService.printCurrentWindow();

Print div by id

this.printerService.printDiv('idOfDivToPrint');

Print Angular TemplateRef or Component

 @ViewChild('PrintTemplate')
  private PrintTemplateTpl: TemplateRef<any>;

printTemplate() {
    this.printerService.printAngular(this.PrintTemplateTpl);
  }

Beware: To print a component the component needs to be known by service (copy source and add it to entry component of app.module). Otherwise use printHTMLElement instead.

Print HTML Element

 @ViewChild(LittleDummyComponent, {read: ElementRef}) PrintComponent: ElementRef;

 printHTMLElementToCurrent() {
    this.printerService.printHTMLElement(this.PrintComponent.nativeElement);
  }

Event of print window

If you want to check whether the print window is open or not subscribe to obserbable $printWindowOpen

this.printWindowSunscription = this.printerService.$printWindowOpen.subscribe(val => {
      console.log('Print window is open:', val);
});

Directive ngxPrintItem

There is an directive ngxPrintItem to mark and store an HTML-Element as an item which can be printed later and anyhwere on the page. An id has to be set. These items are stored in the services observable printerService.$printItems. Use the async pipe to subscribe and the function printPrintItem to print the item.

HTML:

<span id="firstPrintItem" ngxPrintItem printName="First one" >A <b>first</b> span with an ngxPrintItem directive</span>

<div *ngFor="let prinItem of $printItems | async">
  <span>{{prinItem.id}} - {{prinItem.printName}}</span>
  <button (click)="printItem(prinItem)">Print me!</button>
</div>

TS:

  printItem(itemToPrint: PrintItem) {
    this.printerService.printPrintItem(itemToPrint);
  }
});

Keywords

FAQs

Package last updated on 19 May 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc