Пример #1
0
 internal static void FillFormattedParagraph(Paragraph par)
 {
     for (int idx = 0; idx <= 140; ++idx)
     {
         if (idx < 60)
         {
             FormattedText formText = par.AddFormattedText((idx).ToString(), TextFormat.Bold);
             formText.Font.Size = 16;
             formText.AddText(" ");
         }
         else if (idx < 100)
         {
             par.AddText((idx).ToString());
             par.AddText(" ");
         }
         else
         {
             FormattedText formText = par.AddFormattedText((idx).ToString(), TextFormat.Italic);
             formText.Font.Size = 6;
             formText.AddText(" ");
         }
         if (idx % 50 == 0)
             par.AddLineBreak();
     }
     par.AddText(" ...ready.");
 }
Пример #2
0
        /// <summary>
        /// Adds a new paragraph with the specified text to the collection.
        /// </summary>
        public Paragraph AddParagraph(string text)
        {
            Paragraph paragraph = new Paragraph();

            paragraph.AddText(text);
            Add(paragraph);
            return(paragraph);
        }
Пример #3
0
        /// <summary>
        /// Adds a new Footnote with the specified Text.
        /// </summary>
        public Footnote AddFootnote(string text)
        {
            Footnote  footnote = new Footnote();
            Paragraph par      = footnote.Elements.AddParagraph();

            par.AddText(text);
            Add(footnote);
            return(footnote);
        }
Пример #4
0
        /// <summary>
        /// Adds a new paragraph with the specified text and style to the collection.
        /// </summary>
        public Paragraph AddParagraph(string text, string style)
        {
            Paragraph paragraph = new Paragraph();

            paragraph.AddText(text);
            paragraph.Style = style;
            Add(paragraph);
            return(paragraph);
        }
Пример #5
0
        protected override HtmlItem renderingHtmlText(HtmlItem it, ref Paragraph par, HtmlItem parent)
        {
            HtmlText te = it as HtmlText;
            if (te != null)
            {
                if (parent == null)
                {
                    par.AddText(te.Text);
                    it.SizeRenderItem.Width =calculateWithText( te.Text.Length ,8);
                    if (it.SizeRenderItem.Width > 210)
                        it.SizeRenderItem.Width = 210;
                    it.SizeRenderItem.Height = calculateHeightText(te.Text.Length, 8);
                }
            }

            return te;
        }
Пример #6
0
        /// <summary>
        /// Defines page setup, headers, and footers.
        /// </summary>
        private static void DefineContentSection(Document document, List<QueryData> data )
        {
            Section section = document.AddSection();
            //section.PageSetup.OddAndEvenPagesHeaderFooter = true;
            section.PageSetup.StartingNumber = 1;

            HeaderFooter header = section.Headers.Primary;
            header.AddParagraph(data[0].ProjectName + " - Отчет проверки данных от " + DateTime.Now.ToShortDateString() );
            header.Format.Alignment = ParagraphAlignment.Center;
            // Create a paragraph with centered page number. See definition of style "Footer".
            Paragraph paragraph = new Paragraph();
            paragraph.AddTab();
            paragraph.AddPageField();
            paragraph.AddText(" из ");
            paragraph.AddNumPagesField();
            // Add paragraph to footer for odd pages.
            section.Footers.Primary.Add(paragraph);
            // Add clone of paragraph to footer for odd pages. Cloning is necessary because an object must
            // not belong to more than one other object. If you forget cloning an exception is thrown.
            section.Footers.EvenPage.Add(paragraph.Clone());
        }
Пример #7
0
        private void CreatePage()
        {
            // Each MigraDoc document needs at least one section.
            MigraDoc.DocumentObjectModel.Section section = this.document.AddSection();

            // Put a logo in the header
            Image image = section.Headers.Primary.AddImage("Image_Icons/logo1.png");

            image.Height             = "2.5cm";
            image.Width              = "5cm";
            image.LockAspectRatio    = true;
            image.RelativeVertical   = RelativeVertical.Line;
            image.RelativeHorizontal = RelativeHorizontal.Margin;
            image.Top              = ShapePosition.Top;
            image.Left             = ShapePosition.Right;
            image.WrapFormat.Style = WrapStyle.Through;

            // Create the text frame for the address
            this.addressFrame                    = section.AddTextFrame();
            this.addressFrame.Height             = "8.0cm";
            this.addressFrame.Width              = "10.0cm";
            this.addressFrame.Left               = ShapePosition.Left;
            this.addressFrame.RelativeHorizontal = RelativeHorizontal.Margin;
            this.addressFrame.Top                = "4cm";
            this.addressFrame.RelativeVertical   = RelativeVertical.Page;

            this.PriceFrame                    = section.AddTextFrame();
            this.PriceFrame.Height             = "5.0cm";
            this.PriceFrame.Width              = "5.0cm";
            this.PriceFrame.Left               = ShapePosition.Right;
            this.PriceFrame.RelativeHorizontal = RelativeHorizontal.Margin;
            this.PriceFrame.Top                = "4.0cm";
            this.PriceFrame.RelativeVertical   = RelativeVertical.Page;

            // Put sender in address frame
            //= addressFrame.AddParagraph("ul.Pralki 5, 13-342 Lodówka");
            //paragraph.Format.Font.Name = "Times New Roman";
            //paragraph.Format.Font.Size = 7;
            //paragraph.Format.SpaceAfter = 3;

            // Add the print date field
            MigraDoc.DocumentObjectModel.Paragraph paragraph = section.AddParagraph();
            paragraph.Format.SpaceBefore = "8cm";
            paragraph.Style = "Reference";
            paragraph.AddFormattedText($"Faktura nr {order.Date.Year}/{order.Id}", TextFormat.Bold);
            paragraph.AddTab();
            paragraph.AddText("Białystok, ");
            paragraph.AddDateField("dd.MM.yyyy");

            paragraph = section.Footers.Primary.AddParagraph();
            paragraph.AddText($"\u00a9 2021 RTV&AGD \n ul.Pralki 5, 13-342 Lodówka \n Data wydruku: {DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss")} ");
            paragraph.Format.Font.Size = 9;
            paragraph.Format.Alignment = ParagraphAlignment.Center;

            // Create the item table
            this.table                = section.AddTable();
            table.Format.Alignment    = ParagraphAlignment.Justify;
            table.Borders.Color       = MigraDoc.DocumentObjectModel.Colors.Black;
            table.Borders.Width       = 0.25;
            table.Borders.Left.Width  = 0.5;
            table.Borders.Right.Width = 0.5;
            table.Rows.LeftIndent     = 5;
            table.TopPadding          = 10;
            table.BottomPadding       = 10;

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

            column.Format.Alignment = ParagraphAlignment.Center;

            column = this.table.AddColumn("1.5cm");
            column.Format.Alignment = ParagraphAlignment.Right;

            column = this.table.AddColumn("3.5cm");
            column.Format.Alignment = ParagraphAlignment.Right;

            column = this.table.AddColumn("3.5cm");
            column.Format.Alignment = ParagraphAlignment.Right;


            // Create the header of the table
            Row row = table.AddRow();

            row.HeadingFormat    = true;
            row.Format.Alignment = ParagraphAlignment.Left;
            row.Format.Font.Bold = true;
            row.Shading.Color    = TableBlue;
            row.Cells[0].AddParagraph("Nazwa");
            row.Cells[0].Format.Font.Bold  = true;
            row.Cells[0].Format.Alignment  = ParagraphAlignment.Left;
            row.Cells[0].VerticalAlignment = MigraDoc.DocumentObjectModel.Tables.VerticalAlignment.Center;

            row.Cells[1].AddParagraph("Ilość");
            row.Cells[1].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[2].AddParagraph("Cena/szt");
            row.Cells[2].Format.Alignment  = ParagraphAlignment.Left;
            row.Cells[2].VerticalAlignment = MigraDoc.DocumentObjectModel.Tables.VerticalAlignment.Center;

            row.Cells[3].AddParagraph("Wartosc");
            row.Cells[3].Format.Alignment  = ParagraphAlignment.Left;
            row.Cells[3].VerticalAlignment = MigraDoc.DocumentObjectModel.Tables.VerticalAlignment.Center;



            this.table.SetEdge(0, 0, 4, 1, Edge.Box, BorderStyle.Single, 0.75, MigraDoc.DocumentObjectModel.Color.Empty);
        }
Пример #8
0
        /// <summary>
        /// Adds fixed-width text to a MigraDoc paragraph
        /// </summary>
        /// <param name="paragraph">The paragaraph to add text to</param>
        /// <param name="text">The text</param>
        private static void AddFixedWidthText(Paragraph paragraph, string text, int width)
        {
            //For some reason, a parapraph converts all sequences of white
            //space to a single space.  Thus we need to split the text and add
            //the spaces using the AddSpace function.

            int numSpaces = width - text.Length;

            paragraph.AddSpace(numSpaces);
            paragraph.AddText(text);
        }
