Draw table in PDF using skiasharp

Gayatri Gokhale 1 Reputation point
2021-01-19T11:27:26.86+00:00

Hello,

I am using skiasharp plugin to create pdf for android and ios both. I am able to create simple pdf provided in the sample but actually I want is table like structure inside pdf. I am not able to find how to insert table in skiasharp library.

I have done it before for android using iTextSharp plugin but this time I want to do it for iOS also. So finding cross-platform solution.

Anybody did that before ?

Best Regards,
Gayatri

Developer technologies .NET Xamarin
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Ángel Rubén Valdeolmos Carmona 611 Reputation points
    2021-01-19T14:27:12.287+00:00

    Some time ago I wanted to do something similar to "embed a signature". What I end up doing is creating my pdf layout in html (tables and embedded signature) from my server and then displaying it in the application. There are many libraries in .net that convert it from html to pdf. If you don't want the server option, you can have in your app an html template for creating the pdf and then read it using File.ReadAllText and create your pdf layout using html.

    Here you have two links to do it from the server (.net core)
    https://github.com/webgio/Rotativa.AspNetCore
    https://code-maze.com/create-pdf-dotnetcore/

    if you opt for the html embedded in your application, you can use a .net library. You can try
    https://github.com/empira/PDFsharp


  2. Ángel Rubén Valdeolmos Carmona 611 Reputation points
    2021-01-22T07:27:31.143+00:00

    I don't know what dynamic data it can have, but for example in my use case: I have a static header and a logo with the table fields as well, for example: company, vendors, etc. And it works for multiple pages

    and I have a div with id "body" then I open the html using File.ReadAllText and I look for that div and start creating the dynamic html with the data for example:

    string htmlContent = File.ReadAllText(ConfigurationSettings.AppSettings["plantilla"]);
             var html = htmlContent.Substring(0, htmlContent.IndexOf("<div id"));
             html += "<h1>Title</h1>" +
                 $"<h1>PERIODO {pdfViewModel.InitialDate.Substring(0, 10)} - {pdfViewModel.FinalDate.Substring(0, 10)}</h1>" +
                 "<h1>" + pdfViewModel.Grupo + "</h1>";
             var htmlAffter = htmlContent.Substring((htmlContent.IndexOf("</div>") + 6), (htmlContent.Length - (htmlContent.IndexOf("</div>") + 6)));
             htmlContent = html + htmlAffter;
             html = htmlContent.Substring(0, htmlContent.IndexOf("<tr id="));
    
           foreach (var logEmpresa in pdfViewModel.LogEmpresas)
                     {
                         html += "<tr>" +
                                         "<td>" + logEmpresa.Empresa + "</td>" +
                                         "<td>" + logEmpresa.Modulo + "</td>" +
                                         "<td>" + logEmpresa.Usuario.ToString("N0") + "</td>" +
                                         "<td>" + logEmpresa.Transaciones.ToString("N0") + "</td>" +
                                 "</tr>";
                     }
    
             html += @"</table></div></body></html>";
             return html;
             }
            PdfDocument doc = new PdfDocument();
    
         PdfDocument pdf = PdfGenerator.GeneratePdf(html, PageSize.A4);
    
         pdf.Save(path);
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.