Example #1
0
        private void SourcesTable(Section s, IEnumerable <Source> sources, int tableColor = -1)
        {
            Table t;

            if (tableColor == -1)
            {
                t = s.AddTable().TableDefaults();
            }
            else
            {
                t = s.AddTable().TableDefaults(tableColor);
            }

            var colWidth = ContentWidth();
            var c0       = t.AddColumn(colWidth);

            t.AddRow().Cells[0].AddParagraph().AddBold("Sources");

            int number = 1;

            foreach (var src in sources)
            {
                var row = t.AddRow();
                row.BottomPadding = 5;
                row.TopPadding    = 5;

                var para = row.Cells[0].AddParagraph();
                para.AddText(string.Format("{0}. {1}", number, src.Text));

                number++;
            }
        }
Example #2
0
//    [UnitTestFunction]
        public static void TestSection()
        {
            Document doc = new Document();
            Section  sec = doc.AddSection();
            Table    tbl = sec.AddTable();

            tbl.AddColumn();
            Row rw = tbl.AddRow();

            rw.Cells[0].AddParagraph("Table 1");

            sec = doc.AddSection();
            tbl = sec.AddTable();
            tbl.AddColumn();
            rw = tbl.AddRow();
            rw.Cells[0].AddParagraph("Table 2");


            DocumentRenderer docRndrr = new DocumentRenderer();

            docRndrr.Render(doc, "RtfSection.txt", null);
            File.Copy("RtfSection.txt", "RtfSection.rtf", true);
            System.Diagnostics.Process.Start("RtfSection.txt");
            DdlWriter.WriteToFile(doc, "RtfSection.mdddl");
        }
            /// <summary>
            /// Creates the static parts of the PDF document.
            /// </summary>
            private void CreatePage()
            {
                // Each MigraDoc document needs at least one section.
                Section section = this.document.AddSection();
                var     with_2  = section.PageSetup;

                //.HeaderDistance = "1cm"
                with_2.TopMargin = "4,5cm";

                with_2.BottomMargin   = "3,0cm";
                with_2.FooterDistance = "0,3cm";
                //-------------------------------------
                // Create Header
                CreateHeader(section);

                //-------------------------------------
                // Create Footer
                CreateFooter(section);

                //-------------------------------------
                var with_3 = section.AddParagraph();

                //.Format.SpaceBefore = "1,5cm"
                with_3.AddFormattedText("Virksomhedsinfo", TextFormat.Bold);

                //-------------------------------------
                // Create the table for Virksomhed
                CreateTableVirksomhed(section.AddTable());

                var with_4 = section.AddParagraph();

                with_4.Format.SpaceBefore = "0,5cm";
                with_4.AddFormattedText(string.Format("Udfyldes af {0}", Company.name), TextFormat.Bold);

                //-------------------------------------
                // Create the table for Model
                CreateTableModel(section.AddTable());

                var with_5 = section.AddParagraph();

                with_5.Format.SpaceBefore = "0,5cm";
                with_5.AddFormattedText("Udfyldes af Virksomheden:", TextFormat.Bold);

                //-------------------------------------
                // Create the table for Lokation
                CreateTableLokation(section.AddTable());

                //-------------------------------------
                var with_6 = section.AddParagraph();

                with_6.Format.SpaceBefore = "0,2cm";
                with_6.AddText(string.Format("Blanketten bedes returneret til {0} i udfyldt stand. ", Company.name));
                with_6.AddText("Og sendes til nedennævnte adresse – eller alternativt indscan og send til ");
                with_6.AddText(Company.email);
            }
Example #4
0
        private void MediaTable(Section s, IEnumerable <Attachment> media, int tableColor = -1)
        {
            Table t = null;

            if (tableColor == -1)
            {
                t = s.AddTable().TableDefaults();
            }
            else
            {
                t = s.AddTable().TableDefaults(tableColor);
            }

            var colWidth = 0.5 * ContentWidth();
            var c0       = t.AddColumn(colWidth);
            var c1       = t.AddColumn(colWidth);

            var r0 = t.AddRow();

            r0.Cells[0].AddParagraph().AddBold("Number");
            r0.Cells[1].AddParagraph().AddBold("Media");

            double maxImgWidth = colWidth - 10;
            int    number      = 1;

            foreach (var att in media)
            {
                var row = t.AddRow();
                row.BottomPadding = 5;
                row.TopPadding    = 5;

                //number
                var header = row.Cells[0].AddParagraph();
                header.AddText(string.Format("{0}. {1}", number, att.Link));
                number++;

                //thumb
                var pathName = Utils2.RandomFilePath(".png");
                var bmpSrc   = AttachmentManager.GetAttachmentBitmap3(att);
                AttachmentManager.SaveBitmapSource(AttachmentManager.GetAttachmentBitmap3(att), pathName);

                var para = row.Cells[1].AddImage(pathName);
                if (att.Format == (int)AttachmentFormat.Pdf)  //pdf thumb is low resolution
                {
                    para.Height = maxImgWidth;
                }
                else
                {
                    para.Width = maxImgWidth;
                }
                para.RelativeHorizontal = RelativeHorizontal.Column;
                para.RelativeVertical   = RelativeVertical.Paragraph;
            }
        }
Example #5
0
        /// <summary>
        /// Export week scheduling to a section in a document
        /// </summary>
        /// <param name="toExport">The data to export from</param>
        /// <param name="sect">The section to write on</param>
        /// <returns>The section with appended data</returns>
        public override Section Export(Module toExport, Section sect)
        {
            base.Export(toExport, sect);

            //custom code
            Paragraph p = sect.AddParagraph("Weekplanning", "Heading2");

            p.AddLineBreak();

            Table  table      = sect.AddTable();
            Column weekCol    = table.AddColumn(Unit.FromCentimeter(1.5));
            Column subjectCol = table.AddColumn();

            subjectCol.Width    = sect.Document.DefaultPageSetup.PageWidth - sect.Document.DefaultPageSetup.RightMargin - sect.Document.DefaultPageSetup.LeftMargin - weekCol.Width;
            table.Borders.Width = 0.75;
            table.Borders.Color = Colors.DarkGray;

            Row row = table.AddRow();

            row.Cells[0].AddParagraph("Week").Format.Font.Bold        = true;
            row.Cells[1].AddParagraph("Onderwerpen").Format.Font.Bold = true;

            foreach (Weekplanning wp in toExport.Weekplanning)
            {
                row = table.AddRow();
                row.Cells[0].AddParagraph(wp.Week ?? "");
                row.Cells[1].AddParagraph(wp.Onderwerp ?? "");
            }

            p = sect.AddParagraph();
            p.AddLineBreak();

            return(sect);
        }