Пример #9
0
        private static Document CreatePDF(SetViewModel obj)
        {
            Document doc = new Document();

            //Defining styles
            Style style = doc.Styles["Normal"];
            style.Font.Name = "Arial";
            style.Font.Size = 6;

            style = doc.Styles[StyleNames.Header];
            style.ParagraphFormat.AddTabStop("16cm", TabAlignment.Right);

            style = doc.Styles[StyleNames.Footer];
            style.ParagraphFormat.AddTabStop("8cm", TabAlignment.Right);

            foreach (var itemSet in obj.Set)
            {

                //Define content section
                Section section = doc.AddSection();
                section.PageSetup.StartingNumber = 1;
                section.PageSetup.LeftMargin = "0.7cm";
                section.PageSetup.RightMargin = "0.7cm";
                section.PageSetup.BottomMargin = "0.5cm";
                section.PageSetup.TopMargin = "1.4cm";
                section.PageSetup.FooterDistance = "0.5cm";
                section.PageSetup.HeaderDistance = "0.5cm";

                // Create Header
                Table hTable = section.Headers.Primary.AddTable();
                hTable.Borders.Width = 0;
                var hlColumn = hTable.AddColumn("6cm");
                hlColumn.Format.Alignment = ParagraphAlignment.Left;
                var hcColumn = hTable.AddColumn("8cm");
                hlColumn.Format.Alignment = ParagraphAlignment.Center;
                var hrColumn = hTable.AddColumn("6cm");
                hrColumn.Format.Alignment = ParagraphAlignment.Right;
                var hRow = hTable.AddRow();
                var hCell = hRow.Cells[0];
                hCell.AddParagraph("НИИ Антимикробной химиотерапии");
                hCell.Format.Alignment = ParagraphAlignment.Left;
                hCell = hRow.Cells[1];
                hCell.AddParagraph(itemSet.AB);
                hCell.Format.Alignment = ParagraphAlignment.Center;
                hCell = hRow.Cells[2];

                hCell.AddParagraph("Исследование " + itemSet.Project);
                hCell.Format.Alignment = ParagraphAlignment.Right;
                hRow = hTable.AddRow();
                hCell = hRow.Cells[0];
                hCell.AddParagraph("Метод тестирования: " + itemSet.TestMethod);
                hCell.Format.Alignment = ParagraphAlignment.Left;
                hCell = hRow.Cells[2];
                hCell.AddParagraph("Сет:  " + itemSet.Set + " - " + "Антибиотик: " + itemSet.AB);
                hCell.Format.Alignment = ParagraphAlignment.Right;
                hRow = hTable.AddRow();
                hCell = hRow.Cells[0];
                hCell.AddParagraph("Дата печати: " + DateTime.Now.ToShortDateString());
                hCell.Format.Alignment = ParagraphAlignment.Left;
                Paragraph fPar = new Paragraph();
                fPar.AddText("Страница ");
                fPar.AddPageField();
                fPar.AddText(" из ");
                fPar.AddSectionPagesField();
                hCell = hRow.Cells[2];
                hCell.Add(fPar);
                hCell.Format.Alignment = ParagraphAlignment.Right;

                hCell = hTable.Rows[0].Cells[1];
                hCell.MergeDown = 2;

                hCell.Format.Font.Bold = true;
                hCell.Format.Font.Size = 9;
                hCell.Format.Alignment = ParagraphAlignment.Center;

                // Create table

                Table table;
                Row row;
                Cell cell;
                CreateMicTable(doc, itemSet, section, out table, out row, out cell);

                foreach (var item in itemSet.MOList)
                {
                    row = table.AddRow();
                    row.Height = "0.55cm";
                    cell = row.Cells[0];
                    cell.VerticalAlignment = VerticalAlignment.Center;
                    cell.AddParagraph(item.Cell);
                    cell = row.Cells[1];
                    cell.VerticalAlignment = VerticalAlignment.Center;
                    cell.AddParagraph(item.MuseumNumber);
                    cell = row.Cells[2];
                    cell.VerticalAlignment = VerticalAlignment.Center;
                    cell.AddParagraph(item.MO);
                    if (item.Number % 12 == 0)
                    {
                        row.Borders.Bottom.Width = "0.05cm";
                    }
                    if ((item.Number % 48 == 0) && (item.Number > 10))
                    {
                        doc.LastSection.Add(table);
                        doc.LastSection.AddPageBreak();
                        CreateMicTable(doc, itemSet, section, out table, out row, out cell);

                    }
                }

                foreach (var item in itemSet.ControlMOList)
                {
                    row = table.AddRow();
                    row.Height = "0.5cm";
                    cell = row.Cells[0];
                    cell.VerticalAlignment = VerticalAlignment.Center;
                    cell.AddParagraph(item.Cell);
                    cell.Shading.Color = Colors.LightGray;
                    cell = row.Cells[1];
                    cell.VerticalAlignment = VerticalAlignment.Center;
                    cell.AddParagraph(item.MuseumNumber);
                    cell.Shading.Color = Colors.LightGray;
                    cell = row.Cells[2];
                    cell.VerticalAlignment = VerticalAlignment.Center;
                    cell.Shading.Color = Colors.LightGray;
                    cell.AddParagraph(item.MO);

                }

                doc.LastSection.Add(table);

            }
            return doc;
        }
        private Document CreateDocument(List<domain.Product> productList, decimal euro2cny, decimal serviceRate)
        {
            productList.OrderBy(x => x.Brand);

            Document document = new Document();
            document.Styles[StyleNames.Normal].Font.Name = "Arial Unicode MS";
            document.Styles[StyleNames.Normal].Font.Color = new Color(30, 30, 30);

            Section section = document.AddSection();
            section.PageSetup.LeftMargin = 20;
            section.PageSetup.TopMargin = 20;
            Paragraph header = new Paragraph();
            header.Format.Font.Size = 35;
            header.Format.Alignment = ParagraphAlignment.Center;
            header.AddText("");
            header.AddLineBreak(); header.AddLineBreak(); header.AddLineBreak();
            header.AddText("吕贝克Nx-daigou商品报价单");
            header.AddLineBreak(); header.AddLineBreak(); header.AddLineBreak();
            document.LastSection.Add(header);

            Paragraph code = new Paragraph();
            code.Format.Font.Size = 15;
            string codeTxt = "编号: " + (euro2cny * 100.0m).ToString() + "-" + (serviceRate * 100.0m).ToString();
            code.AddText(codeTxt.Replace(".","#"));
            code.Format.Alignment = ParagraphAlignment.Center;
            code.AddLineBreak(); code.AddLineBreak(); code.AddLineBreak();
            document.LastSection.Add(code);

            Paragraph time = new Paragraph();
            time.Format.Alignment = ParagraphAlignment.Center;
            time.Format.Font.Size = 15;

            DateTimeFormatInfo chDatetimeCulture = new CultureInfo("zh-CN", false).DateTimeFormat;
            string result = DateTime.Today.ToString(chDatetimeCulture.LongDatePattern);
            time.AddText("日期: " + result);
            time.AddLineBreak(); time.AddLineBreak(); time.AddLineBreak();
            document.LastSection.Add(time);


            string productCountTxt = "商品总数: " + productList.Count.ToString();
            Paragraph productCountPara = new Paragraph();
            productCountPara.Format.Alignment = ParagraphAlignment.Center;
            productCountPara.AddText(productCountTxt);
            productCountPara.AddLineBreak(); productCountPara.AddLineBreak();
            document.LastSection.Add(productCountPara);


            string remarkTxt = "说明: 报价单里的价格均不包含邮费";
            Paragraph remarkheaderPara = new Paragraph();
            remarkheaderPara.Format.Alignment = ParagraphAlignment.Center;
            remarkheaderPara.Format.Font.Size = 10;
            remarkheaderPara.AddText(remarkTxt);
            remarkheaderPara.AddLineBreak();
            document.LastSection.Add(remarkheaderPara);


            document.LastSection.AddPageBreak();
            
            string lastBrand = "";
            int index = 1;

            foreach (var item in productList)
            {
                if ( lastBrand != item.Brand)
                {
                    Paragraph p = new Paragraph();
                    p.Format.Font.Size = 15;
                    p.Format.Font.Bold = true;
                    p.Format.Font.Color = Colors.DarkBlue;
                    p.AddText("==" + item.Brand + "==");
                    document.LastSection.Add(p);
                    lastBrand = item.Brand;                    
                }
 
                Table table = document.LastSection.AddTable();                
                table.Borders.Visible = true;
                table.Borders.Color = Colors.Gray;


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

                column = table.AddColumn(Unit.FromCentimeter(12));
                column.Format.Alignment = ParagraphAlignment.Left;

                column = table.AddColumn(Unit.FromCentimeter(3));
                column.Format.Alignment = ParagraphAlignment.Left;
    

                table.Rows.Height = 10;

                Row row = table.AddRow();
                row.Cells[0].MergeDown = 2;
                string path = (item.Photo.IsNullOrEmpty()) ? "images\\default.png" : item.Photo;

                Paragraph imagePara = new Paragraph();
                imagePara.Add(CreateImage(DirectoryHelper.CombineWithCurrentExeDir(path)));
                imagePara.Format.Alignment = ParagraphAlignment.Center;

                row.Cells[0].Add(imagePara);
                row.Cells[1].AddParagraph("编号: " + item.ID + "\t\t别名:" + item.Code + "   ");

                string priceTxt = this.productPriceCalcuateService.GetPrice(item, euro2cny * serviceRate).ToString() + "元";
                Paragraph pricePara = new Paragraph();
                pricePara.AddText(priceTxt);
                pricePara.Format.Font.Color = Colors.OrangeRed;
                row.Cells[2].Add(pricePara);               


                row = table.AddRow();
                string productNameTxt = item.Brand + "->" + item.Name;
                Paragraph productNamePara = new Paragraph();
                productNamePara.AddText(productNameTxt);
                productNamePara.Format.Font.Color = Colors.DarkBlue;
                row.Cells[1].Add(productNamePara);      
          
                row.Cells[2].AddParagraph("重量: " + item.GrossWeight + " g");


                row = table.AddRow();
                row.Cells[1].AddParagraph("[规格:" + item.Spec + "]              [适用于:" + item.ApplicableCrowd+"]");

                Paragraph remarkPara = new Paragraph();
                remarkPara.AddText(item.Remark);
                remarkPara.Format.Font.Size = 8;
                row.Cells[1].Add(remarkPara);

                Paragraph tagListPara = new Paragraph();
                tagListPara.AddText(item.TagList);
                tagListPara.Format.Font.Size = 8;
                row.Cells[2].Add(tagListPara);                    

                table.SetEdge(0, 0, 3, 3, Edge.Top, BorderStyle.Single, 2, Colors.Black);

                index++; 
            }

            return document;
        }
