PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Aug 13, 2020 2:32 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Thu Jul 30, 2020 6:19 pm 
Offline

Joined: Thu Jul 30, 2020 6:08 pm
Posts: 2
Hi, so trying to render a PDF that includes a Table.

Here is the Header of the Table, no issue with this:

Code:
 // def header of table

            MigraDoc.DocumentObjectModel.Tables.Row row = table.AddRow();
            MigraDoc.DocumentObjectModel.Tables.Cell cell = row.Cells[0];
            cell.AddParagraph("Jurisdictions");
            cell.Format.Font.Bold = true;


            cell = row.Cells[1];
            cell.AddParagraph("Approval#");
            cell.Format.Font.Bold = true;


            cell = row.Cells[2];
            cell.AddParagraph("Notes");
            cell.Format.Font.Bold = true;


            cell = row.Cells[3];
            cell.AddParagraph("Jurisdiction Fee");
            cell.Format.Font.Bold = true;


            cell = row.Cells[4];
            cell.AddParagraph("Permit Now Fee");
            cell.Format.Font.Bold = true;



The problem is when I try and insert (from a database the values stored therein).


Here is the code loading the data and attempting to display it:


Code:
connection = new MySqlConnection(connetionString);
            connection.Open();
           
            command = new MySqlCommand(sql, connection);
            adapter.SelectCommand = command;
          //  adapter.Fill(ds);
            adapter.Fill(dt);
            connection.Close();

            foreach(DataRow newrow in dt.Rows)
            {
                row.Table.AddRow();

                cell = row.Cells[0];
                cell.AddParagraph(newrow["ApprovalJurisdiction"].ToString());

                cell = row.Cells[1];
                cell.AddParagraph(newrow["ApprovalAppNumber"].ToString());

                cell = row.Cells[2];
                cell.AddParagraph(newrow["ApprovalNotes"].ToString());

                cell = row.Cells[3];
                cell.AddParagraph(newrow["ApprovalJurisdictionFee"].ToString());

                cell = row.Cells[4];
                cell.AddParagraph(newrow["ApprovalPermitNowFee"].ToString());
            }



I've attached a copy of the output.
It literally puts everything in the right column, but all in the header.

I had a FOR loop populating this table, but someone said use a FOR EACH loop, but the output is the same.

Any assistance would be appreciated!

G


Attachments:
pdftable error1.PNG
pdftable error1.PNG [ 17.45 KiB | Viewed 56 times ]
Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 30, 2020 7:30 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 563
Location: CCAA
-Mirage- wrote:
row.Table.AddRow();
This code adds a new row to the table and returns it. However the return value is not used and you continue to add elements to the first row.

Something like "row = row.Table.AddRow();" would make a big difference.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 30, 2020 9:40 pm 
Offline

Joined: Thu Jul 30, 2020 6:08 pm
Posts: 2
Hi TH-Soft,
Thank you for the quick reply!
I've changed my code and it worked, awesome!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 23 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group