Example #6
0
        private void PaymentSection()
        {
            Section section = Pdf.LastSection;

            Table table = section.AddTable();

            table.AddColumn(Unit.FromPoint(section.Document.PageWidth()));
            Row row = table.AddRow();

            if (Invoice.Details != null && Invoice.Details.Count > 0)
            {
                foreach (DetailRow detail in Invoice.Details)
                {
                    row.Cells[0].AddParagraph(detail.Title, ParagraphAlignment.Left, "H2-9B-Color");
                    row.Cells[0].Borders.Bottom = BorderLine;

                    row = table.AddRow();
                    TextFrame frame = null;
                    foreach (string line in detail.Paragraphs)
                    {
                        if (line == detail.Paragraphs[0])
                        {
                            frame       = row.Cells[0].AddTextFrame();
                            frame.Width = section.Document.PageWidth();
                        }
                        frame.AddParagraph(line, ParagraphAlignment.Left, "H2-9");
                    }
                }
            }

            if (Invoice.Company.HasCompanyNumber || Invoice.Company.HasVatNumber)
            {
                row = table.AddRow();

                Color shading = MigraDocHelpers.TextColorFromHtml(Invoice.TextColor);

                if (Invoice.Company.HasCompanyNumber && Invoice.Company.HasVatNumber)
                {
                    row.Cells[0].AddParagraph(string.Format("Company Number: {0}, VAT Number: {1}",
                                                            Invoice.Company.CompanyNumber, Invoice.Company.VatNumber),
                                              ParagraphAlignment.Center, "H2-9B-Inverse")
                    .Format.Shading.Color = shading;
                }
                else
                {
                    if (Invoice.Company.HasCompanyNumber)
                    {
                        row.Cells[0].AddParagraph(string.Format("Company Number: {0}", Invoice.Company.CompanyNumber),
                                                  ParagraphAlignment.Center, "H2-9B-Inverse")
                        .Format.Shading.Color = shading;
                    }
                    else
                    {
                        row.Cells[0].AddParagraph(string.Format("VAT Number: {0}", Invoice.Company.VatNumber),
                                                  ParagraphAlignment.Center, "H2-9B-Inverse")
                        .Format.Shading.Color = shading;
                    }
                }
            }
        }
Example #7
0
        public MezTable AddTable(params MezColumn[] columns)
        {
            var result    = Section.AddTable();
            var bodyWidth = BodyWidth();
            //int starColumns = 0;
            uint starFactors = 0;
            Unit fixedWidth  = 0;

            // Evaluate the columns.
            foreach (var item in columns)
            {
                var star = item as MezStarColumn;
                if (star != null)
                {
                    //++starColumns;
                    starFactors += star.StarFactor;
                    continue;
                }
                var unit = item as MezUnitColumn;
                if (unit != null)
                {
                    fixedWidth += unit.Unit;
                    continue;
                }
                throw new NotImplementedException("Unsupported column type in \"AddTable(params MezColumn[] columns)\".");
            }

            // Create the columns.
            Unit starWidth = bodyWidth - fixedWidth;

            // Do not allow negative widths. Use 0 instead. Should we throw an exception?
            if (starWidth < 0)
            {
                starWidth = 0;
            }

            foreach (var item in columns)
            {
                var    star = item as MezStarColumn;
                var    unit = item as MezUnitColumn;
                Column col  = null;
                if (star != null)
                {
                    col = result.AddColumn(starWidth * star.StarFactor / starFactors);
                }
                else if (unit != null)
                {
                    col = result.AddColumn(unit.Unit);
                }
                if (col != null)
                {
                    col.Style = item.Style;
                    if (item.Alignment.HasValue)
                    {
                        col.Format.Alignment = item.Alignment.Value;
                    }
                }
            }
            return(new MezTable(result));
        }
Example #8
0
        public GenericTable(TableColumnsModel columns, TableBorderModel border, double Xcoords = 0, double Ycoords = 0, double CustomWidth = 0, string CustomWidthAlignment = null)
        {
            // jeśli podano koordynaty w zmiennych
            if (Xcoords > 0 && Ycoords > 0)
            {
                X = Xcoords; Y = Ycoords;
            }
            //jeśli podano CustomWidth
            if (CustomWidth > 0)
            {
                width = CustomWidth;
            }

            //jesli podano alignment
            if (CustomWidthAlignment != null)
            {
                this.CustomWidthAlignment = CustomWidthAlignment;
            }


            tcm = columns; tbm = border;
            doc = new Document();
            Section sec = doc.AddSection();

            this.table = sec.AddTable();
            this.styleTable();
            this.addColumns();
        }
