PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon Sep 28, 2020 11:25 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Mon May 18, 2020 6:48 am 
Offline

Joined: Mon May 18, 2020 6:44 am
Posts: 11
I am new and learning as I go with Migradoc and PDFSharp. I am trying to set my TextFrame data above my table. My overall goal is to create an invoice.

Code:
 public void DefineInvoice(Document document)
        {
            Section section = document.AddSection();
            // create the text frame for address
            TextFrame addressFrame = section.AddTextFrame();
            addressFrame.Height = "3.0cm";
            addressFrame.Width = "7.0cm";
            addressFrame.Left = ShapePosition.Left;
            addressFrame.RelativeHorizontal = RelativeHorizontal.Margin;
            addressFrame.Top = "5.0cm";
            addressFrame.RelativeVertical = RelativeVertical.Page;

            //fill in address for text frame
            Paragraph paragraph = addressFrame.AddParagraph();
            paragraph.AddText("Nieto LLC");
            paragraph.AddLineBreak();
            paragraph.AddText("6110 Google Drive");
            paragraph.AddLineBreak();
            paragraph.AddText("Houston, TX 77309");
            paragraph.AddLineBreak();
            paragraph.AddText("P: 281-890-5899");

            //define table
            Table table = section.AddTable();
           
           
 
            table.Borders.Width = 0.75;
           

            Column column = table.AddColumn(Unit.FromCentimeter(7));
            column.Format.Alignment = ParagraphAlignment.Center;

            column = table.AddColumn(Unit.FromCentimeter(2));
            column.Format.Alignment = ParagraphAlignment.Center;

            column = table.AddColumn(Unit.FromCentimeter(2));
            column.Format.Alignment = ParagraphAlignment.Center;

            column = table.AddColumn(Unit.FromCentimeter(2));
            column.Format.Alignment = ParagraphAlignment.Center;

            column = table.AddColumn(Unit.FromCentimeter(2));
            column.Format.Alignment = ParagraphAlignment.Center;
           

            //define header of table
            Row row = table.AddRow();
            row.HeadingFormat = true;
            Cell cell = row.Cells[0];
            cell.AddParagraph("Item List");
            cell.Format.Font.Bold = true;

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

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

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

            cell = row.Cells[4];
            cell.AddParagraph("Total Price");
            cell.Format.Font.Bold = true;

            //define one row of invoice information
            row = table.AddRow();
            cell = row.Cells[0];
            cell.AddParagraph("Admin theme with psd project layouts");
            cell = row.Cells[1];
            cell.AddParagraph("1");
            cell = row.Cells[2];
            cell.AddParagraph("$26.00");
            cell = row.Cells[3];
            cell.AddParagraph("$5.98");
            cell = row.Cells[4];
            cell.AddParagraph("$31.98");

            //define another row of invoice information
            row = table.AddRow();
            cell = row.Cells[0];
            cell.AddParagraph("Wordpress Theme customization");
            cell = row.Cells[1];
            cell.AddParagraph("2");
            cell = row.Cells[2];
            cell.AddParagraph("$80.00");
            cell = row.Cells[3];
            cell.AddParagraph("$36.80");
            cell = row.Cells[4];
            cell.AddParagraph("$196.80");

            //define another row of invoice information
            row = table.AddRow();
            cell = row.Cells[0];
            cell.AddParagraph("Angular 9 and Node JS Application");
            cell = row.Cells[1];
            cell.AddParagraph("3");
            cell = row.Cells[2];
            cell.AddParagraph("$420.00");
            cell = row.Cells[3];
            cell.AddParagraph("$193.20");
            cell = row.Cells[4];
            cell.AddParagraph("$1033.20");

            //add invisible row as a space line to the table
            row = table.AddRow();
            row.Borders.Visible = false;

            //add the subtotal row
            row = table.AddRow();
            row.Cells[0].Borders.Visible = false;
            row.Cells[0].AddParagraph("Sub Total:");
            row.Cells[0].Format.Font.Bold = true;
            row.Cells[0].Format.Alignment = ParagraphAlignment.Right;
            row.Cells[0].MergeRight = 3;

            //add tax row
            row = table.AddRow();
            row.Cells[0].Borders.Visible = false;
            row.Cells[0].AddParagraph("TAX:");
            row.Cells[0].Format.Font.Bold = true;
            row.Cells[0].Format.Alignment = ParagraphAlignment.Right;
            row.Cells[0].MergeRight = 3;

            //add total
            row = table.AddRow();
            row.Cells[0].Borders.Visible = false;
            row.Cells[0].AddParagraph("TOTAL:");
            row.Cells[0].Format.Font.Bold = true;
            row.Cells[0].Format.Alignment = ParagraphAlignment.Right;
            row.Cells[0].MergeRight = 3;

           

        }


The snapshot of how it looks can be found here:

https://stackoverflow.com/questions/618 ... -the-table


Top
 Profile  
Reply with quote  
PostPosted: Mon May 18, 2020 8:47 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 569
Location: CCAA
You set the address at the absolute vertical position of 5 cm. I assume that address and table would overlap if there were more items (rows) in the table.

If you want to have the address above the table, do not set an absolute position for the address, just let it float in the main body text.

https://stackoverflow.com/a/61865752/162529

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


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

All times are UTC


Who is online

Users browsing this forum: Bing [Bot], jon.farmer and 20 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