|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Print Events in TypeScript PDF Viewer | Syncfusion |
| 4 | +description: Learn about print events in the Syncfusion TypeScript PDF Viewer component. |
| 5 | +platform: document-processing |
| 6 | +control: Print |
| 7 | +documentation: ug |
| 8 | +domainurl: ##DomainURL## |
| 9 | +--- |
| 10 | + |
| 11 | +# Print events in Typescript PDF Viewer |
| 12 | + |
| 13 | +Subscribe to print lifecycle events to track usage and implement custom workflows. |
| 14 | + |
| 15 | +| Name | Description | |
| 16 | +|--------------|-------------| |
| 17 | +| `printStart` | Raised when a print action begins. Use the event to log activity or cancel printing. | |
| 18 | +| `printEnd` | Raised after a print action completes. Use the event to notify users or clean up resources. | |
| 19 | + |
| 20 | +## printStart event |
| 21 | +The [`printStart`](https://ej2.syncfusion.com/documentation/api/pdfviewer/#printstart) event runs when printing starts from the toolbar or from code. Use it to validate prerequisites or cancel the action. |
| 22 | + |
| 23 | +### Event arguments |
| 24 | +Review [`PrintStartEventArgs`](https://ej2.syncfusion.com/documentation/api/pdfviewer/printStartEventArgs/) for details such as `fileName` and the `cancel` option. |
| 25 | + |
| 26 | +The following example logs the file that is being printed and shows how to cancel the operation. |
| 27 | + |
| 28 | +{% tabs %} |
| 29 | +{% highlight ts tabtitle="Standalone" %} |
| 30 | + |
| 31 | +import { PdfViewer, PrintStartEventArgs, Toolbar, Magnification, Navigation, Annotation, LinkAnnotation,ThumbnailView,BookmarkView, TextSelection } from '@syncfusion/ej2-pdfviewer'; |
| 32 | + |
| 33 | +PdfViewer.Inject(Toolbar,Magnification,Navigation, Annotation, LinkAnnotation,ThumbnailView,BookmarkView, TextSelection); |
| 34 | + |
| 35 | +let pdfviewer: PdfViewer = new PdfViewer({ |
| 36 | + documentPath: 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf', |
| 37 | + resourceUrl: "https://cdn.syncfusion.com/ej2/31.1.23/dist/ej2-pdfviewer-lib", |
| 38 | + printStart: (args: PrintStartEventArgs) => { |
| 39 | + console.log('Print action has started for file: ' + args.fileName); |
| 40 | + // To cancel the print action |
| 41 | + // args.cancel = true; |
| 42 | + } |
| 43 | +}); |
| 44 | +pdfviewer.appendTo('#PdfViewer'); |
| 45 | + |
| 46 | +{% endhighlight %} |
| 47 | +{% highlight ts tabtitle="Server-Backed" %} |
| 48 | + |
| 49 | +import { PdfViewer, PrintStartEventArgs, Toolbar, Magnification, Navigation, Annotation, LinkAnnotation,ThumbnailView,BookmarkView, TextSelection } from '@syncfusion/ej2-pdfviewer'; |
| 50 | + |
| 51 | +PdfViewer.Inject(Toolbar,Magnification,Navigation, Annotation, LinkAnnotation,ThumbnailView,BookmarkView, TextSelection); |
| 52 | + |
| 53 | +let pdfviewer: PdfViewer = new PdfViewer({ |
| 54 | + documentPath: 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf', |
| 55 | + serviceUrl: 'https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer/', |
| 56 | + printStart: (args: PrintStartEventArgs) => { |
| 57 | + console.log('Print action has started for file: ' + args.fileName); |
| 58 | + // To cancel the print action |
| 59 | + // args.cancel = true; |
| 60 | + } |
| 61 | +}); |
| 62 | +pdfviewer.appendTo('#PdfViewer'); |
| 63 | + |
| 64 | +{% endhighlight %} |
| 65 | +{% endtabs %} |
| 66 | + |
| 67 | +## printEnd event |
| 68 | +The [`printEnd`](https://ej2.syncfusion.com/documentation/api/pdfviewer/#printend) event triggers after printing completes. Use it to finalize analytics or inform users that printing finished. |
| 69 | + |
| 70 | +### Event arguments |
| 71 | +See [`PrintEndEventArgs`](https://ej2.syncfusion.com/documentation/api/pdfviewer/printEndEventArgs/) for available values such as `fileName`. |
| 72 | + |
| 73 | +The following example logs the printed file name. |
| 74 | + |
| 75 | +{% tabs %} |
| 76 | +{% highlight ts tabtitle="Standalone" %} |
| 77 | + |
| 78 | +import { PdfViewer, PrintEndEventArgs, Toolbar, Magnification, Navigation, Annotation, LinkAnnotation,ThumbnailView,BookmarkView, TextSelection } from '@syncfusion/ej2-pdfviewer'; |
| 79 | + |
| 80 | +PdfViewer.Inject(Toolbar,Magnification,Navigation, Annotation, LinkAnnotation,ThumbnailView,BookmarkView, TextSelection); |
| 81 | + |
| 82 | +let pdfviewer: PdfViewer = new PdfViewer({ |
| 83 | + documentPath: 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf', |
| 84 | + resourceUrl: "https://cdn.syncfusion.com/ej2/31.1.23/dist/ej2-pdfviewer-lib", |
| 85 | + printEnd: (args: PrintEndEventArgs) => { |
| 86 | + console.log('Printed File Name: ' + args.fileName); |
| 87 | + } |
| 88 | +}); |
| 89 | +pdfviewer.appendTo('#PdfViewer'); |
| 90 | + |
| 91 | +{% endhighlight %} |
| 92 | +{% highlight ts tabtitle="Server-Backed" %} |
| 93 | + |
| 94 | +import { PdfViewer, PrintEndEventArgs, Toolbar, Magnification, Navigation, Annotation, LinkAnnotation,ThumbnailView,BookmarkView, TextSelection } from '@syncfusion/ej2-pdfviewer'; |
| 95 | + |
| 96 | +PdfViewer.Inject(Toolbar,Magnification,Navigation, Annotation, LinkAnnotation,ThumbnailView,BookmarkView, TextSelection); |
| 97 | + |
| 98 | +let pdfviewer: PdfViewer = new PdfViewer({ |
| 99 | + documentPath: 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf', |
| 100 | + serviceUrl: 'https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer/', |
| 101 | + printEnd: (args: PrintEndEventArgs) => { |
| 102 | + console.log('Printed File Name: ' + args.fileName); |
| 103 | + } |
| 104 | +}); |
| 105 | +pdfviewer.appendTo('#PdfViewer'); |
| 106 | + |
| 107 | +{% endhighlight %} |
| 108 | +{% endtabs %} |
0 commit comments