Example #9
0
        private void CommentsTable(Section s, IEnumerable <Comment> comments, int color)
        {
            var t2 = s.AddTable().TableDefaults(color);

            t2.AddColumn(0.2 * ContentWidth());
            t2.AddColumn(0.8 * ContentWidth());

            var hdrRow = t2.AddRow();

            hdrRow.Cells[0].AddParagraph().AddBold("Author");
            hdrRow.Cells[1].AddParagraph().AddBold("Comment");

            foreach (var comment in comments)
            {
                if (comment.Person == null || comment.Text == DaoUtils.NEW_COMMENT)
                {
                    continue;
                }

                var row = t2.AddRow();
                row.Cells[0].AddParagraph(comment.Person.Name);
                row.Cells[0].Shading.Color = new MigraDoc.DocumentObjectModel.Color((uint)comment.Person.Color);
                row.Cells[1].AddParagraph(comment.Text);
            }
        }
        void AddReportIdentifier(Document document, Section section, BusinessTrip trip)
        {
            section.AddParagraph("1. Indentyfikator Raportu", "SectionHeader");

            // Create the item table
            Table table = section.AddTable();

            table.Style         = "TableIdentifier";
            table.Borders.Width = 0;
            table.Rows.Height   = Unit.FromPoint(document.Styles["Normal"].Font.Size * 2);

            Column columnHeader = table.AddColumn(Unit.FromCentimeter(5));
            Column columnValue  = table.AddColumn(Unit.FromCentimeter(11));

            Row row2 = table.AddRow();

            row2.Cells[0].AddParagraph("POWÓD PODRÓŻY");
            row2.Cells[1].AddParagraph(trip.BusinessReason);

            Row row3 = table.AddRow();

            row3.Cells[0].AddParagraph("CEL PODÓŻY");
            row3.Cells[1].AddParagraph(trip.BusinessPurpose);

            Row row4 = table.AddRow();

            row4.Cells[0].AddParagraph("KOMENTARZ");
            row4.Cells[1].AddParagraph(trip.Notes);

            AddSectionEndingSpace(section);
        }
        private void AddressSection()
        {
            Section section = Pdf.LastSection;

            Address leftAddress  = Invoice.Company;
            Address rightAddress = Invoice.Client;

            if (Invoice.CompanyOrientation == PositionOption.Right)
            {
                Utils.Swap <Address>(ref leftAddress, ref rightAddress);
            }

            Table table = section.AddTable();

            table.AddColumn(ParagraphAlignment.Left, section.Document.PageWidth() / 2 - 10);
            table.AddColumn(ParagraphAlignment.Center, Unit.FromPoint(20));
            table.AddColumn(ParagraphAlignment.Left, section.Document.PageWidth() / 2 - 10);

            Row row = table.AddRow();

            row.Style         = "H2-10B-Color";
            row.Shading.Color = Colors.White;

            row.Cells[0].AddParagraph(leftAddress.Title, ParagraphAlignment.Left);
            row.Cells[0].Format.Borders.Bottom = BorderLine;
            row.Cells[2].AddParagraph(rightAddress.Title, ParagraphAlignment.Left);
            row.Cells[2].Format.Borders.Bottom = BorderLine;

            row = table.AddRow();
            AddressCell(row.Cells[0], leftAddress.AddressLines);
            AddressCell(row.Cells[2], rightAddress.AddressLines);

            row = table.AddRow();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //Create Word document.
            Document document = new Document();

            //Add a new section.
            Section section = document.AddSection();

            //Add a table with rows and columns and set the text for the table.
            Table table = section.AddTable();

            table.ResetCells(1, 1);
            TableCell cell = table.Rows[0].Cells[0];

            table.Rows[0].Height = 150;
            cell.AddParagraph().AppendText("Draft copy in vertical style");

            //Set the TextDirection for the table to RightToLeftRotated.
            cell.CellFormat.TextDirection = TextDirection.RightToLeftRotated;

            //Set the table format.
            table.TableFormat.WrapTextAround              = true;
            table.TableFormat.Positioning.VertRelationTo  = VerticalRelation.Page;
            table.TableFormat.Positioning.HorizRelationTo = HorizontalRelation.Page;
            table.TableFormat.Positioning.HorizPosition   = section.PageSetup.PageSize.Width - table.Width;
            table.TableFormat.Positioning.VertPosition    = 200;

            String result = "Result-CreateVerticalTable.docx";

            //Save to file.
            document.SaveToFile(result, FileFormat.Docx2013);

            //Launch the MS Word file.
            WordDocViewer(result);
        }
