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 Mar 31, 2022 10:40 am

How can I create a horizontal table in a pdf. This means:
column1 : data
column2 : data2
column3 : data3 ... and so on
and not:
column1 column2 column3
data data2 data3
thank you

ivster.4
 
Posts: 6
Joined: Thu Mar 31, 2022 10:34 am

Fri Apr 01, 2022 9:00 am

Hi,

Thank you for your inquiry.
You could use the code below to implement your requirements.
Code: Select all
 
            PdfDocument doc = new PdfDocument();
            PdfPageBase page = doc.Pages.Add();
            String[] data  = {
                "column1;data1",
                "column2;data2",
                "column3;data3",
            };
            String[][] dataSource = new String[data.Length][];
            for (int i = 0; i < data.Length; i++)
            {
                dataSource[i] = data[i].Split(';');
            }

           PdfTable table = new PdfTable();     
           table.DataSource = dataSource;
           table.BeginRowLayout += Table_BeginRowLayout;
           table.Draw(page, new RectangleF(0, 20, 200, 90));
           doc.SaveToFile("result.pdf");
           doc.Close();
        }
        private static void Table_BeginRowLayout(object sender, BeginRowLayoutEventArgs args)
        {
            args.MinimalHeight = 20f;
        }


In addition, we provide the two instances (PdfGrid and PdfTable) to create tables, you can refer to the tutorials on our website:
Generate PDF Table
Generate Pdf Grid
If you have any questions, please feel free to contact us.

Sincerely,
Kylie
E-iceblue support team
User avatar

kylie.tian
 
Posts: 412
Joined: Mon Mar 07, 2022 2:30 am

Fri Jul 01, 2022 5:45 am

Hi,

Greetings from E-iceblue!
Did the code I provided help you? Could you give us some feedback at your convenience?

Sincerely,
Kylie
E-iceblue support team
User avatar

kylie.tian
 
Posts: 412
Joined: Mon Mar 07, 2022 2:30 am

Return to Spire.PDF