We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Customize Pdf on export called from ToolBar item

Hello Support Team,

i'm experimenting currently with your pivot tables. I checked your examples for esspecially for exporting and i am wondering why all examples of exporting and customizing the output files (ecxel,csv,pdf) are triggered from a external Button. I'd like to use the "internal" toolbar export button for export and want to customize it, like we can do it in grids.

Could you show me a tiny example how to customize a pdf export when using the toolbar export item?

Regards

Stefan


1 Reply

RG Rajeshkannah G Syncfusion Team January 30, 2023 01:54 PM UTC

Hi Stefan,


Please find the response below.


Query

Comments

 I checked your examples for especially for exporting and I am wondering why all examples of exporting and customizing the output files are triggered from an external Button. I'd like to use the "internal" toolbar export button for export and want to customize it, like we can do it in grids.

We have built-in toolbar menu option for PDF, Excel and CSV exporting, you can use it by setting AllowPdfExport and AllowExcelExport as true and adding Enum value “Export” to toolbar items. Furthermore, by using the BeforeExport event, you can customize the PDF or Excel export properties before exporting them.

 

Code Example:

<SfPivotView @ref="pivot" TValue="ProductDetails" ShowToolbar="true" AllowExcelExport="true" AllowPdfExport="true" Toolbar="@toolbar" >   

    <PivotViewEvents TValue="ProductDetails" BeforeExport="beforeExport”></PivotViewEvents>

</SfPivotView>

 

 

@code{

    private SfPivotView<ProductDetails> pivot;

    

    private List<Syncfusion.Blazor.PivotView.ToolbarItems> toolbar = new   List<Syncfusion.Blazor.PivotView.ToolbarItems>{

        Syncfusion.Blazor.PivotView.ToolbarItems.Grid,

        Syncfusion.Blazor.PivotView.ToolbarItems.Export

    };

    public void beforeExport(BeforeExportEventArgs args)

    {    

      //To change PdfExportProperties     

        PdfExportProperties exportProperties = new PdfExportProperties(){FileName= "PivotSample" };

        args.PdfExportProperties = exportProperties;

      //To change ExcelExportProperties

        ExcelExportProperties excelProperties = new ExcelExportProperties() { FileName = "PivotSample" };        

        args.ExcelExportProperties = excelProperties;     

                

    }

 

 

Output Screenshot:

 

To know more about “BeforeExport” event , please look at UG document below.

 

UG Document: https://blazor.syncfusion.com/documentation/pivot-table/tool-bar#beforeexport

 

Meanwhile we have prepared a sample for your reference.

 

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/PivotTable-825787215

 

Could you show me a tiny example how to customize a pdf export when using the custom toolbar export item?

You can use the ToolbarRendered event to add a custom toolbar item for PDF export and customize the PDF export properties while exporting with an external button click.

 

Code Example:

<SfPivotView @ref="pivot" TValue="ProductDetails" ShowToolbar="true" AllowExcelExport="true" AllowPdfExport="true" Toolbar="@toolbar" >   

    <PivotViewEvents TValue="ProductDetails" ToolbarRendered="toolbarRendered></PivotViewEvents>

</SfPivotView>

 

 

@code{

    private SfPivotView<ProductDetails> pivot;

     private void toolbarRendered(ToolbarArgs args)

    {

 

        args.CustomToolbar.Add(new ItemModel

        {

            Text = "ExcelExport",

            TooltipText = "Excel-Export",

            Click = EventCallback.Factory.Create<ClickEventArgs>(this, export)

        });

    }

   

    public async void export(ClickEventArgs args)

    {

        //To customize PDF export properties

        Syncfusion.Blazor.Grids.PdfExportProperties pdfExportProperties = new Syncfusion.Blazor.Grids.PdfExportProperties()          

         { FileName = "sample.pdf" };

        await this.pivot.ExportToPdfAsync(pdfExportProperties);

 

    }

 

Output Screenshot:

 

Table

Description automatically generated

To know more about “ToolbarRendered” event , please look at UG document below.

 

UG Document: https://blazor.syncfusion.com/documentation/pivot-table/events#toolbarrendered

 

Meanwhile we have prepared a sample for your reference.

 

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/PivotTable-825787215

 


Please let us know if you have any concerns.


Regards,

Rajeshkannah G


Loader.
Up arrow icon