Example #13
0
        private void BillingSection()
        {
            Section section = Pdf.LastSection;

            Table table = section.AddTable();

            double width        = section.PageWidth();
            double productWidth = Unit.FromPoint(150);
            double numericWidth = (width - productWidth) / 4;

            table.AddColumn(productWidth);
            table.AddColumn(ParagraphAlignment.Center, numericWidth);
            table.AddColumn(ParagraphAlignment.Center, numericWidth);
            table.AddColumn(ParagraphAlignment.Center, numericWidth);
            table.AddColumn(ParagraphAlignment.Center, numericWidth);

            BillingHeader(table);

            foreach (ItemRow item in Invoice.Items)
            {
                BillingRow(table, item);
            }

            if (Invoice.Totals != null)
            {
                foreach (TotalRow total in Invoice.Totals)
                {
                    BillingTotal(table, total);
                }
            }
            table.AddRow();
        }
        void AddDietDays(Document document, Section section, BusinessTrip trip)
        {
            if (trip.Subsistence == null || trip.Subsistence.Days.Count == 0)
            {
                return;
            }

            section.AddParagraph("DIETA", "SectionHeader");

            // Create the item table
            Table table = section.AddTable();

            table.Style         = "Table";
            table.Borders.Width = 0;
            table.Borders.Color = color;
            //table.Rows.Height = Unit.FromPoint(document.Styles["Normal"].Font.Size * 2);

            Column columnSpaceLeft  = table.AddColumn(Unit.FromCentimeter(0.25));
            Column columnDate       = table.AddColumn(Unit.FromCentimeter(2));
            Column columnType       = table.AddColumn(Unit.FromCentimeter(2));
            Column columnDistance   = table.AddColumn(Unit.FromCentimeter(2));
            Column columnAmount     = table.AddColumn(Unit.FromCentimeter(2));
            Column columnComment    = table.AddColumn(Unit.FromCentimeter(7.5));
            Column columnSpaceRight = table.AddColumn(Unit.FromCentimeter(0.25));

            AddTopRow(table, 6);

            Row rowHeader = table.AddRow();

            rowHeader.Cells[0].AddParagraph("");
            rowHeader.Cells[0].Borders.Left.Width = 0.5;
            rowHeader.Cells[1].AddParagraph("DATA");
            rowHeader.Cells[2].AddParagraph("ŚNIADANIE");
            rowHeader.Cells[3].AddParagraph("OBIAD");
            rowHeader.Cells[4].AddParagraph("KOLACJA");
            rowHeader.Cells[5].AddParagraph("KWOTA");
            rowHeader.Cells[6].AddParagraph("");
            rowHeader.Cells[6].Borders.Right.Width = 0.5;

            AddEmptyRow(table, 6);

            foreach (SubsistenceDay e in trip.Subsistence.Days)
            {
                Row row = table.AddRow();
                row.Cells[0].AddParagraph("");
                row.Cells[1].AddParagraph(e.Date.ToAppString());
                row.Cells[2].AddParagraph(e.Breakfast ? "TAK" : "NIE");
                row.Cells[3].AddParagraph(e.Dinner ? "TAK" : "NIE");
                row.Cells[4].AddParagraph(e.Supper ? "TAK" : "NIE");
                row.Cells[5].AddParagraph(e.AmountPLN.ToString() + " PLN");
                row.Cells[6].AddParagraph("");

                AddRowBorders(row);
            }

            AddEmptyRow(table, 6);
            AddBottomRow(table, 6);

            AddSectionEndingSpace(section);
        }
        void AddMileages(Document document, Section section, BusinessTrip trip)
        {
            if (trip.MileageAllowances.Count == 0)
            {
                return;
            }

            section.AddParagraph("KILOMETRÓWKA", "SectionHeader");

            // Create the item table
            Table table = section.AddTable();

            table.Style         = "Table";
            table.Borders.Width = 0;
            table.Borders.Color = color;
            //table.Rows.Height = Unit.FromPoint(document.Styles["Normal"].Font.Size * 2);

            Column columnSpaceLeft  = table.AddColumn(Unit.FromCentimeter(0.25));
            Column columnDate       = table.AddColumn(Unit.FromCentimeter(2));
            Column columnType       = table.AddColumn(Unit.FromCentimeter(2));
            Column columnDistance   = table.AddColumn(Unit.FromCentimeter(2));
            Column columnAmount     = table.AddColumn(Unit.FromCentimeter(2));
            Column columnComment    = table.AddColumn(Unit.FromCentimeter(7.5));
            Column columnSpaceRight = table.AddColumn(Unit.FromCentimeter(0.25));

            AddTopRow(table, 6);

            Row rowHeader = table.AddRow();

            rowHeader.Cells[0].AddParagraph("");
            rowHeader.Cells[0].Borders.Left.Width = 0.5;
            rowHeader.Cells[1].AddParagraph("DATA");
            rowHeader.Cells[2].AddParagraph("TYP POJAZDU");
            rowHeader.Cells[3].AddParagraph("DYSTANS");
            rowHeader.Cells[4].AddParagraph("KWOTA");
            rowHeader.Cells[5].AddParagraph("KOMENTARZ");
            rowHeader.Cells[6].AddParagraph("");
            rowHeader.Cells[6].Borders.Right.Width = 0.5;

            AddEmptyRow(table, 6);

            foreach (MileageAllowance e in trip.MileageAllowances)
            {
                Row row = table.AddRow();
                row.Cells[0].AddParagraph("");
                row.Cells[1].AddParagraph(e.Date.ToAppString());
                row.Cells[2].AddParagraph(e.Type.Name);
                row.Cells[3].AddParagraph(e.Distance.ToString());
                row.Cells[4].AddParagraph(e.Amount + " PLN");
                row.Cells[5].AddParagraph(e.Notes);
                row.Cells[6].AddParagraph("");

                AddRowBorders(row);
            }

            AddEmptyRow(table, 6);
            AddBottomRow(table, 6);

            AddSectionEndingSpace(section);
        }
Example #16
0
        public void ExportToPDF(string _sCardImage)
        {
            //297×210 A4
            //88x63 Card
            //264x189 9Cards
            Document document = new Document();
            Section  section  = document.AddSection();

            section.PageSetup.BottomMargin = "1.0cm";
            section.PageSetup.TopMargin    = "1.0cm";
            section.PageSetup.LeftMargin   = "0.65cm";
            section.PageSetup.RightMargin  = "0.65cm";

            var table = section.AddTable();

            table.Borders.Color = new MigraDoc.DocumentObjectModel.Color(0, 0, 0);
            var ColumnLeft  = table.AddColumn("0.5cm");
            var Column0     = table.AddColumn("6.315cm");
            var Column1     = table.AddColumn("6.315cm");
            var Column2     = table.AddColumn("6.315cm");
            var ColumnRight = table.AddColumn("0.5cm");
            var topRow      = table.AddRow();

            topRow.Height = "0.5cm";
            //[TODO] Split proxies in 9x9 pages and then add a 9x9 back images
            for (int i = 0; i < 3; ++i)
            {
                var tableRow = table.AddRow();
                //tableRow.Height = "8.8cm";
                for (int j = 1; j < 4; ++j)
                {
                    var cell = tableRow.Cells[j];
                    var par  = cell.AddParagraph();
                    par.Format.SpaceAfter = "-0.07cm";
                    par.Format.LeftIndent = "-0.12cm";
                    cell.Shading.Color    = new MigraDoc.DocumentObjectModel.Color(0, 0, 0);
                    var card = par.AddImage(_sCardImage);
                    card.Width  = "6.3cm";
                    card.Height = "8.8cm";
                }
            }
            var bottomRow = table.AddRow();

            bottomRow.Height      = "0.5cm";
            document.UseCmykColor = true;
            const bool             unicode   = false;
            const PdfFontEmbedding embedding = PdfFontEmbedding.Always;
            // ========================================================================================
            // Create a renderer for the MigraDoc document.
            PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(unicode, embedding);

            // Associate the MigraDoc document with a renderer
            pdfRenderer.Document = document;
            // Layout and render document to PDF
            pdfRenderer.RenderDocument();
            // Save the document...
            string filename = _sCardImage.Replace(".png", ".pdf");

            pdfRenderer.PdfDocument.Save(filename);
        }
Example #17
0
        public static void CellMerge(string outputFile)
        {
            Document document = new Document();
            Section  sec      = document.Sections.AddSection();

            sec.AddParagraph("A paragraph before.");
            Table table = sec.AddTable();

            table.Borders.Visible = true;
            table.AddColumn();
            table.AddColumn();
            Row  row  = table.AddRow();
            Cell cell = row.Cells[0];

            cell.MergeRight          = 1;
            cell.Borders.Visible     = true;
            cell.Borders.Left.Width  = 8;
            cell.Borders.Right.Width = 2;
            cell.AddParagraph("First Cell");

            row  = table.AddRow();
            cell = row.Cells[1];
            cell.AddParagraph("Last Cell within this row");
            cell.MergeDown            = 1;
            cell.Borders.Bottom.Width = 15;
            cell.Borders.Right.Width  = 30;
            cell.Shading.Color        = Colors.LightBlue;
            row = table.AddRow();
            sec.AddParagraph("A Paragraph afterwards");
            PdfDocumentRenderer renderer = new PdfDocumentRenderer();

            renderer.Document = document;
            renderer.RenderDocument();
            renderer.PdfDocument.Save(outputFile);
        }
