
Research
SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains
An emerging npm supply chain attack that infects repos, steals CI secrets, and targets developer AI toolchains for further compromise.
This directive makes printing your HTML sections smooth and easy in your Angular application. It is inspired from the old AngularJS ngPrint directive, thus it is intendend to be used with the new Angular -2/4/5/6/7-... Enjoy ! contributions are so welcomed :)
| ngx-print | Angular |
|---|---|
| 1.2.1 | 7.0.0 - 14.1.0 |
| 1.3.x | 15.0.0 |
| 1.4.x | 16.0.0 |
| 1.5.x | 17.0.0 |
| 2.x.x | 18.0.0 |
| 3.x.x | 19.0.0 |
| 20.x.x | 20.0.0 |
| 21.x.x | 21.0.0 |
Starting with version 20.0.0, this package aligns its major version with the Angular framework version for better clarity and compatibility tracking. Version 20 is intended for Angular 20 and so on.
1- In your root application folder run:
$ npm install ngx-print
2- Once ngx-print is installed, you need to import the directive NgxPrintDirective:
import { NgxPrintDirective } from 'ngx-print';
@Component({
...
imports: [NgxPrintDirective]
...
})
export class PrintExampleComponent {}
3- Then plug n' play with it:
<div>
<!--Your html stuff that you want to print-->
</div>
<button>print</button> <!--Your relevant print button-->
id attribute, then link that id to a directive parameter in your button : <!--
1)- Add an ID here
-->
<div id="print-section">
<!--Your html stuff that you want to print-->
</div>
<!--
2)- Add the directive name in your button (ngxPrint),
3)- Affect your ID to printSectionId
-->
<button printSectionId="print-section" ngxPrint>print</button>
printTitle:<div id="print-section">
<!-- ... -->
</div>
<button printTitle="MyTitle"
printSectionId="print-section"
ngxPrint>print</button>
printStyle:<div id="print-section">
<!-- ... -->
</div>
<button [printStyle]="{h1 : {'color': 'red'}, h2 : {'border': 'solid 1px'}}"
printSectionId="print-section"
ngxPrint>print</button>
Here some simple styles were added to every h1 & h2 tags within the div where print-section is tagged to its id attribute.
useExistingCss attribute:<div id="print-section">
<!-- ... -->
</div>
<button [useExistingCss]="true"
printSectionId="print-section"
ngxPrint>print</button>
styleSheetFile:<div id="print-section">
<!-- ... -->
</div>
<button styleSheetFile="assets/css/custom1.css,assets/css/custom2.css"
printSectionId="print-section"
ngxPrint>print</button>
previewOnly:<div id="print-section">
<!-- ... -->
</div>
<button [previewOnly]="true"
printSectionId="print-section"
ngxPrint>print</button>
closeWindow to false to handle print operations that open a second dialog, like "Microsoft Print to PDF", or "Print using system dialog...":
<div id="print-section">
<!-- ... -->
</div>
<button [closeWindow]="false"
printSectionId="print-section"
ngxPrint>print</button>
bodyClass to whatever class values are needed for some of your css rules that expect an ancestor to have a certain class. For example, a theme selector:<div id="print-section">
<!-- ... -->
</div>
<button [bodyClass]="theme-dark"
printSectionId="print-section"
ngxPrint>print</button>
openNewTab to true. By default openNewTab is false and ngxPrint will open a new print window.<button [openNewTab]="true"
ngxPrint>print</button>
printCompleted event. Please note it is impossible to differentiate between the Cancel or Print buttong being clicked on the print window. This event will fire regardless of which button was clicked:<button (printCompleted)="onPrintComplete()"
printSectionId="print-section"
ngxPrint>print
</button>
Inject the NgxPrintService into your component or service:
private readonly printService = inject(NgxPrintService);
import { PrintOptions } from './path-to-your/print-options.model';
printMe(): void {
const customPrintOptions: PrintOptions = new PrintOptions({
printSectionId: 'print-section',
// add any other print options as needed
});
this.printService.print(customPrintOptions)
}
The print options object allows you to specify how the print job should be handled. All of which have default values that you can optionally override, although printSectionId is required. It contains the following properties:
printSectionId: string = null;
printTitle: string = null;
useExistingCss: boolean = false;
bodyClass: string = '';
openNewTab: boolean = false;
previewOnly: boolean = false;
closeWindow: boolean = true;
printDelay: number = 0;
// Optional property for css as a key-value pair
this.printService.printStyle = styleSheet;
// Optional property for a css file location
this.printService.styleSheetFile = fileLocation;
this.printService.printComplete$.pipe(take(1)).subscribe(() => {
console.log('Print completed!');
});
If Angular is configured to use a CSP Nonce, ngx-print will automatically inject the [printStyle] CSS rules with this Nonce authorization.
Huge thanks to: deeplotia , Ben L , Gavyn McKenzie , silenceway, Muhammad Ahsan Ayaz, Core121 and to all ngx-print users
Did this project help you reducing time? I won't say no to a cup of coffee 🍵 :)
FAQs
Plug n' Play Angular (2++) directive to print your stuff
The npm package ngx-print receives a total of 36,342 weekly downloads. As such, ngx-print popularity was classified as popular.
We found that ngx-print demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers 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.

Research
An emerging npm supply chain attack that infects repos, steals CI secrets, and targets developer AI toolchains for further compromise.

Company News
Socket is proud to join the OpenJS Foundation as a Silver Member, deepening our commitment to the long-term health and security of the JavaScript ecosystem.

Security News
npm now links to Socket's security analysis on every package page. Here's what you'll find when you click through.