| layout | post |
|---|---|
| title | Print Events in TypeScript PDF Viewer | Syncfusion |
| description | Learn how to configure print events and track usage and implements workflows in the Syncfusion TypeScript PDF Viewer component. |
| platform | document-processing |
| control | |
| documentation | ug |
| domainurl |
Subscribe to print lifecycle events to track usage and implement custom workflows.
| Name | Description |
|---|---|
printStart |
Raised when a print action begins. Use the event to log activity or cancel printing. |
printEnd |
Raised after a print action completes. Use the event to notify users or clean up resources. |
The printStart event runs when printing starts from the toolbar or from code. Use it to validate prerequisites or cancel the action.
Common properties:
fileName: Name of the document being printed.cancel(boolean): Set totrueto cancel the print operation.
Review PrintStartEventArgs for details such as fileName and the cancel option.
N> Setting args.cancel = true prevents the print action and, depending on the environment, prevents the print dialog from appearing. In server-backed printing, cancellation prevents the service call that generates print output.
The following example logs the file that is being printed and shows how to cancel the operation.
{% tabs %} {% highlight ts tabtitle="Standalone" %}
import { PdfViewer, PrintStartEventArgs, Toolbar, Magnification, Navigation, Annotation, LinkAnnotation,ThumbnailView,BookmarkView, TextSelection } from '@syncfusion/ej2-pdfviewer';
PdfViewer.Inject(Toolbar,Magnification,Navigation, Annotation, LinkAnnotation,ThumbnailView,BookmarkView, TextSelection);
let pdfviewer: PdfViewer = new PdfViewer({ documentPath: 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf', resourceUrl: "https://cdn.syncfusion.com/ej2/31.1.23/dist/ej2-pdfviewer-lib", printStart: (args: PrintStartEventArgs) => { console.log('Print action has started for file: ' + args.fileName); // To cancel the print action // args.cancel = true; } }); pdfviewer.appendTo('#PdfViewer');
{% endhighlight %} {% highlight ts tabtitle="Server-Backed" %}
import { PdfViewer, PrintStartEventArgs, Toolbar, Magnification, Navigation, Annotation, LinkAnnotation,ThumbnailView,BookmarkView, TextSelection } from '@syncfusion/ej2-pdfviewer';
PdfViewer.Inject(Toolbar,Magnification,Navigation, Annotation, LinkAnnotation,ThumbnailView,BookmarkView, TextSelection);
let pdfviewer: PdfViewer = new PdfViewer({ documentPath: 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf', serviceUrl: 'https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer/', printStart: (args: PrintStartEventArgs) => { console.log('Print action has started for file: ' + args.fileName); // To cancel the print action // args.cancel = true; } }); pdfviewer.appendTo('#PdfViewer');
{% endhighlight %} {% endtabs %}
The printEnd event triggers after printing completes. Use it to finalize analytics or inform users that printing finished.
Common properties:
fileName: Name of the document that was printed.
See PrintEndEventArgs for available values such as fileName.
The following example logs the printed file name.
{% tabs %} {% highlight ts tabtitle="Standalone" %}
import { PdfViewer, PrintEndEventArgs, Toolbar, Magnification, Navigation, Annotation, LinkAnnotation,ThumbnailView,BookmarkView, TextSelection } from '@syncfusion/ej2-pdfviewer';
PdfViewer.Inject(Toolbar,Magnification,Navigation, Annotation, LinkAnnotation,ThumbnailView,BookmarkView, TextSelection);
let pdfviewer: PdfViewer = new PdfViewer({ documentPath: 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf', resourceUrl: "https://cdn.syncfusion.com/ej2/31.1.23/dist/ej2-pdfviewer-lib", printEnd: (args: PrintEndEventArgs) => { console.log('Printed File Name: ' + args.fileName); } }); pdfviewer.appendTo('#PdfViewer');
{% endhighlight %} {% highlight ts tabtitle="Server-Backed" %}
import { PdfViewer, PrintEndEventArgs, Toolbar, Magnification, Navigation, Annotation, LinkAnnotation,ThumbnailView,BookmarkView, TextSelection } from '@syncfusion/ej2-pdfviewer';
PdfViewer.Inject(Toolbar,Magnification,Navigation, Annotation, LinkAnnotation,ThumbnailView,BookmarkView, TextSelection);
let pdfviewer: PdfViewer = new PdfViewer({ documentPath: 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf', serviceUrl: 'https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer/', printEnd: (args: PrintEndEventArgs) => { console.log('Printed File Name: ' + args.fileName); } }); pdfviewer.appendTo('#PdfViewer');
{% endhighlight %} {% endtabs %}