Example #18
0
        /// <summary>Creates the table.</summary>
        /// <param name="section">The section.</param>
        /// <param name="tableObj">The table to convert to html.</param>
        /// <param name="workingDirectory">The working directory.</param>
        private void CreateTable(Section section, AutoDocumentation.Table tableObj, string workingDirectory)
        {
            // Create a 2 column, 1 row table. Image in first cell, X/Y data in second cell.
            Table table = section.AddTable();

            table.Style           = "Table";
            table.Rows.LeftIndent = "1cm";

            foreach (List <string> column in tableObj.data)
            {
                Column column1 = table.AddColumn();
                column1.Width            = "1.4cm";
                column1.Format.Alignment = ParagraphAlignment.Right;
            }

            for (int rowIndex = 0; rowIndex < tableObj.data[0].Count; rowIndex++)
            {
                Row row = table.AddRow();
                for (int columnIndex = 0; columnIndex < tableObj.data.Count; columnIndex++)
                {
                    string cellText = tableObj.data[columnIndex][rowIndex];
                    row.Cells[columnIndex].AddParagraph(cellText);
                }
            }
        }
Example #19
0
        /// <summary>
        /// Create report in doc/docx format
        /// </summary>
        /// <param name="path">path to file</param>
        /// <param name="batteryInfo">battery information</param>
        public void CreateReport(string path, List <BatteryProperty> batteryInfo)
        {
            try
            {
                using (Document doc = new Document())
                {
                    Section   s = doc.AddSection();
                    TextRange tr;
                    tr = InsertNewParagraph("Отчет о состоянии батареи\n", s, HorizontalAlignment.Center);
                    tr.CharacterFormat.FontName         = "Arial";
                    tr.CharacterFormat.FontSize         = 22;
                    tr.CharacterFormat.CharacterSpacing = 2;

                    tr = InsertNewParagraph(DateTime.Now.ToString("dddd, dd MMMM yyyy HH:mm:ss" + '\n'), s, HorizontalAlignment.Center);
                    tr.CharacterFormat.FontName = "Arial";
                    tr.CharacterFormat.FontSize = 16;

                    Table table = s.AddTable(true);
                    FillOutTable(table, batteryInfo);

                    doc.SaveToFile(path, FileFormat.Auto);
                }
            }
            catch (IOException)
            {
                throw new IOException("Не удалось получить доступ к файлу, возможно он открыт в другом приложении\n");
            }
            catch (Exception e)
            {
                throw new Exception("Неопознання ошибка! \n Системное описание ошибки:" + e.Message);
            }
        }
Example #20
0
        /// <summary>
        /// Add a text frame.
        /// </summary>
        /// <param name="section"></param>
        private static void AddCodeBlock(Section section, string text)
        {
            Table table = section.AddTable();

            table.Borders.Width   = "0.5pt";
            table.Borders.Color   = MigraDoc.DocumentObjectModel.Colors.DarkGray;
            table.LeftPadding     = "5mm";
            table.Rows.LeftIndent = "0cm";

            var column = table.AddColumn();

            column.Width = Unit.FromMillimeter(180);

            Row       row = table.AddRow();
            Paragraph p   = row[0].AddParagraph();

            p.Style = "TableParagraph";

            string[] lines = text.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);

            foreach (string line in lines)
            {
                string spacedLine = line.Replace(' ', (char)0xa0); // Turn spaces into non-breaking spaces

                p = row[0].AddParagraph();
                p.AddText(WebUtility.HtmlDecode(spacedLine));
                p.Style = "TableParagraph";
            }
        }
Example #21
0
        private void ArgPointNode(Section s, ArgPoint ap)
        {
            //arg.point header table
            var t = s.AddTable().TableDefaults(ap.Person.Color);

            var c0 = t.AddColumn(0.2 * ContentWidth());
            var c1 = t.AddColumn(0.8 * ContentWidth());

            var r1 = t.AddRow();

            r1.Format.Font.Bold = true;
            r1.Cells[0].AddParagraph().AddBold("Point #" + ap.OrderNumber);
            r1.Cells[1].AddParagraph(ap.Point);

            //var r0 = t.AddRow();
            //r0.Cells[0].AddParagraph("Author");
            //r0.Cells[1].AddParagraph(ap.Person.Name);

            //description
            var descr = s.AddParagraph(ap.Description.Text);

            descr.Format.Shading.Color = new MigraDoc.DocumentObjectModel.Color((uint)ap.Person.Color);
            descr.AlignWithTable();

            //point's media
            MediaTable(s, ap.Attachment, ap.Person.Color);

            //point's sources
            SourcesTable(s, ap.Description.Source, ap.Person.Color);

            //point's comments
            CommentsTable(s, ap.Comment, ap.Person.Color);
        }
Example #22
0
        public void VerticalAlign( )
        {
            string   outputFile = "VerticalAlign.pdf";
            Document document   = new Document();
            Section  sec        = document.Sections.AddSection();

            sec.AddParagraph("A paragraph before.");
            Table table = sec.AddTable();

            table.Borders.Visible = true;
            table.AddColumn();
            table.AddColumn();
            Row row = table.AddRow();

            row.HeightRule        = RowHeightRule.Exactly;
            row.Height            = 70;
            row.VerticalAlignment = VerticalAlignment.Center;
            row[0].AddParagraph("First Cell");
            row[1].AddParagraph("Second Cell");
            sec.AddParagraph("A Paragraph afterwards.");


            PdfDocumentRenderer renderer = new PdfDocumentRenderer();

            renderer.Document = document;
            renderer.RenderDocument();
            renderer.PdfDocument.Save(outputFile);

            LaunchPdf(outputFile);
        }
