PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

How to set TextFrame above my table
https://forum.pdfsharp.net/viewtopic.php?f=2&t=4133
Page 1 of 1

Author:  newbieCoder34 [ Mon May 18, 2020 6:48 am ]
Post subject:  How to set TextFrame above my table

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

Author:  TH-Soft [ Mon May 18, 2020 8:47 am ]
Post subject:  Re: How to set TextFrame above my table

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

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/