Print events in Blazor PDF Viewer
17 Jul 20264 minutes to read
This page lists each event emitted by the Blazor PDF Viewer’s print feature, the argument schema, and the minimal usage notes.
Events
| Name | Description |
|---|---|
| PrintStart | Raised when a print operation begins. Use the event to log activity or cancel printing. |
| PrintEnd | Raised after a print operation completes. Use the event to notify users or clean up resources. |
PrintStart
The PrintStart event triggers when a print operation begins.
Event arguments
The PrintStartEventArgs exposes the following members:
| Property | Type | Description |
|---|---|---|
FileName |
string |
The name of the PDF file being printed. |
Cancel |
bool |
Set to true to cancel the print operation and prevent the print dialog from opening. |
- If the
Cancelproperty is set totruein thePrintStartevent handler, the print operation is canceled and the print dialog does not open. - By default,
Cancelisfalse.
The following example illustrates how to handle the PrintStart event.
@using Syncfusion.Blazor.SfPdfViewer
<SfPdfViewer2 DocumentPath="@DocumentPath" Height="100%" Width="100%">
<PdfViewerEvents PrintStart="@PrintStart"></PdfViewerEvents>
</SfPdfViewer2>
@code{
private string DocumentPath { get; set; } = "wwwroot/Data/PDF_Succinctly.pdf";
private async Task PrintStart(PrintStartEventArgs args)
{
Console.WriteLine($"Printed File Name: {args.FileName}");
}
}The following example shows how to cancel the print operation from the PrintStart handler.
PrintEnd
The PrintEnd event triggers when a print operation completes.
Event arguments
The PrintEndEventArgs exposes the following member:
| Property | Type | Description |
|---|---|---|
FileName |
string |
The name of the PDF file that was printed. |
The following example illustrates how to handle the PrintEnd event.
@using Syncfusion.Blazor.SfPdfViewer
<SfPdfViewer2 DocumentPath="@DocumentPath" Height="100%" Width="100%">
<PdfViewerEvents PrintEnd="@PrintEnd"></PdfViewerEvents>
</SfPdfViewer2>
@code{
private string DocumentPath { get; set; } = "wwwroot/Data/PDF_Succinctly.pdf";
private async Task PrintEnd(PrintEndEventArgs args)
{
Console.WriteLine($"Printed File Name: {args.FileName}");
}
}The following example shows how to handle both PrintStart and PrintEnd together.
@using Syncfusion.Blazor.SfPdfViewer
<SfPdfViewer2 DocumentPath="@DocumentPath" Height="100%" Width="100%">
<PdfViewerEvents PrintStart="@OnPrintStart" PrintEnd="@OnPrintEnd"></PdfViewerEvents>
</SfPdfViewer2>
@code{
private string DocumentPath { get; set; } = "wwwroot/Data/PDF_Succinctly.pdf";
private async Task OnPrintStart(PrintStartEventArgs args)
{
Console.WriteLine($"Print started: {args.FileName}");
}
private async Task OnPrintEnd(PrintEndEventArgs args)
{
Console.WriteLine($"Print completed: {args.FileName}");
}
}View the print sample on GitHub