Example #23
0
        /// <summary>
        /// Creates table header with indicated styles.
        /// </summary>
        /// <param name="section">The section of the Document.</param>
        /// <param name="tableHelper">Consists all necessary styles.</param>
        /// <param name="tableCells">Sets dynamically the names of the table.</param>
        /// <returns>Table class</returns>
        public Table CreateTableHeader(ref Section section, IPdfTableHelperStyles tableHelper, List <PdfTableCell> tableCells)
        {
            var table = section.AddTable();

            table.Style               = tableHelper.TableStyle;
            table.Borders.Color       = Colors.LightGray;
            table.Borders.Width       = tableHelper.BordersWidth;
            table.Borders.Left.Width  = tableHelper.BordersLeftWidth;
            table.Borders.Right.Width = tableHelper.BordersRightWidth;
            table.Rows.LeftIndent     = tableHelper.RowsLeftIndent;

            foreach (var cell in tableCells)
            {
                var column = table.AddColumn(cell.Width);
                column.Format.Alignment = cell.Alignment;
            }

            var row = table.AddRow();

            row.Borders.Width = tableHelper.LargeBorderWidth;
            row.Borders.Color = Colors.Black;
            for (var i = 0; i < tableCells.Count; i++)
            {
                var paragraph = row.Cells[i];
                paragraph.Format.Font.Bold = true;
                row.Cells[i].AddParagraph(tableCells[i].Name);
            }

            return(table);
        }
Example #24
0
        private void addTable(Section section, ObservableCollection <Models.Task> tasks, CancellationToken token)
        {
            var    table               = section.AddTable();
            float  sectionWidth        = section.PageSetup.PageWidth - section.PageSetup.LeftMargin - section.PageSetup.RightMargin;
            double taskColumnWidth     = sectionWidth * TASK_COLUMN_WIDTH_PERCENTAGE;
            double categoryColumnWidth = sectionWidth * CATEGORY_COLUMN_WIDTH_PERCENTAGE;

            table.Style               = "Table";
            table.Borders.Width       = 0.25;
            table.Borders.Left.Width  = 0.5;
            table.Borders.Right.Width = 0.5;
            table.Rows.LeftIndent     = 0;
            table.Format.Font.Name    = FONT_NAME;

            // Before you can add a row, you must define the columns
            Column column = table.AddColumn();

            column.Width            = taskColumnWidth;
            column.Format.Alignment = ParagraphAlignment.Center;
            column                  = table.AddColumn();
            column.Width            = categoryColumnWidth;
            column.Format.Alignment = ParagraphAlignment.Right;

            addHeader(table);
            addBody(tasks, table, token);
        }
        private Table CreateTableWithHeading(string heading)
        {
            Section section = _document.LastSection;

            section.AddParagraph().AddLineBreaks(count: 2);
            //
            Paragraph     paragraph = section.AddParagraph();
            FormattedText text      = paragraph.AddFormattedText(heading, "Heading");

            text.Color = Colors.Black;
            paragraph.AddLineBreaks(count: 2);
            //
            Table  table = section.AddTable();
            Column col   = table.AddColumn(); // 1 column

            col.Width = 80;
            col       = table.AddColumn();  // 2 column
            col.Width = 200;
            col       = table.AddColumn();  // 3 column
            col.Width = 100;
            col       = table.AddColumn();  // 4 column
            col.Width = 100;
            //
            return(table);
        }
Example #26
0
        /// <summary>
        /// Add a text frame.
        /// </summary>
        /// <param name="section"></param>
        private static void AddCodeBlock(Section section, string text)
        {
            Table table = section.AddTable();

            table.Borders.Width   = "0.5pt";
            table.Borders.Color   = MigraDoc.DocumentObjectModel.Colors.DarkGray;
            table.LeftPadding     = "5mm";
            table.Rows.LeftIndent = "0cm";

            var column = table.AddColumn();

            column.Width = Unit.FromMillimeter(180);

            Row row = table.AddRow();

            string[] lines = text.Split(new string[] { "\r\n" }, StringSplitOptions.None);

            foreach (string line in lines)
            {
                int       numSpaces = StringUtilities.IndexNotOfAny(line, " ".ToCharArray(), 0);
                Paragraph p         = row[0].AddParagraph();
                p.AddSpace(numSpaces);
                p.AddText(line);
                p.Style = "TableParagraph";
            }
        }
