How can I help you?
Print events in Typescript PDF Viewer
17 Feb 20265 minutes to read
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. |
printStart event
The printStart event runs when printing starts from the toolbar or from code. Use it to validate prerequisites or cancel the action.
Event arguments
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.
NOTE
Setting
args.cancel = trueprevents 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.
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');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');printEnd event
The printEnd event triggers after printing completes. Use it to finalize analytics or inform users that printing finished.
Event arguments
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.
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');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');