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.

Sun May 02, 2021 5:34 am

Hi,
Can you please advice how to make column text like bellow image

pdf.png


Thanks

kuntal.bose
 
Posts: 20
Joined: Thu Apr 29, 2021 6:05 am

Mon May 03, 2021 6:10 am

Hello,

Thanks for your inquiry.
Please refer to the following code to meet your needs. If you have any other questions, please feel free to contact us.
Code: Select all
            PdfDocument doc = new PdfDocument();
            PdfPageBase page = doc.Pages.Add();
            PdfGrid grid = new PdfGrid();
            grid.Columns.Add(7);
            float width = page.Canvas.ClientSize.Width;

            grid.Style.CellPadding = new PdfPaddings(0, 0, 0, 0);

            PdfGridRow pdfGridRow = grid.Rows.Add();
            pdfGridRow.Height = 30;

            grid.Columns[0].Width = width * 0.03f;
            grid.Columns[1].Width = width * 0.43f;
            grid.Columns[2].Width = width * 0.08f;
            grid.Columns[3].Width = width * 0.23f;
            grid.Columns[4].Width = width * 0.09f;
            grid.Columns[5].Width = width * 0.05f;
            grid.Columns[6].Width = width * 0.09f;
            pdfGridRow.Cells[0].Value = "SI";
            pdfGridRow.Cells[1].Value = "Description of Goods";
            pdfGridRow.Cells[2].Value = "HSN/SAC";
            pdfGridRow.Cells[4].Value = "Rate";
            pdfGridRow.Cells[5].Value = "Disc%";
            pdfGridRow.Cells[6].Value = "Amount";

            PdfGrid embedgrid = new PdfGrid();
            embedgrid.Style.CellPadding = new PdfPaddings(0, 0, 0, 0);
            embedgrid.Columns.Add();

            PdfGridRow pdfembedGridRow = embedgrid.Rows.Add();

            pdfembedGridRow.Cells[0].Value = "Quantity";
            pdfembedGridRow = embedgrid.Rows.Add();

            PdfGrid embedgrid2 = new PdfGrid();
            embedgrid2.Columns.Add(2);
            PdfGridRow pdfGridRow2 = embedgrid2.Rows.Add();
            pdfGridRow2.Cells[0].Value = "Shipped";
            pdfGridRow2.Cells[1].Value = "Billed";

            pdfembedGridRow.Cells[0].Value = embedgrid2;
            pdfGridRow.Cells[3].Value = embedgrid;

            embedgrid2.Columns[0].Width = grid.Columns[3].Width / 2;
            embedgrid2.Columns[1].Width = grid.Columns[3].Width / 2;
            embedgrid2.Rows[0].Height = grid.Rows[0].Height / 2;
            embedgrid.Columns[0].Width = grid.Columns[3].Width;
            embedgrid.Rows[0].Height = grid.Rows[0].Height / 2;
            embedgrid.Rows[1].Height = grid.Rows[0].Height / 2;

            foreach (PdfGridRow row in grid.Rows)
            {
                foreach (PdfGridCell cell in row.Cells)
                {
                    cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Top);
                }
            }
            embedgrid.Rows[0].Cells[0].StringFormat.Alignment = PdfTextAlignment.Center;
            embedgrid2.Rows[0].Cells[0].StringFormat.Alignment = PdfTextAlignment.Center;
            embedgrid2.Rows[0].Cells[1].StringFormat.Alignment = PdfTextAlignment.Center;
            PdfLayoutResult result = grid.Draw(page, new PointF(0, 40));

            doc.SaveToFile("result2.pdf");


Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Sat May 08, 2021 7:23 am

Hello,

Greetings from E-iceblue!
Did the code we provided work for you? Could you please give us some feedback at your convenience?

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Sun May 09, 2021 3:34 pm

Hello
Sorry for delayed reply,Due to some other work not able to check the code yet .I will let you know after check.
Thanks

kuntal.bose
 
Posts: 20
Joined: Thu Apr 29, 2021 6:05 am

Mon May 10, 2021 1:11 am

Hello,

Thanks for your response.
I am looking forward to your test result. If you encounter any questions during your test, just feel free to contact us.

Sincerely
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.PDF