Example #27
0
        public static void Borders(string outputFile)
        {
            Document document = new Document();
            Section  sec      = document.Sections.AddSection();

            sec.AddParagraph("A paragraph before.");
            Table table = sec.AddTable();

            table.Borders.Visible = true;
            table.AddColumn();
            table.AddColumn();
            table.Rows.HeightRule = RowHeightRule.Exactly;
            table.Rows.Height     = 14;
            Row  row  = table.AddRow();
            Cell cell = row.Cells[0];

            cell.Borders.Visible     = true;
            cell.Borders.Left.Width  = 8;
            cell.Borders.Right.Width = 2;
            cell.AddParagraph("First Cell");

            row  = table.AddRow();
            cell = row.Cells[1];
            cell.AddParagraph("Last Cell within this table");
            cell.Borders.Bottom.Width = 15;
            cell.Shading.Color        = Colors.LightBlue;
            sec.AddParagraph("A Paragraph afterwards");
            PdfDocumentRenderer printer = new PdfDocumentRenderer()
            {
                Document = document
            };

            printer.RenderDocument(CancellationToken.None);
            printer.PdfDocument.Save(outputFile);
        }
        private void createTimesheetSection()
        {
            //Go through all the timesheets and create the table for each.
            //Title only occurs on first day
            Section currentSection = (Section)serviceSheetDoc.Sections.LastObject;

            timesheetTable = currentSection.AddTable();

            //Setup the table columns and borders
            Column tableColumnn = timesheetTable.AddColumn(COLUMN_ONE_WIDTH);

            tableColumnn = timesheetTable.AddColumn(COLUMN_TWO_WIDTH);
            timesheetTable.Borders.Color = tableBorderColour;
            timesheetTable.Borders.Width = borderWidth;

            int counter = 0;

            foreach (ServiceDayViewModel sd in currentSheet.AllServiceDays)
            {
                if (counter == 0)
                {
                    Row row1Title = timesheetTable.AddRow();
                    row1Title.Cells[0].MergeRight = 1;
                    Paragraph jobDetailsPara = row1Title.Cells[0].AddParagraph();
                    jobDetailsPara.AddFormattedText("T", "allCapsFirstLetter");
                    jobDetailsPara.AddFormattedText("IMESHEET ", "allCapsNextLetter");
                    row1Title.Cells[0].Shading.Color = headerGrey;
                }

                addDayToTimesheet(sd, counter, currentSheet.UkServiceSheet);

                counter = counter + 1;
            }


            //int noOfDays = currentSheet.ServiceTimesheets.Count;
            //int counter = 0;

            //while (counter < noOfDays)
            //{
            //    if (counter ==0)
            //    {
            //        Row row1Title = timesheetTable.AddRow();
            //        row1Title.Cells[0].MergeRight = 1;
            //        Paragraph jobDetailsPara = row1Title.Cells[0].AddParagraph();
            //        jobDetailsPara.AddFormattedText("T", "allCapsFirstLetter");
            //        jobDetailsPara.AddFormattedText("IMESHEET ", "allCapsNextLetter");
            //        row1Title.Cells[0].Shading.Color = headerGrey;
            //    }

            //    oldServiceDayModel currentDay = currentSheet.ServiceTimesheets[counter];
            //    addDayToTimesheet(currentDay, counter);

            //    counter = counter + 1;
            //}

            //Add a gap before the next section
            currentSection.AddParagraph();
        }
        private void createFollowupSection()
        {
            Section currentSection = (Section)serviceSheetDoc.Sections.LastObject;

            followupTable = currentSection.AddTable();

            //Setup the table columns and borders
            Column tableColumnn = followupTable.AddColumn(COLUMN_ONE_WIDTH);

            tableColumnn = followupTable.AddColumn(COLUMN_TWO_WIDTH);
            followupTable.Borders.Color = tableBorderColour;
            followupTable.Borders.Width = borderWidth;

            Row row1Title = followupTable.AddRow();

            row1Title.Cells[0].MergeRight = 1;
            Paragraph followupPara = row1Title.Cells[0].AddParagraph();

            followupPara.AddFormattedText("F", "allCapsFirstLetter");
            followupPara.AddFormattedText("OLLOW-UP ", "allCapsNextLetter");
            followupPara.AddFormattedText("W", "allCapsFirstLetter");
            followupPara.AddFormattedText("ORK", "allCapsNextLetter");
            row1Title.Cells[0].Shading.Color = headerGrey;

            row1Title.KeepWith = 9;

            addLineToFollowupTable("Additional faults found", currentSheet.AdditionalFaults);
            addLineToFollowupTable("Parts required", currentSheet.FollowUpPartsRequired);
            //RT 18/8/16 - Quote required should be yes/no
            bool quoteRequired = currentSheet.QuoteRequired;

            if (quoteRequired)
            {
                addLineToFollowupTable("Quote required", "Yes");
            }
            else
            {
                addLineToFollowupTable("Quote required", "No");
            }
            //addLineToFollowupTable("Quote required", currentSheet.QuoteRequired.ToString());

            Row rowImages = followupTable.AddRow();

            rowImages.Cells[0].MergeRight = 1;
            Paragraph followupImagesPara = rowImages.Cells[0].AddParagraph();

            followupImagesPara.AddFormattedText("F", "allCapsFirstLetter");
            followupImagesPara.AddFormattedText("OLLOW-UP WORK IMAGES", "allCapsNextLetter");
            rowImages.Cells[0].Shading.Color = headerGrey;

            addImageToFollowupTable("Image 1", currentSheet.Image1, 4);
            addImageToFollowupTable("Image 2", currentSheet.Image2, 4);
            addImageToFollowupTable("Image 3", currentSheet.Image3, 4);
            addImageToFollowupTable("Image 4", currentSheet.Image4, 4);
            addImageToFollowupTable("Image 5", currentSheet.Image5, 4);

            //Add a space before the next table
            currentSection.AddParagraph();
        }
Example #30
0
        internal static void AddInvoiceTable(Section s)
        {
            Table t = s.AddTable();

            t.HeaderRowStyle.SetBorderStyle(Stroke.None).SetFont(HiddenFont).Border.SetWidth(0.0f);
            t.ContentRowStyle.SetBorderStyle(Stroke.None).SetFont(ItalicFont).Border.SetWidth(0.0f);
            t.SetDataSource(InvoiceData);
        }
Example #31
0
        private void addTable(Section section)
        {
            String[] header = { "Name", "Capital", "Continent", "Area", "Population" };
            String[][] data =
                {
                    new String[]{"Argentina", "Buenos Aires", "South America", "2777815", "32300003"},
                    new String[]{"Bolivia", "La Paz", "South America", "1098575", "7300000"},
                    new String[]{"Brazil", "Brasilia", "South America", "8511196", "150400000"},
                    new String[]{"Canada", "Ottawa", "North America", "9976147", "26500000"},
                    new String[]{"Chile", "Santiago", "South America", "756943", "13200000"},
                    new String[]{"Colombia", "Bagota", "South America", "1138907", "33000000"},
                    new String[]{"Cuba", "Havana", "North America", "114524", "10600000"},
                    new String[]{"Ecuador", "Quito", "South America", "455502", "10600000"},
                    new String[]{"El Salvador", "San Salvador", "North America", "20865", "5300000"},
                    new String[]{"Guyana", "Georgetown", "South America", "214969", "800000"},
                    new String[]{"Jamaica", "Kingston", "North America", "11424", "2500000"},
                    new String[]{"Mexico", "Mexico City", "North America", "1967180", "88600000"},
                    new String[]{"Nicaragua", "Managua", "North America", "139000", "3900000"},
                    new String[]{"Paraguay", "Asuncion", "South America", "406576", "4660000"},
                    new String[]{"Peru", "Lima", "South America", "1285215", "21600000"},
                    new String[]{"United States of America", "Washington", "North America", "9363130", "249200000"},
                    new String[]{"Uruguay", "Montevideo", "South America", "176140", "3002000"},
                    new String[]{"Venezuela", "Caracas", "South America", "912047", "19700000"}
                };
            Spire.Doc.Table table = section.AddTable();
            table.ResetCells(data.Length + 1, header.Length);

            // ***************** First Row *************************
            TableRow row = table.Rows[0];
            row.IsHeader = true;
            row.Height = 20;    //unit: point, 1point = 0.3528 mm
            row.HeightType = TableRowHeightType.Exactly;
            row.RowFormat.BackColor = Color.Gray;
            for (int i = 0; i < header.Length; i++)
            {
                row.Cells[i].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                Paragraph p = row.Cells[i].AddParagraph();
                p.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
                TextRange txtRange = p.AppendText(header[i]);
                txtRange.CharacterFormat.Bold = true;
            }

            for (int r = 0; r < data.Length; r++)
            {
                TableRow dataRow = table.Rows[r + 1];
                dataRow.Height = 20;
                dataRow.HeightType = TableRowHeightType.Exactly;
                dataRow.RowFormat.BackColor = Color.Empty;
                for (int c = 0; c < data[r].Length; c++)
                {
                    dataRow.Cells[c].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                    dataRow.Cells[c].AddParagraph().AppendText(data[r][c]);
                }
            }
        }
