Skip to content

Latest commit

 

History

History
126 lines (92 loc) · 5.25 KB

File metadata and controls

126 lines (92 loc) · 5.25 KB
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 Print
documentation ug
domainurl

Print events in Typescript PDF Viewer

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 to true to 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 %}

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.

{% 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 %}

See Also