Пример #1
0
        protected override HtmlItem renderingHtmlLi(HtmlItem it, ref Paragraph par, HtmlItem parent)
        {
            HtmlLi  l = it as HtmlLi;
            if (l != null)
            {
                foreach (HtmlItem i in it.ListItem)
                {
                 FormattedText ff = new FormattedText();
                 HtmlItem itemrendered =   renderingit(i, ref par, l, null);
                 HtmlText textitem = itemrendered as HtmlText;
                 //RenderStyle.CreateRenderStyle(it, ref ff).Render();

                 if (textitem != null)
                 {
                     ff.Add(new Text(textitem.Text));
                     par.Add(ff);
                     it.SizeRenderItem.Width = calculateWithText(textitem.Text.Length, ff.Size);

                     if (it.SizeRenderItem.Width > 210)
                         it.SizeRenderItem.Width = 210;
                     it.SizeRenderItem.Height = calculateHeightText(textitem.Text.Length, ff.Size);

                 }
                }
            }

            return l;
        }
Пример #2
0
        protected override HtmlItem renderingHtmlDiv(HtmlItem it, ref Paragraph par, HtmlItem parent)
        {
            HtmlDiv div = it as HtmlDiv;
            if (div != null)
            {
                foreach (HtmlItem t in it.ListItem)
                {
                    FormattedText ff = new FormattedText();
                    RenderStyle.CreateRenderStyle(it, ref ff).Render(); //Render styles element

                    HtmlItem itemrendered = renderingit(t, ref par, it, null);
                    HtmlText textitem = itemrendered as HtmlText;
                    if (textitem != null)
                    {
                        ff.Add(new Text(textitem.Text));
                        it.SizeRenderItem.Width = calculateWithText(textitem.Text.Length, ff.Size);
                        if (it.SizeRenderItem.Width > 210)
                            it.SizeRenderItem.Width = 210;
                        it.SizeRenderItem.Height = calculateHeightText(textitem.Text.Length, ff.Size);
                    }

                    par.Add(ff);

                }
                par.AddLineBreak();
            }
            return div;
        }
Пример #3
0
        protected override HtmlItem renderingHtmlContent(HtmlItem it, ref Paragraph par, HtmlItem parent)
        {
            HtmlContent content = it as HtmlContent;
            if (content != null)
            {
                if (parent is HtmlContent)
                    par.AddLineBreak();

                foreach (HtmlItem t in it.ListItem)
                {
                    FormattedText ff = new FormattedText();
                    if (content.Bold.hasValue())
                        ff.Bold = content.Bold.Value;
                    if (content.Size.hasValue())
                        ff.Size = content.Size.Value;

                    RenderStyle.CreateRenderStyle(it, ref ff).Render();

                    HtmlItem itemrendered = renderingit(t, ref par, it, null);
                    HtmlText textitem = itemrendered as HtmlText;
                    if (textitem != null)
                    {
                        ff.Add(new Text(textitem.Text));
                        par.Add(ff);
                        it.SizeRenderItem.Width = calculateWithText(textitem.Text.Length, ff.Size);

                        //ff.Section.PageSetup.PageWidth=59 =>>210 mm A4
                        if (it.SizeRenderItem.Width > 210)
                            it.SizeRenderItem.Width = 210;
                        it.SizeRenderItem.Height = calculateHeightText(textitem.Text.Length, ff.Size);

                    }
                }
                par.AddLineBreak();
            }
            return content;
        }
Пример #4
0
 /// <summary>
 /// Render a image into a table cell
 /// </summary>
 public void RenderInto(Cell cell)
 {
     MigraDoc.DocumentObjectModel.Paragraph paragraph = cell.AddParagraph();
     paragraph.Add(this.CreateImage());
     paragraph.Format.Alignment = GetAlignment();
 }
        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;
        }
Пример #6
0
        protected override HtmlItem renderingHtmlSpan(HtmlItem it, ref Paragraph par, HtmlItem parent)
        {
            HtmlSpan span = it as HtmlSpan;
            if (span != null)
            {
                foreach (HtmlItem t in it.ListItem)
                {
                    FormattedText ff = new FormattedText();
                    if (span.Size.hasValue())
                        ff.Size = span.Size.Value;
                    if (span.Bold.hasValue())
                        ff.Bold = span.Bold.Value;
                    if (span.Sub.hasValue())
                        ff.Subscript = span.Sub.Value;
                    if (span.Super.hasValue())
                        ff.Superscript = span.Super.Value;

                    RenderStyle.CreateRenderStyle(it, ref ff).Render(); // render styles element

                    HtmlItem itemrendered = renderingit(t, ref par, it, null);
                    HtmlText textitem = itemrendered as HtmlText;
                    if (textitem != null)
                    {
                        ff.Add(new Text(textitem.Text));
                        it.SizeRenderItem.Width = calculateWithText(textitem.Text.Length, ff.Size);
                        if (it.SizeRenderItem.Width > 210)
                            it.SizeRenderItem.Width = 210;
                        it.SizeRenderItem.Height = calculateHeightText(textitem.Text.Length, ff.Size);
                    }

                    par.Add(ff);

                }
            }
            return span;
        }