Example #32
0
        private void AddForm(Section section)
        {
            ParagraphStyle descriptionStyle = new ParagraphStyle(section.Document);
            descriptionStyle.Name = "description";
            descriptionStyle.CharacterFormat.FontSize = 12;
            descriptionStyle.CharacterFormat.FontName = "Arial";
            descriptionStyle.CharacterFormat.TextColor = Color.FromArgb(0x00, 0x45, 0x8e);
            section.Document.Styles.Add(descriptionStyle);

            Paragraph p1 = section.AddParagraph();
            String text1
                = "So that we can verify your identity and find your information, "
                + "please provide us with the following information. "
                + "This information will be used to create your online account. "
                + "Your information is not public, shared in anyway, or displayed on this site";
            p1.AppendText(text1);
            p1.ApplyStyle(descriptionStyle.Name);

            Paragraph p2 = section.AddParagraph();
            String text2
                = "You must provide a real email address to which we will send your password.";
            p2.AppendText(text2);
            p2.ApplyStyle(descriptionStyle.Name);
            p2.Format.AfterSpacing = 8;

            //field group label style
            ParagraphStyle formFieldGroupLabelStyle = new ParagraphStyle(section.Document);
            formFieldGroupLabelStyle.Name = "formFieldGroupLabel";
            formFieldGroupLabelStyle.ApplyBaseStyle("description");
            formFieldGroupLabelStyle.CharacterFormat.Bold = true;
            formFieldGroupLabelStyle.CharacterFormat.TextColor = Color.White;
            section.Document.Styles.Add(formFieldGroupLabelStyle);

            //field label style
            ParagraphStyle formFieldLabelStyle = new ParagraphStyle(section.Document);
            formFieldLabelStyle.Name = "formFieldLabel";
            formFieldLabelStyle.ApplyBaseStyle("description");
            formFieldLabelStyle.ParagraphFormat.HorizontalAlignment
                = Spire.Doc.Documents.HorizontalAlignment.Right;
            section.Document.Styles.Add(formFieldLabelStyle);

            //add table
            Table table = section.AddTable();

            //2 columns of per row
            table.DefaultColumnsNumber = 2;

            //default height of row is 20point
            table.DefaultRowHeight = 20;

            //load form config data
            using (Stream stream = File.OpenRead(@"..\..\..\..\..\..\Data\Form.xml"))
            {
                XPathDocument xpathDoc = new XPathDocument(stream);
                XPathNodeIterator sectionNodes = xpathDoc.CreateNavigator().Select("/form/section");
                foreach (XPathNavigator node in sectionNodes)
                {
                    //create a row for field group label, does not copy format
                    TableRow row = table.AddRow(false);
                    row.Cells[0].CellFormat.BackColor = Color.FromArgb(0x00, 0x71, 0xb6);
                    row.Cells[0].CellFormat.VerticalAlignment = VerticalAlignment.Middle;

                    //label of field group
                    Paragraph cellParagraph = row.Cells[0].AddParagraph();
                    cellParagraph.AppendText(node.GetAttribute("name", ""));
                    cellParagraph.ApplyStyle(formFieldGroupLabelStyle.Name);

                    XPathNodeIterator fieldNodes = node.Select("field");
                    foreach (XPathNavigator fieldNode in fieldNodes)
                    {
                        //create a row for field, does not copy format
                        TableRow fieldRow = table.AddRow(false);

                        //field label
                        fieldRow.Cells[0].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                        Paragraph labelParagraph = fieldRow.Cells[0].AddParagraph();
                        labelParagraph.AppendText(fieldNode.GetAttribute("label", ""));
                        labelParagraph.ApplyStyle(formFieldLabelStyle.Name);

                        fieldRow.Cells[1].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                        Paragraph fieldParagraph = fieldRow.Cells[1].AddParagraph();
                        String fieldId = fieldNode.GetAttribute("id", "");
                        switch (fieldNode.GetAttribute("type", ""))
                        {
                            case "text":
                                //add text input field
                                TextFormField field
                                    = fieldParagraph.AppendField(fieldId, FieldType.FieldFormTextInput) as TextFormField;

                                //set default text
                                field.DefaultText = "";
                                field.Text = "";
                                break;

                            case "list":
                                //add dropdown field
                                DropDownFormField list
                                    = fieldParagraph.AppendField(fieldId, FieldType.FieldFormDropDown) as DropDownFormField;

                                //add items into dropdown.
                                XPathNodeIterator itemNodes = fieldNode.Select("item");
                                foreach (XPathNavigator itemNode in itemNodes)
                                {
                                    list.DropDownItems.Add(itemNode.SelectSingleNode("text()").Value);
                                }
                                break;

                            case "checkbox":
                                //add checkbox field
                                fieldParagraph.AppendField(fieldId, FieldType.FieldFormCheckBox);
                                break;
                        }
                    }

                    //merge field group row. 2 columns to 1 column
                    table.ApplyHorizontalMerge(row.GetRowIndex(), 0, 1);
                }
            }
        }