# NgxPrinterDemo A easy to use service to print the window, parts of a window (div) or an image. Printing of Angular Templates or Components is possible. You can print opening a new window / tab or using the current window. A directive can also be used to mark and store an HTML-element. Several usefull directives can further assist you. See the DEMO App and [DEMO-Page](https://plaetzchen79.github.io/) 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 **Easy start** The easiest way to print an HTML Element is HTML: ```html
``` ## Options ### Open new window 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* ```javascript imports: [ BrowserModule, NgxPrinterModule.forRoot({printOpenWindow: true}) ], ``` ### Rendering time Before openening the print window the service to some time to render the print content. Default time is 200ms. You can adjust the time using the property *timeToWaitRender* (also in forRoot). ### Default CSS-Class When printing to the current window the service creates an component with a css-class called 'default'. You can override this class *name* using the property *renderClass* (also in forRoot). Make sure that the class is placed in your global styles (styles.css). ### Name of app-root When printing to the current window the service searches the app-root component. If you have changed the name of the root component in your app you can override the name using the property *appRootName*. ### Position of image for directive 'ngxPrintItemMarker' The maker image is placed to the bottom left. You can change this by changing the property *markerPosition*. Use a value of the enum *ngxPrintMarkerPosition* (TopLeft, .TopRight, .BottomLeft, .BottomRight). ### Print preview - not fire print event If you want to display a preview without fireing the print event you can use *printPreviewOnly = true*. This can also be usefull for debugging purposes. ## Functions - How to print ### Print current window `this.printerService.printCurrentWindow();` ### Print div by id `this.printerService.printDiv('idOfDivToPrint');` ### Print image src/url directly `this.printerService.printImg('assets/bratwurst.jpg');` ### Print Angular TemplateRef or Component ```javascript @ViewChild('PrintTemplate') private PrintTemplateTpl: TemplateRef