npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-printify

v1.5.2

Published

A utility for printing in Angular applications

Downloads

1,360

Readme

NgxPrintify

NgxPrintify is an Angular utility library that simplifies the process of printing content in your Angular applications. It provides a directive for easy integration into your components and a service for programmatic printing.

Table of Contents

Installation

To install ngx-printify, use npm:

npm install ngx-printify --save

Dependencies

Version Compatibility

The NgxPrintify library supports the following Angular versions based on its releases:

| NgxPrintify Version | Angular Versions Supported | |----------------------|------------------------------| | 1.1.6 | Angular 10.0.0 to 14.2.3 | | 1.2.2 | Angular 15.0.0 | | 1.3.1 | Angular 16.0.0 | | 1.4.1 | Angular 17.0.0 | | 1.5.2 | Angular 18.0.0 |

Ensure that your Angular project is within the specified version range to utilize the features of NgxPrintify effectively.

Usage

Directive Usage

The NgxPrintify directive allows you to trigger print functionality directly from your templates.

Step 1: Import the Module

Make sure to import the NgxPrintifyModule in your Angular module.

import { NgxPrintifyModule } from 'ngx-printify';

@NgModule({
  imports: [
    NgxPrintifyModule,
    // other imports
  ],
})
export class AppModule {}

Step 2: Using the Directive in Templates

You can use the ngxPrintify directive in your component templates as follows:

<div id="printArea1">
  <h1>Content of Print Area 1</h1>
  <p>This is the content that will be printed from printArea1.</p>
</div>

<div id="printArea2">
  <h1>Content of Print Area 2</h1>
  <p>This is the content that will be printed from printArea2.</p>
</div>

<ng-template #printTemplate>
  <h1>Print This Title</h1>
  <p>This is the content to print.</p>
  <div class="highlight">Highlighted content.</div>
</ng-template>

<button ngxPrintify 
        [printItemsId]="'printArea1,printArea2'"  <!-- Allow multiple IDs separated by commas -->
        [printTemplate]="printTemplate" 
        [printTitle]="'Print Example'" 
        [useExistingCss]="true" 
        [printStyle]="{ h1: { color: 'red' }, '.highlight': { border: 'solid 1px' } }" 
        [closeWindow]="true" 
        [previewOnly]="false">
  Print
</button>

Service Usage

The NgxPrintifyService can be used for more programmatic control over printing.

Step 1: Import the Service

Inject the NgxPrintifyService into your component:

import { Component, TemplateRef, ViewChild } from '@angular/core';
import { NgxPrintifyService } from 'ngx-printify';

@Component({
  selector: 'app-example',
  templateUrl: './example.component.html',
})
export class ExampleComponent {
  @ViewChild('printTemplate') printTemplate!: TemplateRef<any>;

  constructor(private printService: NgxPrintifyService) {}

  print() {
    this.printService.print({
      printItemsId: 'printArea1,printArea2', // Allow multiple IDs separated by commas
      printTemplate: this.printTemplate, // Pass the TemplateRef here
      printTitle: 'Print Example',
      useExistingCss: true,
      printStyle: {
        h1: { color: 'red' },
        '.highlight': { border: 'solid 1px', color: 'blue' }
      },
      closeWindow: true,
      previewOnly: false,
      printWindowOptions: {
        width: 800,
        height: 600
      }
    });
  }
}

API Reference

NgxPrintifyDirective

Inputs:

  • printItemsId?: string: Comma-separated IDs of elements to print (supports multiple IDs).
  • printTitle?: string: Title for the print window.
  • useExistingCss?: boolean: Whether to use existing styles.
  • printStyle?: { [key: string]: { [property: string]: string } }: Styles to apply to elements.
  • styleSheetFile?: string: Custom stylesheets to include.
  • previewOnly?: boolean: If true, shows the print preview without printing.
  • closeWindow?: boolean: Whether to close the print window after printing.
  • printWindowOptions?: PrintWindowOptions: Additional options for the print window.
  • printTemplate?: TemplateRef<any>: Angular template to render.

NgxPrintifyService

Method:

  • print(params: { ... }): void: Prepares and executes the print operation with the specified parameters.

License

This project is licensed under the MIT License - see the LICENSE file for details.