Пример #11
0
        /// <summary>
        /// The write equation.
        /// </summary>
        /// <param name="equation">
        /// The equation.
        /// </param>
        public void WriteEquation(Equation equation)
        {
            Paragraph p = this.CurrentSection.AddParagraph();

            p.AddText("Equations are not supported.");
        }
Пример #12
0
        private static MigraDoc.Rendering.PdfDocumentRenderer CreatePeopleListDocument(Person currentUser, List<PersonListViewModel> churchList, string documentType)
        {
            // Create new MigraDoc document
            Document document = new Document();
            document.Info.Title = documentType + " List for " + currentUser.Church.Name;
            document.Info.Author = "oikonomos";
            document.Info.Subject = documentType + " List";
            Section sec = document.AddSection();
            sec.PageSetup.TopMargin = Unit.FromCentimeter(1);
            sec.PageSetup.LeftMargin = Unit.FromCentimeter(1);
            document.DefaultPageSetup.TopMargin = Unit.FromCentimeter(1);
            document.DefaultPageSetup.LeftMargin = Unit.FromCentimeter(1);

            Paragraph p = new Paragraph();
            p.AddText(documentType + " List for " + currentUser.Church.Name);
            p.Format.Font.Size = 6.0;
            sec.Footers.Primary.Add(p);

            MigraDoc.DocumentObjectModel.Tables.Table table = new MigraDoc.DocumentObjectModel.Tables.Table();
            AddHeaders(table, documentType + "s");

            var style = document.Styles["Normal"];
            style.Font.Size = 8.0;
            TextMeasurement tm = new TextMeasurement(style.Font.Clone());
            int familyId = 0;
            foreach (PersonListViewModel person in churchList)
            {
                Row row=table.AddRow();
                Cell cell = row.Cells[0];
                if (familyId != person.FamilyId)
                {
                    cell.Format.Font.Bold = true;
                    cell.AddParagraph(AdjustIfTooWideToFitIn(cell, person.Surname, tm));
                }
                cell = row.Cells[1];
                cell.AddParagraph(AdjustIfTooWideToFitIn(cell, person.Firstname, tm));
                cell = row.Cells[2];
                if (familyId != person.FamilyId)
                {
                    cell.AddParagraph(AdjustIfTooWideToFitIn(cell, person.HomePhone ?? string.Empty, tm));
                }
                cell = row.Cells[3];
                cell.AddParagraph(AdjustIfTooWideToFitIn(cell, person.WorkPhone ?? string.Empty, tm));
                cell = row.Cells[4];
                cell.AddParagraph(AdjustIfTooWideToFitIn(cell, person.CellPhone ?? string.Empty, tm));
                cell = row.Cells[5];
                cell.AddParagraph(AdjustIfTooWideToFitIn(cell, person.Email ?? string.Empty, tm));
                familyId = person.FamilyId;
            }

            sec.Add(table);

            MigraDoc.Rendering.PdfDocumentRenderer pdfRender = new MigraDoc.Rendering.PdfDocumentRenderer(false, PdfSharp.Pdf.PdfFontEmbedding.Always);
            pdfRender.Document = document; //document is where all of my info has been written to and is a MigraDoc type
            pdfRender.RenderDocument();

            return pdfRender;
        }
Пример #13
0
        public void CreateCharacterCertificatePDF(string[] CertificateData, string admNo, int admYear)
        {
            if (CertificateData.Length != 5)
            {
                return;
            }
            else
            {
                // Generate nmhs-nexap directory in my document folder
                string containerfolder  = this.GenerateDocumentBaseDirectory();
                MigraModel.Document doc = new MigraModel.Document();
                MigraModel.Section  sec = doc.AddSection();
                sec.PageSetup           = doc.DefaultPageSetup.Clone();
                sec.PageSetup.TopMargin = ".7cm";

                MigraDoc.DocumentObjectModel.Shapes.TextFrame tframe = sec.AddTextFrame();
                tframe.AddImage("nmhs-logo.jpg");
                tframe.Left               = "-.5cm";
                tframe.Top                = "0.7cm";
                tframe.RelativeVertical   = MigraModel.Shapes.RelativeVertical.Page;
                tframe.RelativeHorizontal = MigraModel.Shapes.RelativeHorizontal.Margin;

                MigraModel.Paragraph paraSchoolName = sec.AddParagraph();
                paraSchoolName.Format.Font.Name  = "Times New Roman";
                paraSchoolName.Format.Alignment  = MigraModel.ParagraphAlignment.Center;
                paraSchoolName.Format.Font.Size  = 25;
                paraSchoolName.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkBlue;
                string schoolName = "NAIMOUZA HIGH SCHOOL";
                paraSchoolName.AddFormattedText(schoolName, MigraModel.TextFormat.Bold);

                MigraModel.Paragraph paraSchoolAddress = sec.AddParagraph();
                paraSchoolAddress.Format.Font.Size = 14;
                paraSchoolAddress.Format.Alignment = MigraModel.ParagraphAlignment.Center;
                string addrs = "Vill. & P.O. Sujapur, Dist. Malda, 732206";
                paraSchoolAddress.AddText(addrs);

                MigraModel.Paragraph paraSchoolMeta = sec.AddParagraph();
                paraSchoolMeta.Format.Font.Size = 10;
                paraSchoolMeta.Format.Alignment = MigraModel.ParagraphAlignment.Center;
                string meta = "INDEX NO. - R1-110, CONTACT NO. - 03512-246525";
                paraSchoolMeta.AddFormattedText(meta, MigraModel.TextFormat.NotBold);

                MigraModel.Paragraph paraAdmissionMeta = sec.AddParagraph();
                paraAdmissionMeta.Format.Font.Size = 10;
                paraAdmissionMeta.Format.Alignment = MigraModel.ParagraphAlignment.Right;
                string admYr = (admYear != 0) ? admYear.ToString() : "0000";
                string ameta = "Admission Sl. " + admNo + " of " + admYr;
                paraAdmissionMeta.AddFormattedText(ameta, MigraModel.TextFormat.Bold);

                MigraModel.Paragraph paraCertificateType = sec.AddParagraph();
                paraCertificateType.Format.Font.Size = 18;
                paraCertificateType.Format.Alignment = MigraModel.ParagraphAlignment.Center;
                paraCertificateType.AddLineBreak();
                string ctype = "CHARACTER CERTIFICATE";
                paraCertificateType.AddFormattedText(ctype, MigraModel.TextFormat.NotBold);

                MigraModel.Paragraph para_a = sec.AddParagraph();
                para_a.Format.Font.Name  = "Lucida Handwriting";
                para_a.Format.Font.Size  = 16;
                para_a.Format.Font.Color = MigraModel.Colors.DarkBlue;
                para_a.Format.Alignment  = MigraModel.ParagraphAlignment.Justify;
                para_a.AddLineBreak();
                para_a.AddLineBreak();
                para_a.AddLineBreak();
                para_a.AddLineBreak();
                para_a.AddTab();

                string para_aText, para_aTextb, paraTextc, paraTextd, stdName;
                para_aText  = CertificateData[0].Trim();
                para_aTextb = CertificateData[1].Trim();
                paraTextc   = CertificateData[2].Trim();
                paraTextd   = CertificateData[3].Trim();
                stdName     = CertificateData[4].Trim();

                para_a.AddText(para_aText);

                MigraModel.Paragraph para_b = sec.AddParagraph();
                para_b.Format.Font.Name  = "Lucida Handwriting";
                para_b.Format.Font.Size  = 16;
                para_b.Format.Font.Color = MigraModel.Colors.DarkBlue;
                para_b.Format.Alignment  = MigraModel.ParagraphAlignment.Justify;
                para_b.AddLineBreak();
                para_b.AddTab();
                para_b.AddText(para_aTextb);

                MigraModel.Paragraph para_c = sec.AddParagraph();
                para_c.Format.Font.Name  = "Lucida Handwriting";
                para_c.Format.Font.Size  = 16;
                para_c.Format.Font.Color = MigraModel.Colors.DarkBlue;
                para_c.Format.Alignment  = MigraModel.ParagraphAlignment.Justify;
                para_c.AddLineBreak();
                para_c.AddTab();
                para_c.AddText(paraTextc);

                MigraModel.Paragraph para_d = sec.AddParagraph();
                para_d.Format.Font.Name  = "Lucida Handwriting";
                para_d.Format.Font.Size  = 16;
                para_d.Format.Font.Color = MigraModel.Colors.DarkBlue;
                para_d.Format.Alignment  = MigraModel.ParagraphAlignment.Justify;
                para_d.AddLineBreak();
                para_d.AddTab();
                para_d.AddText(paraTextd);


                MigraDoc.DocumentObjectModel.Shapes.TextFrame tframeHMaster = sec.AddTextFrame();
                MigraModel.Paragraph paraHMaster = tframeHMaster.AddParagraph();
                paraHMaster.Format.Font.Size = "14";
                paraHMaster.Format.Alignment = MigraModel.ParagraphAlignment.Center;
                string txt1 = "Headmaster";
                string txt2 = "Naimuza High School";
                string txt3 = "Sujapur, Malda";
                paraHMaster.AddText(txt1);
                paraHMaster.AddLineBreak();
                paraHMaster.AddText(txt2);
                paraHMaster.AddLineBreak();
                paraHMaster.AddText(txt3);
                tframeHMaster.Width              = "6cm";
                tframeHMaster.Left               = "10cm";
                tframeHMaster.Top                = "19cm";
                tframeHMaster.RelativeVertical   = MigraModel.Shapes.RelativeVertical.Page;
                tframeHMaster.RelativeHorizontal = MigraModel.Shapes.RelativeHorizontal.Margin;

                MigraDoc.Rendering.PdfDocumentRenderer docRend = new MigraDoc.Rendering.PdfDocumentRenderer(false);
                docRend.Document = doc;
                try
                {
                    docRend.RenderDocument();
                }
                catch (Exception e)
                {
                    System.Windows.MessageBox.Show(e.Message);
                    return;
                }
                string fname      = "CHR_" + stdName + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".pdf";
                string pathString = Path.Combine(containerfolder, fname);
                docRend.PdfDocument.Save(pathString);

                System.Diagnostics.ProcessStartInfo processInfo = new System.Diagnostics.ProcessStartInfo();
                processInfo.FileName = pathString;
                System.Diagnostics.Process.Start(processInfo);
            }
        }
