Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Thu Jan 17, 2013 12:22 pm

I often need to have a cell merge with other cells to the right or down into other rows but can not find any examples of this. It looks like this can be done when using Word tables. Also, can you explain the differences between the grid and table in PDF. Many thanks

msutherland25
 
Posts: 1
Joined: Fri Jan 11, 2013 6:33 pm

Fri Jan 18, 2013 6:19 am

Hello,

Thanks for your inquiry.
For merge cells problem, we provide you some sample code, please try the code below. And you can refer to Grid demo in spire.pdf component. Please download Spire.PDF Pack Version:2.6( the download link is http://www.e-iceblue.com/Download/download-pdf-for-net-now/spirepdf-pack.html?Itemid=0) and install it in your computer. Please open Start menu->Programs->e-iceblue->Spire.PDF->Demos->CSDemos-VS2010, under WinForms/06_Grid/Grid-VS2010 project after finish the installing.

In Spire.PDF, Table is a special Grid. But it is more simple to use and especially to import data from DataSource. In Table, we cant manipulate the cell, we cant insert another table into one cell, but we can set the style by row. In Grid, we can manipulate each cell, set different style for every cell and embed another Grid.

If we miss something or you have other problem, please tell us.
Code: Select all
            PdfDocument doc = new PdfDocument();
            PdfPageBase page = doc.Pages.Add();

            PdfGrid grid = new PdfGrid();

            grid.Columns.Add(5);
            float width = page.Canvas.ClientSize.Width - (grid.Columns.Count + 1);
            for (int i = 0; i < grid.Columns.Count; i++)
            {
                grid.Columns[i].Width = width * 0.20f;
            }

            PdfGridRow row0 = grid.Rows.Add();
            PdfGridRow row1 = grid.Rows.Add();

            row0.Style.Font = new PdfTrueTypeFont(new Font("Arial",16f,FontStyle.Bold),true);
            row1.Style.Font = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Italic), true);

            row0.Cells[0].Value = "Corporation";
            row0.Cells[0].RowSpan = 2;

            row0.Cells[1].Value = "B&K Undersea Photo";
            row0.Cells[1].StringFormat=new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            row0.Cells[1].ColumnSpan = 3;

            row0.Cells[4].Value = "World";
            row0.Cells[4].Style.Font = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold | FontStyle.Italic), true);
            row0.Cells[4].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            row0.Cells[4].Style.BackgroundBrush = PdfBrushes.LightGreen;
         
             
            row1.Cells[1].Value = "Diving International Unlimited";
            row1.Cells[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            row1.Cells[1].ColumnSpan = 4;

            grid.Draw(page, new PointF(0, 0));

            doc.SaveToFile("sample.pdf");


Best regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Tue Jan 22, 2013 7:53 am

Hello,

Did the solution solve your problem? If you still have the problem, please tell us.

Best regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Fri Jan 25, 2013 9:36 am

Hello,

Please feel free to contact us if you need any assistance about our products.

Thanks & Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDF