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 Dec 01, 2013 11:00 pm

How can I prevent text wrapping within a table? It would be nice if the text didn't appear on multiple lines. To achieve this it would sometimes require the table to be 2 pages wide. Is this possible as well?
Image

will.marriott
 
Posts: 27
Joined: Thu Oct 24, 2013 9:47 pm

Mon Dec 02, 2013 7:37 am

Hello Will,

Sorry for late reply as weekend. Thanks for your inquiry.
Regarding your issue, you could only set the width of the Pdf page to prevent text wrapping within a table. Please refer to the following code.
Code: Select all
PdfDocument doc = new PdfDocument();
            PdfSection sec = doc.Sections.Add();
            sec.PageSettings.Width=PdfPageSize.A4.Width * 2;//set the page size according to your need or calculating
            PdfPageBase page = sec.Pages.Add();
            float y = 10;
            PdfBrush brush1 = PdfBrushes.Black;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString("Country List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Country List", format1).Height;
            y = y + 5;

            String[] data
                = {
                    "Name;Capital;Continent;Area;Population;Name;Capital;Continent;Area;Population;Name;Capital;Continent;Area;Population;Name;Capital;Continent;Area",
                    "Argentina;Buenos Aires;South America;2777815;32300003;Argentina;Buenos Aires;South America;2777815;32300003;Argentina;Buenos Aires;South America;2777815;32300003;Argentina;Buenos Aires;South America;2777815",
                    "Argentina;Buenos Aires;South America;2777815;32300003;Argentina;Buenos Aires;South America;2777815;32300003;Argentina;Buenos Aires;South America;2777815;32300003;Argentina;Buenos Aires;South America;2777815",
                    "Argentina;Buenos Aires;South America;2777815;32300003;Argentina;Buenos Aires;South America;2777815;32300003;Argentina;Buenos Aires;South America;2777815;32300003;Argentina;Buenos Aires;South America;2777815",
                    "Argentina;Buenos Aires;South America;2777815;32300003;Argentina;Buenos Aires;South America;2777815;32300003;Argentina;Buenos Aires;South America;2777815;32300003;Argentina;Buenos Aires;South America;2777815",
                    "Argentina;Buenos Aires;South America;2777815;32300003;Argentina;Buenos Aires;South America;2777815;32300003;Argentina;Buenos Aires;South America;2777815;32300003;Argentina;Buenos Aires;South America;2777815",
                    "Argentina;Buenos Aires;South America;2777815;32300003;Argentina;Buenos Aires;South America;2777815;32300003;Argentina;Buenos Aires;South America;2777815;32300003;Argentina;Buenos Aires;South America;2777815"
                };

            String[][] dataSource
                = new String[data.Length][];
            for (int i = 0; i < data.Length; i++)
            {
                dataSource[i] = data[i].Split(';');
            }

            PdfTable table = new PdfTable(); 
            table.Style.HeaderSource = PdfHeaderSource.Rows;
            table.Style.HeaderRowCount = 1;
            table.Style.ShowHeader = true;
            table.DataSource = dataSource;
            PdfLayoutResult result = table.Draw(page, new PointF(0, y));
            doc.SaveToFile("SimpleTable.pdf");
            doc.Close();

If there are any questions, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Wed Dec 04, 2013 8:39 am

Hello Will,

Has the issue been resolved? Could you please give us some feedback if convenience?

If there are any questions, welcome to get it back to us.

Thanks And Regards,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Sun Jan 05, 2014 10:21 pm

This is not ideal. The last export library I used automatically sized the table and exported two or more pages wide if required.

will.marriott
 
Posts: 27
Joined: Thu Oct 24, 2013 9:47 pm

Mon Jan 06, 2014 9:06 am

Hello Will,

Thanks for your feedback.
Sorry that at present our Spire.Pdf product doesn't support the feature that column width automatically adjusts to the text in table.
If there are any questions, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Return to Spire.PDF