Example #1
0
        public static void CreatePdf(string person1, string person2, DataHandler datahandler, Dictionary <string, string[]> groups)
        {
            Document document = new Document();

            document.UseCmykColor = true;

            MigraDoc.DocumentObjectModel.Section section = document.AddSection();
            section.PageSetup.Orientation = MigraDoc.DocumentObjectModel.Orientation.Landscape;
            MigraDoc.DocumentObjectModel.Paragraph paragraph = section.AddParagraph();
            paragraph.Format.Font.Color = MigraDoc.DocumentObjectModel.Color.FromCmyk(100, 20, 30, 50);

            if (person1 == "<Ingen sælger valgt>")
            {
                person1 = null;
            }

            if (person2 == "<Ingen sælger valgt>")
            {
                person2 = null;
            }

            if (person1 != null)
            {
                paragraph.AddFormattedText(person1, TextFormat.Bold);
                paragraph.AddLineBreak();
                paragraph.AddLineBreak();

                DefineCharts(document, person1, groups, datahandler);
            }

            if (person2 != null)
            {
                MigraDoc.DocumentObjectModel.Section newSection = document.AddSection();
                newSection.PageSetup.Orientation = MigraDoc.DocumentObjectModel.Orientation.Landscape;
                MigraDoc.DocumentObjectModel.Paragraph newParagraph = newSection.AddParagraph();

                newParagraph.AddFormattedText(person2, TextFormat.Bold);
                newParagraph.AddLineBreak();
                newParagraph.AddLineBreak();

                DefineCharts(document, person2, groups, datahandler);
            }

            const bool             unicode     = false;
            const PdfFontEmbedding embedding   = PdfFontEmbedding.Always;
            PdfDocumentRenderer    pdfRenderer = new PdfDocumentRenderer(unicode, embedding);

            pdfRenderer.Document = document;
            pdfRenderer.RenderDocument();

            string time   = DateTime.Today.ToShortDateString();
            string myfile = time + ".pdf";

            pdfRenderer.PdfDocument.Save(myfile);
            Process.Start(myfile);
        }
Example #2
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.");
 }
Example #3
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;
        }
Example #4
0
        /// <summary>
        /// Writes the figure text.
        /// </summary>
        /// <param name="f">The f.</param>
        /// <param name="pa">The paragraph.</param>
        protected void WriteEndFigure(Figure f, Paragraph pa)
        {
            if (f.FigureText == null)
            {
                return;
            }

            pa.AddLineBreak();
            pa.AddFormattedText(f.GetFullCaption(this.style), "FigureText");
        }
Example #5
0
        /// <summary>
        /// Creates the dynamic parts of the invoice.
        /// </summary>
        void FillContent()
        {
            // Fill address in address text frame
            Paragraph paragraph = this.addressFrame.AddParagraph();

            paragraph.AddText("Dr. Anwar Ali");
            paragraph.AddLineBreak();
            paragraph.AddText("Health And Social Services ");
            paragraph.AddLineBreak();
            paragraph.AddText("Karachi");

            Row row1;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                row1            = this.table.AddRow();
                row1.TopPadding = 1.5;

                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    row1.Cells[j].Shading.Color     = TableGray;
                    row1.Cells[j].VerticalAlignment = VerticalAlignment.Center;

                    row1.Cells[j].Format.Alignment       = ParagraphAlignment.Left;
                    row1.Cells[j].Format.FirstLineIndent = 1;

                    row1.Cells[j].AddParagraph(dt.Rows[i][j].ToString());


                    this.table.SetEdge(0, this.table.Rows.Count - 2, dt.Columns.Count, 1, Edge.Box, BorderStyle.Single, 0.75);
                }
            }

            // Add the notes paragraph
            paragraph = this.document.LastSection.AddParagraph();
            paragraph.Format.SpaceBefore      = "1cm";
            paragraph.Format.Borders.Width    = 0.75;
            paragraph.Format.Borders.Distance = 3;
            paragraph.Format.Borders.Color    = TableBorder;
            paragraph.Format.Shading.Color    = TableGray;

            paragraph.AddText("Note: For any complain please contact us in 24 hours from the issuance of bill");
        }
