NG Kit

Ngx Print

ngxPrint is a reusable Angular directive that prints any specified section of your application. Apply it to a button, point it at an element by id, and it opens a print dialog or a live preview window that renders exactly the content you want.

Overview

Add the ngxPrint (or print) attribute to a <button> and set printSectionId to the id of the element whose contents should be printed. The directive provides rich printing capabilities including:

  • Angular Material table support (with pagination)
  • jQuery DataTable support

With options for custom styling (printStyle), external stylesheets (styleSheetFile), paginated data tables, and a preview-only mode (previewOnly), it makes it easy to print or preview exactly what you need.

API

Selectors

button[ngxPrint], button[print]

The directive must be applied to a <button> element, and printSectionId is required.

Inputs

NameTypeDefaultDescription
printSectionIdstring | undefinedundefinedID of the HTML element whose contents need to be printed
printTitlestring | undefinedundefinedTitle of the document to be printed (appears in print preview)
useExistingCssbooleanfalseIf true, uses existing CSS from the HTML element, otherwise no CSS applied
printDelaynumber0Delay in milliseconds before opening the print dialog
matTableDataSourceMatTableDataSource<T>Instance of the Material Table Data Source (required for Material table support)
paginatorMatPaginatorInstance of the Material Paginator (required for Material table support)
paginatorIdstring''HTML element ID of the Mat Paginator
inputFilterIdstring''HTML element ID of the Mat-Table input filter
isMatTablebooleanfalseIf true, indicates the referenced table is a Material Table
hideMatTablePaginatorbooleanfalseIf true, hides the Mat-Table paginator during printing
previewOnlybooleanfalseIf true, prevents the print dialog from opening (preview only)
printStylePrintStyleParamsObject containing CSS properties to apply while printing
styleSheetFilestring''Comma-separated list of CSS file paths to include in the print document

PrintStyleParams

The printStyle input accepts an object whose values map CSS selectors to declaration blocks:

PropertyTypeDescription
valuesRecord<string, Record<string, string>>Nested map of at-rule / selector to CSS property declarations applied while printing