locked
How to place two tables side by side in pdf, in c# RRS feed

  • Question

  • User596010427 posted

    How to place two tables side by side in pdf.Can we add two html tables  side by side using CSS  and then convert the output in pdf format.I tried doing it with iTextSharp , but it seems CSS is not supporting properly.Plaese suggest solution or other methods.

    Monday, March 20, 2017 8:49 AM

All replies

  • Monday, March 20, 2017 2:55 PM
  • User426857743 posted

    Hi,

    You can take a look at Free Spire.PDF. It allows converting from html to pdf, image to pdf, pdf to image etc..

    https://www.nuget.org/packages/FreeSpire.PDF/

    Tuesday, March 21, 2017 6:45 AM
  • User-1599850035 posted

    Try this

    using Spire.Pdf.Grid;
    using Spire.Pdf;
    
    namespace CreatePdfTable
    {
        class Program
        {
            static void Main(string[] args)
            {
                //create document
                PdfDocument doc = new PdfDocument();
                PdfPageBase page = doc.Pages.Add();
    
                //create a 2x2 grid and draw it at (10, 10)
                PdfGrid grid1 = new PdfGrid();
                grid1.Columns.Add(2);
                grid1.Rows.Add();
                grid1.Rows.Add();
                foreach (var row in grid1.Rows)
                {
                    row.Height = 12f;
                }
                foreach (PdfGridColumn col in grid1.Columns)
                {
                    col.Width = 50f;
                }
                grid1.Draw(page.Canvas, 10, 10);
    
                //create another 2x2 grid and draw it at (120, 10)
                PdfGrid grid2 = new PdfGrid();
                grid2.Columns.Add(2);
                grid2.Rows.Add();
                grid2.Rows.Add();
                foreach (var row in grid2.Rows)
                {
                    row.Height = 12f;
                }
                foreach (PdfGridColumn col in grid2.Columns)
                {
                    col.Width = 50f;
                }
                grid2.Draw(page.Canvas,120,10);
    
                //save
                doc.SaveToFile("Create_Two_Table.pdf");
            }
        }
    }

    Tuesday, March 21, 2017 7:44 AM