Example #6
0
        private void FillContent()
        {
            //XPathNavigator item = SelectItem("/invoice/to");
            MigraDoc.DocumentObjectModel.Paragraph paragraph = addressFrame.AddParagraph();
            paragraph.AddText("Dane Zamawiajacego :");
            paragraph.AddLineBreak();
            paragraph.AddText($"Imię i nazwisko: {order.UserData.Name} {order.UserData.Surname}");
            paragraph.AddLineBreak();
            paragraph.AddText($"Adres: ul. {order.UserData.Adres.Street} {order.UserData.Adres.HomeNumber}, {order.UserData.Adres.PostCode} {order.UserData.Adres.City}");

            MigraDoc.DocumentObjectModel.Paragraph priceParagraph = PriceFrame.AddParagraph();
            priceParagraph.AddText($"Cena całkowita: \n {order.OrderAmount} zł \n ");
            //paragraph.AddLineBreak();
            priceParagraph.AddText($"Rodzaj przesyłki: \n {order.OrderOption}  \n");
            //paragraph.AddLineBreak();
            priceParagraph.AddText($"Cena z przesyłką: \n {order.Amount} zł\n ");
            //paragraph.AddLineBreak();


            foreach (var orderItem in order.Ordered)
            {
                Row row = table.AddRow();
                row.TopPadding = 1.5;

                row.Cells[0].Shading.Color     = TableGray;
                row.Cells[0].VerticalAlignment = MigraDoc.DocumentObjectModel.Tables.VerticalAlignment.Center;
                row.Cells[0].Format.Alignment  = ParagraphAlignment.Left;
                row.Cells[1].Format.Alignment  = ParagraphAlignment.Left;
                row.Cells[2].Format.Alignment  = ParagraphAlignment.Left;
                row.Cells[3].Format.Alignment  = ParagraphAlignment.Left;
                row.Cells[1].Shading.Color     = TableGray;
                row.Cells[2].Shading.Color     = TableGray;
                row.Cells[3].Shading.Color     = TableGray;

                row.Cells[0].AddParagraph(orderItem.Product.Name);
                row.Cells[1].AddParagraph(orderItem.Count.ToString());
                row.Cells[2].AddParagraph($"{orderItem.Product.Price} zł");
                row.Cells[3].AddParagraph($"{orderItem.Amount} zł");

                this.table.SetEdge(0, this.table.Rows.Count - 1, 4, 1, Edge.Box, BorderStyle.Single, 0.75);
            }
        }
        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;
        }
        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;
        }
Example #9
0
        /// <summary>
        /// Writes the figure text.
        /// </summary>
        /// <param name="f">The f.</param>
        /// <param name="pa">The paragraph.</param>
        protected void WriteEndFigure(Figure f, Paragraph pa)
        {
            if (f.FigureText == null)
            {
                return;
            }

            pa.AddLineBreak();
            pa.AddFormattedText(f.GetFullCaption(this.style), "FigureText");
        }
Example #10
0
 /// <summary>
 /// The write end figure.
 /// </summary>
 /// <param name="f">
 /// The f.
 /// </param>
 /// <param name="pa">
 /// The pa.
 /// </param>
 public void WriteEndFigure(Figure f, Paragraph pa)
 {
     pa.AddLineBreak();
     pa.AddFormattedText(f.GetFullCaption(this.style), "FigureText");
 }
 /// <summary>
 /// The write end figure.
 /// </summary>
 /// <param name="f">
 /// The f.
 /// </param>
 /// <param name="pa">
 /// The pa.
 /// </param>
 public void WriteEndFigure(Figure f, Paragraph pa)
 {
     pa.AddLineBreak();
     pa.AddFormattedText(f.GetFullCaption(this.style), "FigureText");
 }
Example #12
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);
            }
        }