Export to PDF/Excel not working for Android and iOs mobile application

I tried to export PDF/Excel using demo link mentioned below here.

Blazor DataGrid Advanced Exporting Example - Syncfusion Demos

Code as per attached link works successfully for windows application and web browser but it does not work for mobile application for android and iOS.

Please do the needful.

Thank you.




3 Replies

PS Prathap Senthil Syncfusion Team November 8, 2023 01:27 PM UTC

Hi Amish

Based on the reported issue, we recommend using the Excel and PDF export solutions below to solve this problem. Please see the code snippet and example code below for reference.


  public async Task ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args)

  {

      if (args.Item.Id == "Grid_excelexport") //Id is combination of Grid's ID and itemname

      {

          using (ExcelEngine excelEngine = new ExcelEngine())

          {

              IApplication application = excelEngine.Excel;

              application.DefaultVersion = ExcelVersion.Excel2013;

              IWorkbook workbook = application.Workbooks.Create(1);

              IWorksheet worksheet = workbook.Worksheets[0];

              IList<Order> reports = Orders; // pass the datasoruce

              worksheet.ImportData(reports, 1, 1, true);

              MemoryStream stream = new MemoryStream();

              workbook.SaveAs(stream);

             

              await Runtime.InvokeVoidAsync("saveAsFile", new object[] { "export.xlsx", Convert.ToBase64String(stream.ToArray()) });

 

          }

      }

      if (args.Item.Id == "Grid_pdfexport")

      {

          PdfDocument pdfDocument = new PdfDocument();

          PdfPage pdfPage = pdfDocument.Pages.Add();

          //Create a new PdfGrid.

          PdfGrid pdfGrid = new PdfGrid();

          pdfGrid.Columns.Add(DefaultGrid.Columns.Count);

 

          PdfGridRow[] headerRow = pdfGrid.Headers.Add(1);

          var GridColHeader = DefaultGrid.Columns.Select(x => x.HeaderText).ToList();

          for (var i = 0; i < DefaultGrid.Columns.Count; i++)

          {

              headerRow[0].Cells[i].Value = GridColHeader[i];

          }

          // Add Rows to the grid based/using on Grid's DataSource

          for (int i = 0; i < Orders.Count; i++)

          {

              PdfGridRow row = pdfGrid.Rows.Add();

              //assign cells based on grid's columns

              row.Cells[0].Value = Orders[i].OrderID.ToString();

              row.Cells[1].Value = Orders[i].CustomerID;

              row.Cells[2].Value = Orders[i].OrderDate.ToString();

              row.Cells[3].Value = Orders[i].Freight.ToString();

          }

          //enable repeating grid column header in each page

          pdfGrid.RepeatHeader = true;

          //Draw the PdfGrid.

          pdfGrid.Draw(pdfPage, new PointF(0, 0));

          MemoryStream stream = new MemoryStream();

          pdfDocument.Save(stream);

          //Close the document

          pdfDocument.Close(true);

 

          await Runtime.InvokeVoidAsync("saveAsFile", new object[] { "output.pdf", Convert.ToBase64String(stream.ToArray()) });

 

 

      }

  }

function
saveAsFile(filename, bytesBase64) {

 

 

 

    if (navigator.msSaveBlob) {

 

        //Download document in Edge browser

 

        var data = window.atob(bytesBase64);

 

        var bytes = new Uint8Array(data.length);

 

        for (var i = 0; i < data.length; i++) {

 

            bytes[i] = data.charCodeAt(i);

 

        }

 

        var blob = null;

 

        if (filename.endsWith(".pdf"))

 

            blob = new Blob([bytes.buffer], { type: "application/pdf" });

 

        else if (filename.endsWith(".xlsx"))

 

            blob = new Blob([bytes.buffer], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });

 

        navigator.msSaveBlob(blob, filename);

 

    }

 

    else {

 

        var link = document.createElement('a');

 

        link.download = filename;

 

        if (filename.endsWith(".pdf"))

 

            link.rel='nofollow' href = "data:application/pdf;base64," + bytesBase64;

 

        else if (filename.endsWith(".xlsx"))

 

            link.rel='nofollow' href = "data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64," + bytesBase64;

 

        document.body.appendChild(link); // Needed for Firefox

 

        link.click();

 

        document.body.removeChild(link);

 

    }

 

}

 



Regards,
Prathap S


Attachment: DataGridExport_72c9aea4.zip


KS Kumaresan Subramani November 26, 2023 05:37 AM UTC

Hi team, 


Facing same issue in EJ2 angular too.


any possible solution, we are using latest angular package.


Thanks.



HS Hemanthkumar S Syncfusion Team November 30, 2023 07:22 AM UTC

Hi Kumaresan Subramani,


Greetings from Syncfusion support.


Before we proceed with providing a solution, we need some information to better understand the issue you are facing. Please provide us with the following details:


  1. Provide a detailed description of the issue you are currently facing and what your expected scenario is. This will help us better understand the problem and provide an appropriate solution.
  2. Are you encountering any script errors? If so, provide an image or description of the script error, as it will assist us in identifying the cause of the issue.
  3. Share the complete code for rendering the Grid. Having the full code will allow us to review the implementation and potentially identify any issues or suggest improvements.
  4. Provide the version of the Syncfusion package that you are using.
  5. Sharing a video or screenshot demonstration would greatly assist us in better understanding your query. It would allow us to visualize the problem and provide more precise guidance or suggestions.
  6. Share the reproducible sample or hosted link that showcases the issue. Having a sample or hosted link will enable us to directly analyze and validate the problem, which can lead to a faster resolution.
  7. If possible, try to replicate the issue with the help of the below-attached sample.

https://stackblitz.com/edit/angular-a23rpz?file=src%2Fapp.component.ts,src%2Fapp.component.html


We appreciate your cooperation in providing us with the requested information, as it will help us provide a more effective solution to your query.


Regards,

Hemanth Kumar S


Loader.
Up arrow icon