Default toolbar icons are disappeared after first attempt
Hello, this is Tristan.
I have been working on PDFViewer2 to customize the primary toolbar with default options using Grid.
The code I provide is the combination of two documentations ("To customize PDF export" and "How to customize the Primary Toolbar with default options") with slight modifications.
https://blazor.syncfusion.com/documentation/datagrid/pdf-export#to-customize-pdf-export
I have noticed that when page was loaded, every thing looked good and I was able to see all 8 buttons (4 default and 4 customized buttons) in toolbar when I clicked "PDF Export" button first time. However, after close the dialog and clicked "PDF Export" again, there were only 4 customized buttons.
I do not know why the default options were disappeared after first attempt. I expect to have all 8 buttons every time I click "PDF Export". Can you investigate this issue?
Let me know if you have any question.
Thank you.
Attachment: Pdf_Viewer__Toolbar_3b6adb28.zip
Hi Tristan Kim,
Thank you for
reaching out to us. After further analysis, we found that the issue occurred
because the toolbar items were initialized only the first time. However, when
attempting to reopen the PDF Viewer, it failed due to improper initialization
of the toolbar items. To resolve this, please update the toolbar items in the
toolbar click handler of the grid component to ensure they are consistently
maintained each time the PDF Viewer is opened. Below, we have provided a code
snippet for your reference. Kindly review it and confirm whether it meets your
requirements.
Code Snippet:
|
pri { if (args.Item.Id == "Grid_pdfexport") { ToolbarItems = new List<Syncfusion.Blazor.SfPdfViewer.ToolbarItem>() { Syncfusion.Blazor.SfPdfViewer.ToolbarItem.OpenOption, Syncfusion.Blazor.SfPdfViewer.ToolbarItem.SelectionTool, Syncfusion.Blazor.SfPdfViewer.ToolbarItem.SearchOption, Syncfusion.Blazor.SfPdfViewer.ToolbarItem.PrintOption }; await ExportDialog.ShowAsync();
FileName = $"test.pdf";
using (MemoryStream pdfStream = await DefaultGrid.ExportToPdfAsync(true, PdfExportProperties)) { byte[] byteArray = pdfStream.ToArray(); string base64String = Convert.ToBase64String(byteArray); DocumentPath = "data:application/pdf;base64," + base64String; }
StateHasChanged(); } } |
Regards,
Sathiyaseelan K
Thank you Sathiyaseelan.
I have verified your suggestion works.
However, it is a bit confusing why values of ToolbarItems are cleared whereas ones of CustomToolbarItems are persisted. I expect values of both ToolbarItems and CustomToolbarItems remain as-is, since they are fields of the component and I do not change any values after initialization,.
Can you explain why it behaves like this?
Thank you very much.
Hi Tristan Kim,
Thank
you for the update. Since you added the toolbar and declared it initially, it
updates correctly the first time the PDF Viewer is opened in a dialog. When the
PDF Viewer is opened for the first time, the entire component is rendered.
However, when the dialog is closed, the PDF Viewer component is destroyed. When
reopening the dialog, the entire component does not render again, causing the
toolbar items to be set to null. To avoid this issue, please update the toolbar
items before opening the PDF Viewer dialog.
Regards,
Sathiyaseelan K
- 3 Replies
- 2 Participants
- Marked answer
-
TK Tristan Kim
- Mar 12, 2025 09:20 PM UTC
- Mar 14, 2025 02:58 PM UTC