Пример #14
0
 /// <summary>
 /// Adds a new paragraph with the specified text to the collection.
 /// </summary>
 public Paragraph AddParagraph(string text)
 {
   Paragraph paragraph = new Paragraph();
   paragraph.AddText(text);
   Add(paragraph);
   return paragraph;
 }
Пример #15
0
 /// <summary>
 /// Adds a new paragraph with the specified text and style to the collection.
 /// </summary>
 public Paragraph AddParagraph(string text, string style)
 {
   Paragraph paragraph = new Paragraph();
   paragraph.AddText(text);
   paragraph.Style = style;
   Add(paragraph);
   return paragraph;
 }
        public void MakeGiftCert(int itemID)
        {
            try
            {
                GiftCertificateInfo item;
                //load the item
                GiftCertificateController controller = new GiftCertificateController();
                item = controller.GetGiftCert(itemId);

                string CertAmountWords    = "";
                string MailToAddressField = "";
                string CertAmountNumber   = "";

                if (item != null)
                {
                    if (item.PaypalPaymentState.ToString().Length == 0)
                    {
                        Response.Redirect(Globals.NavigateURL("Access Denied"), true);
                    }

                    TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;

                    CertAmountWords  = textInfo.ToTitleCase(NumberToWords(Int32.Parse(item.CertAmount.ToString())).ToString()).ToString() + " Dollars" + Environment.NewLine;
                    CertAmountNumber = "$" + String.Format("{0:f2}", item.CertAmount).ToString();

                    MailToAddressField = item.MailTo.ToString() + Environment.NewLine
                                         + item.MailToAddress.ToString() + Environment.NewLine
                                         + item.MailToCity.ToString() + ", " + item.MailToState.ToString() + " " + item.MailToZip.ToString();

                    _CertNotes = item.Notes.ToString();
                }


                string myPortalName = this.PortalSettings.PortalName.ToString();



                Document document = new Document();
                document.Info.Author   = "Joseph Aucoin";
                document.Info.Keywords = "Gift Certificate";
                document.Info.Title    = myPortalName.ToString() + " Gift Certificate";

                // Get the A4 page size
                MigraDoc.DocumentObjectModel.Unit width, height;
                PageSetup.GetPageSize(PageFormat.Letter, out width, out height);



                // Add a section to the document and configure it such that it will be in the centre
                // of the page
                Section section = document.AddSection();
                section.PageSetup.PageHeight  = height;
                section.PageSetup.PageWidth   = width;
                section.PageSetup.LeftMargin  = 20;
                section.PageSetup.RightMargin = 10;
                section.PageSetup.TopMargin   = 20; // height / 2;



                //++++++++++++++++++++++++++++++
                //++++++++++++++++++++++++++++++
                //++++++++++++++++++++++++++++++
                // ADD LOGO
                string myLogo = PortalSettings.HomeDirectoryMapPath + _CertLogo.ToString(); // "Images\\Chapins-Logo.png";
                MigraDoc.DocumentObjectModel.Shapes.Image image = section.Headers.Primary.AddImage(myLogo.ToString());

                image.LockAspectRatio    = true;
                image.RelativeVertical   = MigraDoc.DocumentObjectModel.Shapes.RelativeVertical.Line;
                image.RelativeHorizontal = MigraDoc.DocumentObjectModel.Shapes.RelativeHorizontal.Margin;
                image.Top              = MigraDoc.DocumentObjectModel.Shapes.ShapePosition.Top;
                image.Left             = MigraDoc.DocumentObjectModel.Shapes.ShapePosition.Right;
                image.WrapFormat.Style = MigraDoc.DocumentObjectModel.Shapes.WrapStyle.Through;

                MigraDoc.DocumentObjectModel.Tables.Table HeaderTable = new MigraDoc.DocumentObjectModel.Tables.Table();
                HeaderTable.Borders.Width         = 0; // Default to show borders 1 pixel wide Column
                HeaderTable.LeftPadding           = 10;
                HeaderTable.RightPadding          = 10;
                HeaderTable.Borders.Left.Visible  = false;
                HeaderTable.Borders.Right.Visible = false;


                // Add 1 columns
                float myColumnWidth = ((section.PageSetup.PageWidth - section.PageSetup.LeftMargin - section.PageSetup.RightMargin) / 2);   // ((width / 2) - 10);
                MigraDoc.DocumentObjectModel.Tables.Column column0 = HeaderTable.AddColumn(myColumnWidth);

                MigraDoc.DocumentObjectModel.Tables.Row row1 = HeaderTable.AddRow();
                row1.Cells[0].Elements.AddParagraph(_CertReturnAddress.ToString());
                row1.Cells[0].Format.Alignment = ParagraphAlignment.Left;


                section.Add(HeaderTable);

                /// SPACING
                MigraDoc.DocumentObjectModel.Paragraph paragraph = section.AddParagraph();
                paragraph.Format.LineSpacingRule = MigraDoc.DocumentObjectModel.LineSpacingRule.Exactly;
                paragraph.Format.LineSpacing     = MigraDoc.DocumentObjectModel.Unit.FromMillimeter(30.0);

                //   section.Add(paragraph);

                //++++++++++++++++++++++++++++++
                // ADD ANOTHER TABLE FOR MAIL TO ADDRESS
                // Create a table so that we can draw the horizontal lines
                MigraDoc.DocumentObjectModel.Tables.Table tableMailToAddress = new MigraDoc.DocumentObjectModel.Tables.Table();
                tableMailToAddress.Borders.Width = 0; // Default to show borders 1 pixel wide Column
                tableMailToAddress.LeftPadding   = 20;
                tableMailToAddress.RightPadding  = 10;

                //  float myColumnWidth100percent = (width - 10);
                var column = tableMailToAddress.AddColumn((section.PageSetup.PageWidth - section.PageSetup.LeftMargin - section.PageSetup.RightMargin));

                double fontHeight = 20;
                Font   font       = new Font("Times New Roman", fontHeight);

                // Add a row with a single cell for the first line
                MigraDoc.DocumentObjectModel.Tables.Row  row  = tableMailToAddress.AddRow();
                MigraDoc.DocumentObjectModel.Tables.Cell cell = row.Cells[0];


                cell = row.Cells[0];

                cell.Format.Font.Color = Colors.Black;
                cell.Format.Alignment  = ParagraphAlignment.Left;
                cell.Format.Font.ApplyFont(font);

                cell.AddParagraph(MailToAddressField.ToString());

                section.Add(tableMailToAddress);

                // ADD SPACER+++++++++++++++++++++++++++++++++++++++
                MigraDoc.DocumentObjectModel.Paragraph paragraph1 = section.AddParagraph();
                paragraph1.Format.LineSpacingRule = MigraDoc.DocumentObjectModel.LineSpacingRule.Exactly;
                paragraph1.Format.LineSpacing     = MigraDoc.DocumentObjectModel.Unit.FromMillimeter(20.0);



                // ADD ANOTHER TABLE FOR CERT
                // Create a table so that we can draw the horizontal lines
                MigraDoc.DocumentObjectModel.Tables.Table tableCert = new MigraDoc.DocumentObjectModel.Tables.Table();
                tableCert.Borders.Width         = 0; // Default to show borders 1 pixel wide Column
                tableCert.LeftPadding           = 10;
                tableCert.RightPadding          = 10;
                tableCert.Borders.Right.Visible = true;

                //  float myColumnWidth100percent = (width - 10);
                float sectionWidth = section.PageSetup.PageWidth - section.PageSetup.LeftMargin - section.PageSetup.RightMargin;
                float columnWidth  = sectionWidth;


                var columnCert = tableCert.AddColumn(columnWidth);
                columnCert.Format.Alignment = ParagraphAlignment.Center;

                double fontHeightCert = 30;
                Font   fontCert       = new Font("Times New Roman", fontHeightCert);

                // Add a row with a single cell for the first line
                MigraDoc.DocumentObjectModel.Tables.Row  rowCert  = tableCert.AddRow();
                MigraDoc.DocumentObjectModel.Tables.Cell cellCert = rowCert.Cells[0];

                cellCert.Format.Font.Color = Colors.Black;
                cellCert.Format.Font.ApplyFont(fontCert);
                cellCert.Borders.Left.Visible   = false;
                cellCert.Borders.Right.Visible  = false;
                cellCert.Borders.Bottom.Visible = false;

                cellCert.AddParagraph(_CertBannerText.ToString());

                // Add a row with a single cell for the second line
                rowCert  = tableCert.AddRow();
                cellCert = rowCert.Cells[0];

                cellCert.Format.Font.Color = Colors.Black;
                cellCert.Format.Alignment  = ParagraphAlignment.Center;
                cellCert.Format.Font.ApplyFont(fontCert);
                cellCert.Borders.Left.Visible  = false;
                cellCert.Borders.Right.Visible = false;
                cellCert.Borders.Top.Visible   = false;

                cellCert.AddParagraph(CertAmountWords.ToString());

                // 3RD LINE
                // Add a row with a single cell for the third line
                rowCert  = tableCert.AddRow();
                cellCert = rowCert.Cells[0];


                Font fontCertDetails = new Font("Times New Roman", 20);
                cellCert.Format.Font.Color = Colors.Black;

                cellCert.Format.Alignment = ParagraphAlignment.Left;
                cellCert.Format.Font.ApplyFont(fontCertDetails);
                cellCert.Borders.Left.Visible  = false;
                cellCert.Borders.Right.Visible = false;
                cellCert.Borders.Top.Visible   = false;

                cellCert.Format.SpaceBefore = MigraDoc.DocumentObjectModel.Unit.FromMillimeter(10.0);
                cellCert.Format.LeftIndent  = MigraDoc.DocumentObjectModel.Unit.FromMillimeter(15.0);
                cellCert.AddParagraph("Date:" + item.CreatedDate.ToShortDateString() + Environment.NewLine + "Presented to: " + item.ToName.ToString() + Environment.NewLine +
                                      "From: " + item.FromName.ToString() + Environment.NewLine + "Amount: " + CertAmountNumber.ToString());


////////////////////////////////
                // 4th LINE
                // Add a row with a single cell for the forth line
                rowCert  = tableCert.AddRow();
                cellCert = rowCert.Cells[0];


                Font fontCertSignature = new Font("Arial", 12);
                cellCert.Format.Font.Color = Colors.Black;

                cellCert.Format.Alignment = ParagraphAlignment.Left;
                cellCert.Format.Font.ApplyFont(fontCertSignature);
                cellCert.Borders.Left.Visible  = false;
                cellCert.Borders.Right.Visible = false;
                cellCert.Borders.Top.Visible   = false;

                cellCert.Format.SpaceBefore = MigraDoc.DocumentObjectModel.Unit.FromMillimeter(10.0);
                cellCert.Format.LeftIndent  = MigraDoc.DocumentObjectModel.Unit.FromMillimeter(15.0);
                cellCert.AddParagraph("Authorized Signature: __________________________________________________");

                ////////////////////////////////
                // 5th LINE
                // Add a row with a single cell for the fifth line
                rowCert  = tableCert.AddRow();
                cellCert = rowCert.Cells[0];


                Font fontCertInvoiceNumber = new Font("Arial", 10);
                cellCert.Format.Font.Color = Colors.Black;

                cellCert.Format.Alignment = ParagraphAlignment.Center;
                cellCert.Format.Font.ApplyFont(fontCertInvoiceNumber);
                cellCert.Borders.Left.Visible  = false;
                cellCert.Borders.Right.Visible = false;
                cellCert.Borders.Top.Visible   = false;
                //      cellCert.Format.AddTabStop("16cm", TabAlignment.Right);
                cellCert.Format.SpaceBefore = MigraDoc.DocumentObjectModel.Unit.FromMillimeter(3.0);
                //cellCert.Format.LeftIndent = MigraDoc.DocumentObjectModel.Unit.FromMillimeter(15.0);
                cellCert.AddParagraph("Certificate Number 00" + item.ItemId.ToString());

                document.LastSection.Add(tableCert);


                if (item.Notes.ToString().Trim().Length > 0)
                {
                    //+++++++++ ADD PARAGRAPH FOR BUYER NOTES
                    MigraDoc.DocumentObjectModel.Paragraph paragraphFooter = section.AddParagraph();
                    paragraphFooter.Format.LineSpacingRule = MigraDoc.DocumentObjectModel.LineSpacingRule.Exactly;
                    paragraphFooter.Format.LineSpacing     = MigraDoc.DocumentObjectModel.Unit.FromMillimeter(8.0);
                    paragraphFooter.Format.SpaceBefore     = MigraDoc.DocumentObjectModel.Unit.FromMillimeter(10.0);
                    paragraphFooter.AddText("NOTES:" + Environment.NewLine + _CertNotes.ToString());
                }



                Paragraph footerText = new Paragraph();
                footerText.Format.Alignment = ParagraphAlignment.Center;
                footerText.AddText(_CertFooterText.ToString());

                section.Footers.Primary.Add(footerText);



                // Create a renderer
                PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer();

                // Associate the MigraDoc document with a renderer
                pdfRenderer.Document = document;

                // Layout and render document to PDF
                pdfRenderer.RenderDocument();


                string pdfFilename = PortalSettings.HomeDirectoryMapPath + _PdfFilesFolder.ToString() + "Cert" + itemId.ToString() + ".pdf";

                if (File.Exists(pdfFilename))
                {
                    File.Delete(pdfFilename);
                }

                pdfRenderer.PdfDocument.Save(pdfFilename);



                bool watermarkIsNeeded = false;
                if (_CertWatermark.ToString().Trim().Length > 1)
                {
                    watermarkIsNeeded = true;
                }

                if (watermarkIsNeeded)
                {
                    PdfDocument pdfIn  = PdfReader.Open(pdfFilename, PdfDocumentOpenMode.Import);
                    PdfDocument pdfOut = new PdfDocument();

                    for (int i = 0; i < pdfIn.PageCount; i++)
                    {
                        PdfPage pg = pdfIn.Pages[i];
                        pg = pdfOut.AddPage(pg);
                        // WATERMARK TEXT
                        string draftFlagStr = _CertWatermark.ToString();

                        // Get an XGraphics object for drawing beneath the existing content
                        XGraphics gfx = XGraphics.FromPdfPage(pg, XGraphicsPdfPageOptions.Prepend);

                        // Get the size (in point) of the text
                        XFont fontWM = new XFont("Verdana", 62, XFontStyle.Bold);
                        XSize size   = gfx.MeasureString(draftFlagStr, fontWM);

                        // Define a rotation transformation at the center of the page
                        gfx.TranslateTransform(pg.Width / 2, pg.Height / 2);
                        gfx.RotateTransform(-Math.Atan(pg.Height / pg.Width) * 180 / Math.PI);
                        gfx.TranslateTransform(-pg.Width / 2, -pg.Height / 2);

                        // Create a string format
                        XStringFormat format = new XStringFormat();
                        format.Alignment     = XStringAlignment.Near;
                        format.LineAlignment = XLineAlignment.Near;

                        // Create a dimmed red brush
                        XBrush brush = new XSolidBrush(XColor.FromArgb(32, 0, 0, 255));

                        // Draw the string
                        gfx.DrawString(draftFlagStr, fontWM, brush,
                                       new XPoint((pg.Width - size.Width) / 2, (pg.Height - size.Height) / 2),
                                       format);
                    }
                    pdfOut.Save(pdfFilename);
                }



                // Save and show the document
                //  pdfRenderer.PdfDocument.Save("TestDocument.pdf");
                Process.Start("explorer.exe", pdfFilename);


                HyperLinkPDF.Visible     = true;
                HyperLinkPDF.NavigateUrl = PortalSettings.HomeDirectory + _PdfFilesFolder.ToString() + "Cert" + itemId.ToString() + ".pdf";
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
Пример #17
0
    public Document CreateDocument()
    {
        Document document = new Document();

        document.Info.Title = "Existing Client Task List";
        document.Info.Author = "Sol-TBCRM";
        document.Info.Subject = "";

        using (SqlConnection oConn = new SqlConnection(Connect.sConnStr))
        {
            oConn.Open();

            // Read the list of new clients
            string strQuery;
            if ((string)Session["LoggedInUserID"] == "7")
                strQuery = "select MarketerUserID, EventAssignedUserID, ClientID, MarketerName, MarketerSurname, users.sName as AssignedName, users.sSurname as AssignedSurname, dtCreated, sMessage, sClientName, sClientNumber, sContactPerson, sTelephone from (select MarketerUserID, EventAssignedUserID, ClientID, users.sName as MarketerName, users.sSurname as MarketerSurname, dtCreated, sMessage, sClientName, sClientNumber, sContactPerson, sTelephone from (select MarketerUserID, EventAssignedUserID, existing_clients.PKiClientID as ClientID, dtCreated, sMessage, existing_clients.sName as sClientName, existing_clients.sClientNumber, existing_clients.sContactPerson, existing_clients.sTelephone from (select marketer_assignment.FKiUserID as MarketerUserID, events.FKiExistingClientID as EventClientID, events.FKiUserAssignedID as EventAssignedUserID, events.dtCreated, events.sMessage  from events inner join marketer_assignment on events.FKiExistingClientID = marketer_assignment.FKiClientID  WHERE events.sStatus = 'Active') MarketerEventJoin inner join existing_clients on MarketerEventJoin.EventClientID = existing_clients.PKiClientID WHERE existing_clients.bExcluded = 0) MarketerEventsClientsJoin inner join users on users.PKiUserId = MarketerUserID) FinalJoin inner join users on PKiUserID = EventAssignedUserID ORDER BY MarketerUserID, ClientID, dtCreated";
            else
                strQuery = "select MarketerUserID, EventAssignedUserID, ClientID, MarketerName, MarketerSurname, users.sName as AssignedName, users.sSurname as AssignedSurname, dtCreated, sMessage, sClientName, sClientNumber, sContactPerson, sTelephone from (select MarketerUserID, EventAssignedUserID, ClientID, users.sName as MarketerName, users.sSurname as MarketerSurname, dtCreated, sMessage, sClientName, sClientNumber, sContactPerson, sTelephone from (select MarketerUserID, EventAssignedUserID, existing_clients.PKiClientID as ClientID, dtCreated, sMessage, existing_clients.sName as sClientName, existing_clients.sClientNumber, existing_clients.sContactPerson, existing_clients.sTelephone from (select marketer_assignment.FKiUserID as MarketerUserID, events.FKiExistingClientID as EventClientID, events.FKiUserAssignedID as EventAssignedUserID, events.dtCreated, events.sMessage  from events inner join marketer_assignment on events.FKiExistingClientID = marketer_assignment.FKiClientID  WHERE events.sStatus = 'Active' AND marketer_assignment.FKiUserID = '" + (string)Session["LoggedInUserID"] + "') MarketerEventJoin inner join existing_clients on MarketerEventJoin.EventClientID = existing_clients.PKiClientID WHERE existing_clients.bExcluded = 0) MarketerEventsClientsJoin inner join users on users.PKiUserId = MarketerUserID) FinalJoin inner join users on PKiUserID = EventAssignedUserID ORDER BY MarketerUserID, ClientID, dtCreated";

            SqlDataReader reader = Connect.getDataCommand(strQuery, oConn).ExecuteReader();

            int lastuserid = -1;
            int lastclientid = -1;
            int numclients = 0;
            int numevents = 0;
            DateTime lastdate = DateTime.MinValue;
            if (!reader.HasRows)
            {
                Section section = document.AddSection();
                section.PageSetup.PageFormat = PageFormat.A4;
                section.AddParagraph("No items for user '" + (string)Session["LoggedInUserID"] + "'");
            }
            while (reader.Read())
            {
                // Start new section
                if ((int)reader["MarketerUserID"] != lastuserid)
                {
                   /* if (lastuserid != -1)
                        document.LastSection.AddPageBreak();*/
                    numclients = 0;
                    lastuserid = (int)reader["MarketerUserID"];
                    // Create a paragraph with centered page number. See definition of style "Footer".
                    Paragraph paragraph = new Paragraph();
                    paragraph.AddTab();
                    paragraph.AddPageField();
                    // Add a section to the document
                    Section section = document.AddSection();
                    section.PageSetup.PageFormat = PageFormat.A4;
                    section.PageSetup.StartingNumber = 1;

                    // Add paragraph to footer for odd pages.
                    section.Footers.Primary.Add(paragraph);

                    HeaderFooter header = section.Headers.Primary;
                    header.AddParagraph(DateTime.Now.ToString() + "\t\t" + (string)reader["MarketerName"] + " " + (string)reader["MarketerSurname"] + " Task List");

                    paragraph = section.AddParagraph();
                    paragraph.Format.Font.Name = "Arial";
                    paragraph.Format.Font.Size = Unit.FromPoint(18);
                    paragraph.Format.SpaceBefore = Unit.FromCentimeter(2);
                    paragraph.Format.SpaceAfter = Unit.FromCentimeter(2);
                    paragraph.Format.Alignment = ParagraphAlignment.Center;
                    paragraph.AddText((string)reader["MarketerName"] + " " + (string)reader["MarketerSurname"] + " Task List\n");
                    Table table = section.AddTable();
                    table.Format.Alignment = ParagraphAlignment.Left;
                    Column column = table.AddColumn(Unit.FromCentimeter(1));
                    table.AddColumn(Unit.FromCentimeter(2));
                    table.AddColumn(Unit.FromCentimeter(5));
                    table.AddColumn(Unit.FromCentimeter(5));
                    table.AddColumn(Unit.FromCentimeter(3));
                    Row row = table.AddRow();
                    row.Format.Font.Italic = true;
                    row.Format.SpaceAfter = Unit.FromMillimeter(5);
                    Cell cell = row.Cells[0];
                    cell.AddParagraph("#");
                    cell = row.Cells[1];
                    cell.AddParagraph("Code");
                    cell = row.Cells[2];
                    cell.AddParagraph("Client");
                    cell = row.Cells[3];
                    cell.AddParagraph("Contact");
                    cell = row.Cells[4];
                    cell.AddParagraph("Telephone");

                    numclients++;
                    numevents = 1;
                    lastclientid = (int)reader["ClientID"];
                    AddClient(document, reader, numclients);
                    lastdate = (DateTime)reader["dtCreated"];
                    AddDate(document, reader);
                    AddEvent(document, reader, numevents);
                }
                else // Continue in section
                {
                    // New client
                    if ((int)reader["ClientID"] != lastclientid)
                    {
                        lastclientid = (int)reader["ClientID"];
                        lastdate = (DateTime)reader["dtCreated"];
                        numclients++;
                        numevents = 1;
                        AddClient(document, reader, numclients);
                        AddDate(document, reader);
                        AddEvent(document, reader, numevents);
                    }
                    else // Continue with same client
                    {
                        DateTime newdate = (DateTime)reader["dtCreated"];
                        if (newdate.Year != lastdate.Year && newdate.Month != lastdate.Month && newdate.Day != lastdate.Day) // New date
                        {
                            AddDate(document, reader);
                            numevents = 1;
                            AddEvent(document, reader, numevents);
                        }
                        else // Continue with same date
                        {
                            numevents++;
                            AddEvent(document, reader, numevents);
                        }
                    }
                }
            }

            reader.Close();
            oConn.Close();
        }
        return document;
    }
Пример #18
0
        /// <summary>
        /// Defines page setup, headers, and footers
        /// </summary>
        /// <param name="document">MigraDoc document created via Documents.CreateDocument()</param>
        public static void DefineContentSection(Document document)
        {
            Section section = document.AddSection();
            section.PageSetup.TopMargin = "5cm";
            section.PageSetup.StartingNumber = 1;
            section.PageSetup.Orientation = Orientation.Landscape;

            // Create header
            HeaderFooter header = section.Headers.Primary;

            // Add logo
            Image image = header.AddImage(Report.logoPath);
            image.Width = "8cm";
            image.WrapFormat.Style = WrapStyle.Through;

            // Add company name
            Paragraph h1 = new Paragraph();
            h1.AddText(Report.companyName);
            h1.Format.Font.Color = Colors.SlateGray;
            h1.Format.Font.Size = 24;
            h1.Format.Font.Bold = true;
            header.Add(h1);

            // Add report name
            Paragraph h2 = new Paragraph();
            h2.Format.Font.Color = Colors.SlateGray;
            h2.AddText("Welfare Check Breach Report");
            h2.Format.Font.Size = 18;
            h2.Format.Borders.Width = 0;
            h2.Format.Borders.Bottom.Width = 1;
            h2.Format.Borders.Color = Colors.LightSlateGray;
            h2.Format.Borders.Distance = 4;
            header.Add(h2);

            // Add current date
            Paragraph h3 = new Paragraph();
            h3.Format.Font.Size = 12;
            h3.Format.Font.Italic = true;
            h3.Format.Borders.Distance = 6;
            h3.AddDateField();
            header.Add(h3);

            // Create a paragraph with centered page number. See definition of style "Footer".
            Paragraph footer = new Paragraph();
            footer.Format.Borders.Width = 0;
            footer.Format.Borders.Top.Width = 1;
            footer.Format.Borders.Color = Colors.LightSlateGray;
            footer.Format.Borders.Distance = 10;
            footer.AddPageField();

            // Add paragraph to footer
            section.Footers.Primary.Add(footer);
        }
Пример #19
0
        private static MigraDoc.Rendering.PdfDocumentRenderer CreateHomeGroupAttendanceDocument(string groupName, List<AttendanceEventViewModel> attendees, Dictionary<int, string> comments)
        {
            // Create new MigraDoc document
            Document document = new Document();
            document.Info.Title = groupName;
            document.Info.Author = "oikonomos";
            document.Info.Subject = "Homegroup Attendance for " + groupName;
            Section sec = document.AddSection();
            sec.PageSetup.TopMargin = Unit.FromCentimeter(1);
            sec.PageSetup.LeftMargin = Unit.FromCentimeter(1);
            document.DefaultPageSetup.TopMargin = Unit.FromCentimeter(1);
            document.DefaultPageSetup.LeftMargin = Unit.FromCentimeter(1);

            Paragraph p = sec.Headers.Primary.AddParagraph();
            p.AddText("Homegroup Attendance for " + groupName);
            p.Format.Font.Size = 10.0;
            p.Format.Font.Bold = true;
            p.Format.Alignment = ParagraphAlignment.Center;

            Paragraph pf = new Paragraph();
            pf.AddText("Date: " + DateTime.Now.ToString("dd MMM yyyy"));
            pf.Format.Font.Size = 6.0;
            sec.Footers.Primary.Add(pf);

            //Work out which distinct days there are in each month
            List<int> month1Events = new List<int>();
            List<int> month2Events = new List<int>();
            int month1 = DateTime.Now.AddMonths(-1).Month;
            int month2 = DateTime.Now.Month;
            GetAttendanceDays(attendees, month1Events, month2Events, month1, month2);

            if (month1Events.Count == 0)
            {
                month1Events.Add(1);
            }
            if (month2Events.Count == 0)
            {
                month2Events.Add(1);
            }

            MigraDoc.DocumentObjectModel.Tables.Table attendeesTable = new MigraDoc.DocumentObjectModel.Tables.Table();
            int totalColumns = AddAttendanceHeaders(month1, month2, month1Events, month2Events, attendeesTable, "Members");
            AddAttendanceData(attendees, document, month1Events, month2Events, month1, month2, attendeesTable, totalColumns, comments);
            sec.Add(attendeesTable);

            document.LastSection.PageSetup.TopMargin = Unit.FromMillimeter(20);

            MigraDoc.Rendering.PdfDocumentRenderer pdfRender = new MigraDoc.Rendering.PdfDocumentRenderer(false, PdfSharp.Pdf.PdfFontEmbedding.Always);
            pdfRender.Document = document; //document is where all of my info has been written to and is a MigraDoc type
            pdfRender.RenderDocument();

            return pdfRender;
        }
Пример #20
0
        private static MigraDoc.Rendering.PdfDocumentRenderer CreateHomeGroupListDocument(string groupName, List<PersonViewModel> personList)
        {
            // Create new MigraDoc document
            Document document = new Document();
            document.Info.Title = groupName;
            document.Info.Author = "oikonomos";
            document.Info.Subject = "Group List for " + groupName;
            Section sec = document.AddSection();
            sec.PageSetup.TopMargin = Unit.FromCentimeter(1);
            sec.PageSetup.LeftMargin = Unit.FromCentimeter(1);
            document.DefaultPageSetup.TopMargin = Unit.FromCentimeter(1);
            document.DefaultPageSetup.LeftMargin = Unit.FromCentimeter(1);

            Paragraph p = sec.Headers.Primary.AddParagraph();
            p.AddText("Group List for " + groupName);
            p.Format.Font.Size = 10.0;
            p.Format.Font.Bold = true;
            p.Format.Alignment = ParagraphAlignment.Center;

            Paragraph pf = new Paragraph();
            pf.AddText("Date: " + DateTime.Now.ToString("dd MMM yyyy"));
            pf.Format.Font.Size = 6.0;
            sec.Footers.Primary.Add(pf);

            MigraDoc.DocumentObjectModel.Tables.Table membersTable = new MigraDoc.DocumentObjectModel.Tables.Table();
            personList = personList.OrderBy(x => x.RoleName).ThenBy(x => x.Surname).ThenBy(x => x.PersonId).ToList();
            AddHeaders(membersTable, null);
            AddHomegroupData(document, personList, membersTable);

            MigraDoc.DocumentObjectModel.Tables.Table visitorsTable = new MigraDoc.DocumentObjectModel.Tables.Table();

            sec.Add(membersTable);

            document.LastSection.PageSetup.TopMargin = Unit.FromMillimeter(20);

            MigraDoc.Rendering.PdfDocumentRenderer pdfRender = new MigraDoc.Rendering.PdfDocumentRenderer(false, PdfSharp.Pdf.PdfFontEmbedding.Always);
            pdfRender.Document = document; //document is where all of my info has been written to and is a MigraDoc type
            pdfRender.RenderDocument();

            return pdfRender;
        }
Пример #21
0
        public string pdfRapportoAgentePlusOld(string autore, string emailAutore, string periodoRiferimento, Single acconto, Single recupero, Single daRiportare, Single monete, Single carta, string targa, List <cCostanti.tOperazione> info)
        {
            cCostanti costanti = new cCostanti();
            string    testo = "";
            string    fileName, pathFileName;
            string    pageFooterText = "";

            DateTime  currentTime     = DateTime.Now;
            Document  document        = new Document();
            Table     table           = new MigraDoc.DocumentObjectModel.Tables.Table();
            Paragraph infoPremilinari = new MigraDoc.DocumentObjectModel.Paragraph();
            Column    colonna;

            FormattedText ftextTarga = new FormattedText();

            fileName     = ("pdf_" + emailAutore).Replace(" ", "").Replace(".", "_").Replace("@", "_") + ".pdf";
            pathFileName = HttpContext.Current.Server.MapPath(costanti.pathRemoto + "/" + fileName);

            Style style = document.Styles["Normal"];

            style.Font.Name = "Arial Unicode MS";
            style.Font.Size = 12;
            style.Font.Bold = false;


            //table Style
            style           = document.Styles.AddStyle("tabella", "Normal");
            style.Font.Name = "Verdana";
            style.Font.Size = 12;
            style.Font.Bold = false;

            style           = document.Styles.AddStyle("rigaBold", "Normal");
            style.Font.Name = "Verdana";
            style.Font.Size = 12;
            style.Font.Bold = true;

            style           = document.Styles.AddStyle("riga24", "Normal");
            style.Font.Name = "Verdana";
            style.Font.Size = 24;
            style.Font.Bold = true;

            style           = document.Styles.AddStyle("testoBold", "Normal");
            style.Font.Name = "Verdana";
            style.Font.Size = 12;
            style.Font.Bold = true;

            style            = document.Styles.AddStyle("testoRosso", "Normal");
            style.Font.Name  = "Verdana";
            style.Font.Size  = 14;
            style.Font.Bold  = true;
            style.Font.Color = Colors.OrangeRed;

            style            = document.Styles.AddStyle("testoBlu", "Normal");
            style.Font.Name  = "Verdana";
            style.Font.Size  = 14;
            style.Font.Bold  = true;
            style.Font.Color = Colors.DarkBlue;

            style            = document.Styles.AddStyle("testoNero", "Normal");
            style.Font.Name  = "Verdana";
            style.Font.Size  = 14;
            style.Font.Bold  = true;
            style.Font.Color = Colors.Black;

            style            = document.Styles.AddStyle("Titolo", "Normal");
            style.Font.Name  = "Verdana";
            style.Font.Size  = 16;
            style.Font.Bold  = true;
            style.Font.Color = Colors.Orange;

            Section page = document.AddSection();

            //header
            Paragraph header = page.Headers.Primary.AddParagraph();

            header.AddText("Money BOX");
            header.Format.Alignment = ParagraphAlignment.Left;
            header.Style            = "Titolo";
            testo  = string.Format("{0}, {1}, targa: ", autore, emailAutore);
            header = page.Headers.Primary.AddParagraph();
            header.AddText(testo);
            ftextTarga.AddText(targa.ToUpper());
            ftextTarga.Color = Colors.Red;
            header.Add(ftextTarga);
            header.AddText("\n");
            header.Format.Alignment = ParagraphAlignment.Left;

            //footer
            pageFooterText = string.Format(" report del {0}, {1} ", currentTime.ToShortDateString(), currentTime.ToShortTimeString()) + "\n";
            Paragraph footer = page.Footers.Primary.AddParagraph();

            footer.AddText(pageFooterText);
            footer.Format.Alignment = ParagraphAlignment.Center;

            table.Style               = "tabella";
            table.Borders.Color       = Colors.Black;
            table.Borders.Width       = 0.25;
            table.Borders.Left.Width  = 0.5;
            table.Borders.Right.Width = 0.5;
            table.Rows.LeftIndent     = 0;

            colonna = table.AddColumn("6cm");
            colonna.Format.Alignment = ParagraphAlignment.Left;
            colonna = table.AddColumn("3.5cm");
            colonna.Format.Alignment = ParagraphAlignment.Left;
            colonna = table.AddColumn("3.5cm");
            colonna.Format.Alignment = ParagraphAlignment.Left;
            colonna = table.AddColumn("3.5cm");
            colonna.Format.Alignment = ParagraphAlignment.Left;

            infoPremilinari.AddText("\nPeriodo di riferimento: ");
            infoPremilinari.AddFormattedText(periodoRiferimento, TextFormat.Bold);
            infoPremilinari.AddText("\n\n");


            page.Add(infoPremilinari);
            Row riga = table.AddRow();

            riga.Style = "rigaBold";
            riga.Cells[0].AddParagraph("Locale");
            riga.Cells[1].AddParagraph("acconto");
            riga.Cells[2].AddParagraph("recupero \n da riportare");
            riga.Cells[3].AddParagraph("da Riportare");
            riga.Cells[0].Format.Alignment = ParagraphAlignment.Left;
            riga.Cells[1].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[2].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[3].Format.Alignment = ParagraphAlignment.Right;

            foreach (var value in info)
            {
                riga = table.AddRow();
                riga.Cells[0].AddParagraph(value.nomeLocale + "\n" + value.data);
                if (value.acconto == 0)
                {
                    riga.Cells[1].AddParagraph("");
                }
                else
                {
                    riga.Cells[1].AddParagraph(String.Format("{0:0,0.00}", value.acconto));
                }

                if (value.recupero == 0)
                {
                    riga.Cells[2].AddParagraph("");
                }
                else
                {
                    riga.Cells[2].AddParagraph(String.Format("{0:0,0.00}", value.recupero));
                }
                if (value.daRiportare == 0)
                {
                    riga.Cells[3].AddParagraph("");
                }
                else
                {
                    riga.Cells[3].AddParagraph(String.Format("{0:0,0.00}", value.daRiportare));
                }
                riga.Cells[0].Format.Alignment = ParagraphAlignment.Left;
                riga.Cells[1].Format.Alignment = ParagraphAlignment.Right;
                riga.Cells[2].Format.Alignment = ParagraphAlignment.Right;
                riga.Cells[3].Format.Alignment = ParagraphAlignment.Right;
            }

            riga       = table.AddRow();
            riga.Style = "rigaBold";
            riga.Cells[0].AddParagraph("\nFlusso acconti\n\n");
            riga.Cells[1].AddParagraph("\n" + String.Format("{0:0,0.00}", acconto));
            riga.Cells[2].AddParagraph("");
            riga.Cells[2].MergeRight       = 1;
            riga.Cells[0].Format.Alignment = ParagraphAlignment.Left;
            riga.Cells[1].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[2].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[0].Style            = "testoNero";
            riga.Cells[1].Style            = "testoBlu";

            riga       = table.AddRow();
            riga.Style = "rigaBold";
            riga.Cells[0].AddParagraph("Flusso di cassa");
            riga.Cells[0].MergeRight = 1;
            riga.Cells[2].AddParagraph(String.Format("{0:0,0.00}", recupero));
            riga.Cells[3].AddParagraph(String.Format("{0:0,0.00}", daRiportare));
            riga.Cells[0].Format.Alignment = ParagraphAlignment.Left;
            riga.Cells[2].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[3].Format.Alignment = ParagraphAlignment.Right;


            riga       = table.AddRow();
            riga.Style = "rigaBold";
            riga.Cells[0].AddParagraph("Monete");
            riga.Cells[0].MergeRight = 1;
            riga.Cells[2].AddParagraph(String.Format("{0:0,0.00}", monete));
            riga.Cells[0].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[2].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[3].MergeDown        = 3;

            riga       = table.AddRow();
            riga.Style = "rigaBold";
            riga.Cells[0].AddParagraph("Carta");
            riga.Cells[0].MergeRight = 1;
            riga.Cells[2].AddParagraph(String.Format("{0:0,0.00}", carta));
            riga.Cells[0].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[2].Format.Alignment = ParagraphAlignment.Right;

            riga       = table.AddRow();
            riga.Style = "rigaBold";
            riga.Cells[0].AddParagraph("Tot. cassa");
            riga.Cells[0].MergeRight = 1;
            riga.Cells[2].AddParagraph(String.Format("{0:0,0.00}", monete + carta + recupero));
            riga.Cells[0].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[2].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[0].Style            = "testoNero";
            riga.Cells[2].Style            = "testoNero";

            riga       = table.AddRow();
            riga.Style = "rigaBold";
            riga.Cells[0].AddParagraph("\nFlusso di cassa\n\n");
            riga.Cells[0].MergeRight = 1;
            riga.Cells[2].AddParagraph("\n" + String.Format("{0:0,0.00}", monete + carta + recupero - daRiportare));
            riga.Cells[3].AddParagraph("\n");
            riga.Cells[0].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[2].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[3].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[0].Style            = "testoNero";
            riga.Cells[2].Style            = "testoRosso";

            page.Add(table);

            PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true);

            pdfRenderer.Document = document;
            pdfRenderer.RenderDocument();
            pdfRenderer.PdfDocument.Save(pathFileName);

            //Process.Start(fileName);
            return(fileName);
        }
Пример #22
0
        /// <summary>
        /// Creates the static parts of the invoice.
        /// </summary>
        void CreatePage()
        {
            // Each MigraDoc document needs at least one section.
            Section section = this.document.AddSection();

            // Put a logo in the header
            Image image = section.AddImage(path);

            image.Top              = ShapePosition.Top;
            image.Left             = ShapePosition.Left;
            image.WrapFormat.Style = WrapStyle.Through;

            // Create footer
            Paragraph paragraph = section.Footers.Primary.AddParagraph();

            paragraph.AddText("Health And Social Services.");
            paragraph.Format.Font.Size = 9;
            paragraph.Format.Alignment = ParagraphAlignment.Center;

            // Create the text frame for the address
            this.addressFrame                    = section.AddTextFrame();
            this.addressFrame.Height             = "3.0cm";
            this.addressFrame.Width              = "7.0cm";
            this.addressFrame.Left               = ShapePosition.Left;
            this.addressFrame.RelativeHorizontal = RelativeHorizontal.Margin;
            this.addressFrame.Top                = "5.0cm";
            this.addressFrame.RelativeVertical   = RelativeVertical.Page;

            // Put sender in address frame
            paragraph = this.addressFrame.AddParagraph("Karachi,Pakistan");
            paragraph.Format.Font.Name  = "Times New Roman";
            paragraph.Format.Font.Size  = 7;
            paragraph.Format.SpaceAfter = 3;

            // Add the print date field
            paragraph = section.AddParagraph();
            paragraph.Format.SpaceBefore = "6cm";
            paragraph.Style = "Reference";
            paragraph.AddFormattedText("Patients Detail", TextFormat.Bold);
            paragraph.AddTab();
            paragraph.AddText("Date, ");
            paragraph.AddDateField("dd.MM.yyyy");

            // Create the item table
            this.table                     = section.AddTable();
            this.table.Style               = "Table";
            this.table.Borders.Color       = TableBorder;
            this.table.Borders.Width       = 0.25;
            this.table.Borders.Left.Width  = 0.5;
            this.table.Borders.Right.Width = 0.5;
            this.table.Rows.LeftIndent     = 0;



            // Before you can add a row, you must define the columns
            Column column;

            foreach (DataColumn col in dt.Columns)
            {
                column = this.table.AddColumn(Unit.FromCentimeter(3));
                column.Format.Alignment = ParagraphAlignment.Center;
            }

            // Create the header of the table
            Row row = table.AddRow();

            row.HeadingFormat    = true;
            row.Format.Alignment = ParagraphAlignment.Center;
            row.Format.Font.Bold = true;
            row.Shading.Color    = TableBlue;


            for (int i = 0; i < dt.Columns.Count; i++)
            {
                row.Cells[i].AddParagraph(dt.Columns[i].ColumnName);
                row.Cells[i].Format.Font.Bold  = false;
                row.Cells[i].Format.Alignment  = ParagraphAlignment.Left;
                row.Cells[i].VerticalAlignment = VerticalAlignment.Bottom;
            }

            this.table.SetEdge(0, 0, dt.Columns.Count, 1, Edge.Box, BorderStyle.Single, 0.75, Color.Empty);
        }