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.

Tue May 08, 2018 6:41 pm

I'm trying to add a table to an existing pdf, but no matter what I've tried, the table width will not extend past a certain point on the page. I've tried everything I could including setting the column width individually. No matter what, the table width won't extend.

If I start with a new PDF, the table width will fully extend to the width of the page.

Is there anything I can do to extend this table further?

jumper4000
 
Posts: 12
Joined: Thu Mar 01, 2018 11:46 pm

Wed May 09, 2018 2:07 am

Dear jumper4000,

Thanks for your inquiry.
We first suggest you use the latest Spire.PDF Pack(Hot Fix) Version:4.4.11 which includes all improvements. If the issue still exists after trying, please provide your input PDF and the code you were using for further investigation.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Wed May 09, 2018 9:03 pm

Hi, I installed the latest 4.4.11 version and I'm still running into the same issue. I'm not too sure, but I have a feeling, it has to do with adding a section to the existing page, and setting page size and margins. Hopefully you can figure it out. Here's a simplified version of my code -

Code: Select all
dfDocument doc = new PdfDocument();
            string strTemplatePath = @"Templates\Test.pdf";
            doc.LoadFromFile(strTemplatePath); 
            PdfPageBase page = doc.Pages[0];

            PdfTable table = new PdfTable();

            int iOrderNumber = 9949173;

            string connectionString = "Data Source=SQL;Initial Catalog=DB;Integrated Security=True";
            string detailQueryString = @"
                SELECT * FROM Test WHERE OrderNum = @iOrderNumber   
                ";

            SqlConnection SQLConn = new SqlConnection(connectionString);
            SqlCommand SQLCmd = new SqlCommand(detailQueryString, SQLConn);
            using (SQLConn = new SqlConnection(connectionString))
            {
                SQLCmd = new SqlCommand(detailQueryString, SQLConn);
                SQLCmd.Parameters.AddWithValue("@iOrderNumber", iOrderNumber);
                using (SqlDataAdapter dataAdapter = new SqlDataAdapter(SQLCmd))
                {
                    DataTable dataTable = new DataTable();
                    dataAdapter.Fill(dataTable);
                    table.DataSourceType = PdfTableDataSourceType.TableDirect;
                    table.DataSource = dataTable;
                }
            } 
            PdfLayoutResult result = table.Draw(page, new PointF(0, 400));

            string strFilePath = @"archive\test.pdf";
            doc.SaveToFile(strFilePath);
            doc.Close();
            PDFDocumentViewer(strFilePath);

jumper4000
 
Posts: 12
Joined: Thu Mar 01, 2018 11:46 pm

Thu May 10, 2018 2:56 am

Dear jumper4000,

Thanks for your code.
You guess is partially right, the cause of your issue is that there is 40 margin by default when loading a pdf. You could set the margin to "0", then the table width will cover the entire page.
Code: Select all
doc.PageSettings.Margins = new PdfMargins(0);

If there is any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Thu May 10, 2018 11:44 pm

Perfect. Thank you so much. That did it :)

jumper4000
 
Posts: 12
Joined: Thu Mar 01, 2018 11:46 pm

Fri May 11, 2018 1:50 am

Dear jumper4000,

Thanks for your feedback.
Any question, please feel free to contact us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.PDF

cron