Beispiel #1
0
        public static COLOR.Color ConvertToColor(string colorStr)
        {
            COLOR.Color result = COLOR.Color.Black;
            var         tokens = colorStr.Split(new char[] { ',' });
            int         r, g, b;

            if (tokens.Length > 2 && Int32.TryParse(tokens[0], out r) && Int32.TryParse(tokens[1], out g) &&
                Int32.TryParse(tokens[2], out b))
            {
                return(COLOR.Color.FromArgb(r, g, b));
            }
            return(COLOR.Color.Empty);
        }
Beispiel #2
0
        private static PdfTemplate AddHeader(PdfDocument doc, string title, string description)
        {
            SizeF rect = new SizeF(doc.Pages[0].GetClientSize().Width, 50);

            //Create page template
            PdfTemplate header       = new PdfTemplate(rect);
            PdfFont     font         = new PdfStandardFont(PdfFontFamily.Helvetica, 24);
            float       doubleHeight = font.Height * 2;
            Color       activeColor  = Color.FromArgb(44, 71, 120);
            SizeF       imageSize    = new SizeF(110f, 35f);
            //Locating the logo on the right corner of the drawing surface
            PointF imageLocation = new PointF(doc.Pages[0].GetClientSize().Width - imageSize.Width - 20, 5);


            PdfSolidBrush brush = new PdfSolidBrush(activeColor);

            PdfPen pen = new PdfPen(Color.DarkBlue, 3f);

            font = new PdfStandardFont(PdfFontFamily.Helvetica, 16, PdfFontStyle.Bold);

            //Set formatting for the text
            PdfStringFormat format = new PdfStringFormat();

            format.Alignment     = PdfTextAlignment.Center;
            format.LineAlignment = PdfVerticalAlignment.Middle;

            //Draw title
            header.Graphics.DrawString(title, font, brush, new RectangleF(0, 0, header.Width, header.Height), format);
            brush = new PdfSolidBrush(Color.Gray);
            font  = new PdfStandardFont(PdfFontFamily.Helvetica, 6, PdfFontStyle.Bold);

            format               = new PdfStringFormat();
            format.Alignment     = PdfTextAlignment.Left;
            format.LineAlignment = PdfVerticalAlignment.Bottom;

            //Draw description
            header.Graphics.DrawString(description, font, brush, new RectangleF(0, 0, header.Width, header.Height - 8), format);

            //Draw some lines in the header
            pen = new PdfPen(Color.DarkBlue, 0.7f);
            header.Graphics.DrawLine(pen, 0, 0, header.Width, 0);
            pen = new PdfPen(Color.DarkBlue, 2f);
            header.Graphics.DrawLine(pen, 0, 03, header.Width + 3, 03);
            pen = new PdfPen(Color.DarkBlue, 2f);
            header.Graphics.DrawLine(pen, 0, header.Height - 3, header.Width, header.Height - 3);
            header.Graphics.DrawLine(pen, 0, header.Height, header.Width, header.Height);

            return(header);
        }
        private void AddHeader(PdfPage page, PdfDocument doc, string title)
        {
            RectangleF             rect   = new RectangleF(0, 0, doc.Pages[0].GetClientSize().Width, 50);
            PdfPageTemplateElement header = new PdfPageTemplateElement(rect);
            PdfFont font         = new PdfStandardFont(PdfFontFamily.Helvetica, 24);
            float   doubleHeight = font.Height * 2;

            Syncfusion.Drawing.Color activeColor = Syncfusion.Drawing.Color.FromArgb(44, 71, 120);


            //Draw the image in the Header.

            PdfSolidBrush brush = new PdfSolidBrush(activeColor);

            PdfPen pen = new PdfPen(Syncfusion.Drawing.Color.DarkBlue, 3f);

            font = new PdfStandardFont(PdfFontFamily.Helvetica, 6, PdfFontStyle.Bold);

            //Set formattings for the text
            PdfStringFormat format = new PdfStringFormat();

            format.Alignment     = PdfTextAlignment.Center;
            format.LineAlignment = PdfVerticalAlignment.Middle;

            //Draw title
            //Draw description
            header.Graphics.DrawString("                  mail: [email protected]", font, brush, new RectangleF(0, 0, header.Width, header.Height), format);
            header.Graphics.DrawString(" tel: 781 507 097", font, brush, new RectangleF(0, 0, header.Width, header.Height + 11), format);
            header.Graphics.DrawString("       785 886 491", font, brush, new RectangleF(0, 0, header.Width, header.Height + 21), format);
            brush = new PdfSolidBrush(Syncfusion.Drawing.Color.Gray);
            font  = new PdfStandardFont(PdfFontFamily.Helvetica, 6, PdfFontStyle.Bold);

            format               = new PdfStringFormat();
            format.Alignment     = PdfTextAlignment.Left;
            format.LineAlignment = PdfVerticalAlignment.Bottom;



            //Add header template at the top.
            doc.Template.Top = header;
        }
Beispiel #4
0
        public ActionResult InteractiveFeatures(string InsideBrowser)
        {
            #region Field Definitions
            document = new PdfDocument();
            document.PageSettings.Margins.All = 0;
            document.PageSettings.Size        = new SizeF(PdfPageSize.A4.Width, 600);
            interactivePage = document.Pages.Add();
            PdfGraphics g    = interactivePage.Graphics;
            RectangleF  rect = new RectangleF(0, 0, interactivePage.Graphics.ClientSize.Width, 100);

            PdfBrush whiteBrush  = new PdfSolidBrush(white);
            PdfPen   whitePen    = new PdfPen(white, 5);
            PdfBrush purpleBrush = new PdfSolidBrush(new PdfColor(255, 158, 0, 160));
            PdfFont  font        = new PdfStandardFont(PdfFontFamily.Helvetica, 25);
            Syncfusion.Drawing.Color maroonColor = Color.FromArgb(255, 188, 32, 60);
            Syncfusion.Drawing.Color orangeColor = Color.FromArgb(255, 255, 167, 73);
            #endregion

            #region Header
            g.DrawRectangle(purpleBrush, rect);
            g.DrawPie(whitePen, whiteBrush, new RectangleF(-20, 35, 700, 200), 20, -180);
            g.DrawRectangle(whiteBrush, new RectangleF(0, 99.5f, 700, 200));
            g.DrawString("Invoice", new PdfStandardFont(PdfFontFamily.TimesRoman, 24), PdfBrushes.White, new PointF(500, 10));

            string basePath = _hostingEnvironment.WebRootPath;
            string dataPath = string.Empty;
            dataPath = basePath + @"/PDF/";

            //Read the file
            FileStream file = new FileStream(dataPath + "AdventureCycle.jpg", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            g.DrawImage(PdfImage.FromStream(file), new RectangleF(100, 70, 390, 130));
            #endregion

            #region Body

            //Invoice Number
            Random invoiceNumber = new Random();
            g.DrawString("Invoice No: " + invoiceNumber.Next().ToString(), new PdfStandardFont(PdfFontFamily.Helvetica, 14), new PdfSolidBrush(maroonColor), new PointF(50, 210));
            g.DrawString("Date: ", new PdfStandardFont(PdfFontFamily.Helvetica, 14), new PdfSolidBrush(maroonColor), new PointF(350, 210));

            //Current Date
            PdfTextBoxField textBoxField = new PdfTextBoxField(interactivePage, "date");
            textBoxField.Font          = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
            textBoxField.Bounds        = new RectangleF(384, 204, 150, 30);
            textBoxField.ForeColor     = new PdfColor(maroonColor);
            textBoxField.ReadOnly      = true;
            document.Actions.AfterOpen = new PdfJavaScriptAction(@"var newdate = new Date(); 
            var thisfieldis = this.getField('date');  
            
            var theday = util.printd('dddd',newdate); 
            var thedate = util.printd('d',newdate); 
            var themonth = util.printd('mmmm',newdate);
            var theyear = util.printd('yyyy',newdate);  
            
            thisfieldis.strokeColor=color.transparent;
            thisfieldis.value = theday + ' ' + thedate + ', ' + themonth + ' ' + theyear ;");
            document.Form.Fields.Add(textBoxField);

            //invoice table
            PdfLightTable table = new PdfLightTable();
            table.Style.ShowHeader = true;
            g.DrawRectangle(new PdfSolidBrush(Syncfusion.Drawing.Color.FromArgb(238, 238, 238, 248)), new RectangleF(50, 240, 500, 140));

            //Header Style
            PdfCellStyle headerStyle = new PdfCellStyle();
            headerStyle.Font            = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Bold);
            headerStyle.TextBrush       = whiteBrush;
            headerStyle.StringFormat    = new PdfStringFormat(PdfTextAlignment.Center);
            headerStyle.BackgroundBrush = new PdfSolidBrush(orangeColor);
            headerStyle.BorderPen       = new PdfPen(whiteBrush, 0);
            table.Style.HeaderStyle     = headerStyle;

            //Cell Style
            PdfCellStyle bodyStyle = new PdfCellStyle();
            bodyStyle.Font           = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
            bodyStyle.StringFormat   = new PdfStringFormat(PdfTextAlignment.Left);
            bodyStyle.BorderPen      = new PdfPen(whiteBrush, 0);
            table.Style.DefaultStyle = bodyStyle;
            table.DataSource         = GetProductReport(_hostingEnvironment.WebRootPath);
            table.Columns[0].Width   = 90;
            table.Columns[1].Width   = 160;
            table.Columns[3].Width   = 100;
            table.Columns[4].Width   = 65;
            table.Style.CellPadding  = 3;
            table.BeginCellLayout   += table_BeginCellLayout;

            PdfLightTableLayoutResult result = table.Draw(interactivePage, new RectangleF(50, 240, 500, 140));

            g.DrawString("Grand Total:", new PdfStandardFont(PdfFontFamily.Helvetica, 12), new PdfSolidBrush(Syncfusion.Drawing.Color.FromArgb(255, 255, 167, 73)), new PointF(result.Bounds.Right - 150, result.Bounds.Bottom));
            CreateTextBox(interactivePage, "GrandTotal", "Grand Total", new RectangleF(result.Bounds.Width - 15, result.Bounds.Bottom - 2, 66, 18), true, "");


            //Send to Server
            PdfButtonField sendButton = new PdfButtonField(interactivePage, "OrderOnline");
            sendButton.Bounds      = new RectangleF(200, result.Bounds.Bottom + 70, 80, 25);
            sendButton.BorderColor = white;
            sendButton.BackColor   = maroonColor;
            sendButton.ForeColor   = white;
            sendButton.Text        = "Order Online";
            PdfSubmitAction submitAction = new PdfSubmitAction("http://stevex.net/dump.php");
            submitAction.DataFormat    = SubmitDataFormat.Html;
            sendButton.Actions.MouseUp = submitAction;
            document.Form.Fields.Add(sendButton);

            //Order by Mail
            PdfButtonField sendMail = new PdfButtonField(interactivePage, "sendMail");
            sendMail.Bounds      = new RectangleF(300, result.Bounds.Bottom + 70, 80, 25);
            sendMail.Text        = "Order By Mail";
            sendMail.BorderColor = white;
            sendMail.BackColor   = maroonColor;
            sendMail.ForeColor   = white;

            // Create a javascript action.
            PdfJavaScriptAction javaAction = new PdfJavaScriptAction("address = app.response(\"Enter an e-mail address.\",\"SEND E-MAIL\",\"\");"
                                                                     + "var aSubmitFields = [];"
                                                                     + "for( var i = 0 ; i < this.numFields; i++){"
                                                                     + "aSubmitFields[i] = this.getNthFieldName(i);"
                                                                     + "}"
                                                                     + "if (address){ cmdLine = \"mailto:\" + address;this.submitForm(cmdLine,true,false,aSubmitFields);}");

            sendMail.Actions.MouseUp = javaAction;
            document.Form.Fields.Add(sendMail);

            //Print
            PdfButtonField printButton = new PdfButtonField(interactivePage, "print");
            printButton.Bounds          = new RectangleF(400, result.Bounds.Bottom + 70, 80, 25);
            printButton.BorderColor     = white;
            printButton.BackColor       = maroonColor;
            printButton.ForeColor       = white;
            printButton.Text            = "Print";
            printButton.Actions.MouseUp = new PdfJavaScriptAction("this.print (true); ");
            document.Form.Fields.Add(printButton);
            file = new FileStream(dataPath + "Product Catalog.pdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            PdfAttachment attachment = new PdfAttachment("Product Catalog.pdf", file);
            attachment.ModificationDate = DateTime.Now;
            attachment.Description      = "Specification";
            document.Attachments.Add(attachment);

            //Open Specification
            PdfButtonField openSpecificationButton = new PdfButtonField(interactivePage, "openSpecification");
            openSpecificationButton.Bounds          = new RectangleF(50, result.Bounds.Bottom + 20, 87, 15);
            openSpecificationButton.TextAlignment   = PdfTextAlignment.Left;
            openSpecificationButton.Font            = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
            openSpecificationButton.BorderStyle     = PdfBorderStyle.Underline;
            openSpecificationButton.BorderColor     = orangeColor;
            openSpecificationButton.BackColor       = new PdfColor(255, 255, 255);
            openSpecificationButton.ForeColor       = orangeColor;
            openSpecificationButton.Text            = "Open Specification";
            openSpecificationButton.Actions.MouseUp = new PdfJavaScriptAction("this.exportDataObject({ cName: 'Product Catalog.pdf', nLaunch: 2 });");
            document.Form.Fields.Add(openSpecificationButton);

            RectangleF     uriAnnotationRectangle = new RectangleF(interactivePage.Graphics.ClientSize.Width - 160, interactivePage.Graphics.ClientSize.Height - 30, 80, 20);
            PdfTextWebLink linkAnnot = new PdfTextWebLink();
            linkAnnot.Url   = "http://www.adventure-works.com";
            linkAnnot.Text  = "http://www.adventure-works.com";
            linkAnnot.Font  = new PdfStandardFont(PdfFontFamily.Helvetica, 8);
            linkAnnot.Brush = PdfBrushes.White;
            linkAnnot.DrawTextWebLink(interactivePage, uriAnnotationRectangle.Location);
            #endregion

            #region Footer
            g.DrawRectangle(purpleBrush, new RectangleF(0, interactivePage.Graphics.ClientSize.Height - 100, interactivePage.Graphics.ClientSize.Width, 100));
            g.DrawPie(whitePen, whiteBrush, new RectangleF(-20, interactivePage.Graphics.ClientSize.Height - 250, 700, 200), 0, 180);
            #endregion

            //Save the PDF to the MemoryStream
            MemoryStream ms = new MemoryStream();

            document.Save(ms);

            //If the position is not set to '0' then the PDF will be empty.
            ms.Position = 0;

            //Close the PDF document.
            document.Close(true);

            //Download the PDF document in the browser.
            FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf");
            fileStreamResult.FileDownloadName = "Interactive features.pdf";
            return(fileStreamResult);
        }
Beispiel #5
0
        public ActionResult AutoFilter(string id, string FilterType, string button, string colorsList, string rdb1, string rdb3, string iconText, string iconSetTypeList, string field, string checkbox)
        {
            string basePath = _hostingEnvironment.WebRootPath;

            if (FilterType == null)
            {
                ViewBag.datasource  = icons.GetSymbols();
                ViewBag.datasource2 = icons.GetRating();
                ViewBag.datasource3 = icons.GetArrows();
                return(View());
            }
            else if (button == "Input Template")
            {
                //Step 1 : Instantiate the spreadsheet creation engine.
                ExcelEngine excelEngine = new ExcelEngine();
                //Step 2 : Instantiate the excel application object.
                IApplication application = excelEngine.Excel;
                IWorkbook    workbook;
                if (FilterType == "Advanced Filter")
                {
                    FileStream inputStream = new FileStream(basePath + @"/XlsIO/AdvancedFilterData.xlsx", FileMode.Open, FileAccess.Read);
                    workbook = application.Workbooks.Open(inputStream);
                }
                else if (FilterType == "Color Filter")
                {
                    FileStream inputStream = new FileStream(basePath + @"/XlsIO/FilterData_Color.xlsx", FileMode.Open, FileAccess.Read);
                    workbook = application.Workbooks.Open(inputStream);
                }
                else if (FilterType == "Icon Filter")
                {
                    FileStream inputStream = new FileStream(basePath + @"/XlsIO/IconFilterData.xlsx", FileMode.Open, FileAccess.Read);
                    workbook = application.Workbooks.Open(inputStream);
                }
                else
                {
                    FileStream inputStream = new FileStream(basePath + @"/XlsIO/FilterData.xlsx", FileMode.Open, FileAccess.Read);
                    workbook = application.Workbooks.Open(inputStream);
                }
                MemoryStream ms = new MemoryStream();
                workbook.SaveAs(ms);
                ms.Position = 0;
                return(File(ms, "Application/msexcel", "InputTemplate.xlsx"));
            }
            else
            {
                string fileName = null;

                //Step 1 : Instantiate the spreadsheet creation engine.
                ExcelEngine excelEngine = new ExcelEngine();
                //Step 2 : Instantiate the excel application object.
                IApplication application = excelEngine.Excel;
                IWorkbook    workbook;
                if (FilterType == "Advanced Filter")
                {
                    FileStream inputStream = new FileStream(basePath + @"/XlsIO/AdvancedFilterData.xlsx", FileMode.Open, FileAccess.Read);
                    workbook = application.Workbooks.Open(inputStream);
                }
                else if (FilterType == "Color Filter")
                {
                    FileStream inputStream = new FileStream(basePath + @"/XlsIO/FilterData_Color.xlsx", FileMode.Open, FileAccess.Read);
                    workbook = application.Workbooks.Open(inputStream);
                }
                else if (FilterType == "Icon Filter")
                {
                    FileStream inputStream = new FileStream(basePath + @"/XlsIO/IconFilterData.xlsx", FileMode.Open, FileAccess.Read);
                    workbook = application.Workbooks.Open(inputStream);
                }
                else
                {
                    FileStream inputStream = new FileStream(basePath + @"/XlsIO/FilterData.xlsx", FileMode.Open, FileAccess.Read);
                    workbook = application.Workbooks.Open(inputStream);
                }
                IWorksheet sheet = workbook.Worksheets[0];
                if (FilterType != "Advanced Filter")
                {
                    sheet.AutoFilters.FilterRange = sheet.Range[1, 1, 49, 3];
                }

                switch (FilterType)
                {
                case "Custom Filter":
                    fileName = "CustomFilter.xlsx";
                    IAutoFilter filter1 = sheet.AutoFilters[0];
                    filter1.IsAnd = false;
                    filter1.FirstCondition.ConditionOperator = ExcelFilterCondition.Equal;
                    filter1.FirstCondition.DataType          = ExcelFilterDataType.String;
                    filter1.FirstCondition.String            = "Owner";

                    filter1.SecondCondition.ConditionOperator = ExcelFilterCondition.Equal;
                    filter1.SecondCondition.DataType          = ExcelFilterDataType.String;
                    filter1.SecondCondition.String            = "Sales Representative";
                    break;

                case "Text Filter":
                    fileName = "TextFilter.xlsx";
                    IAutoFilter filter2 = sheet.AutoFilters[0];
                    filter2.AddTextFilter(new string[] { "Owner", "Sales Representative", "Sales Associate" });
                    break;

                case "DateTime Filter":
                    fileName = "DateTimeFilter.xlsx";
                    IAutoFilter filter3 = sheet.AutoFilters[1];
                    filter3.AddDateFilter(new DateTime(2004, 9, 1, 1, 0, 0, 0), DateTimeGroupingType.month);
                    filter3.AddDateFilter(new DateTime(2011, 1, 1, 1, 0, 0, 0), DateTimeGroupingType.year);
                    break;

                case "Dynamic Filter":
                    fileName = "DynamicFilter.xlsx";
                    IAutoFilter filter4 = sheet.AutoFilters[1];
                    filter4.AddDynamicFilter(DynamicFilterType.Quarter1);
                    break;

                case "Color Filter":
                    fileName = "ColorFilter.xlsx";
                    #region ColorFilter
                    sheet.AutoFilters.FilterRange = sheet["A1:C49"];

                    Syncfusion.Drawing.Color color = Syncfusion.Drawing.Color.Empty;
                    switch (colorsList.ToLower())
                    {
                    case "red":
                        color = Color.Red;
                        break;

                    case "blue":
                        color = Color.Blue;
                        break;

                    case "green":
                        color = Color.Green;
                        break;

                    case "yellow":
                        color = Color.Yellow;
                        break;

                    case "empty":
                        color = Color.Empty;
                        break;
                    }
                    if (rdb3 == "FontColor")
                    {
                        IAutoFilter filter = sheet.AutoFilters[2];
                        filter.AddColorFilter(color, ExcelColorFilterType.FontColor);
                    }
                    else
                    {
                        IAutoFilter filter = sheet.AutoFilters[0];
                        filter.AddColorFilter(color, ExcelColorFilterType.CellColor);
                    }


                    #endregion
                    break;

                case "Icon Filter":
                    fileName = "IconFilter.xlsx";
                    #region IconFilter
                    sheet.AutoFilters.FilterRange = sheet["A4:D44"];
                    int filterIndex          = 0;
                    ExcelIconSetType iconset = ExcelIconSetType.FiveArrows;
                    int iconId = 0;
                    switch (iconSetTypeList)
                    {
                    case "ThreeSymbols":
                        iconset     = ExcelIconSetType.ThreeSymbols;
                        filterIndex = 3;
                        break;

                    case "FourRating":
                        iconset     = ExcelIconSetType.FourRating;
                        filterIndex = 1;
                        break;

                    case "FiveArrows":
                        iconset     = ExcelIconSetType.FiveArrows;
                        filterIndex = 2;
                        break;
                    }
                    switch (iconText)
                    {
                    case "0":
                        //Do nothing
                        break;

                    case "1":
                        iconId = 1;
                        break;

                    case "2":
                        iconId = 2;
                        break;

                    case "3":
                        if (iconSetTypeList.Equals("ThreeSymbols"))
                        {
                            iconset = (ExcelIconSetType)(-1);
                        }
                        else
                        {
                            iconId = 3;
                        }
                        break;

                    case "4":
                        if (iconSetTypeList.Equals("FourRating"))
                        {
                            iconset = (ExcelIconSetType)(-1);
                        }
                        else
                        {
                            iconId = 4;
                        }
                        break;

                    case "5":
                        iconset = (ExcelIconSetType)(-1);
                        break;
                    }
                    IAutoFilter filter5 = sheet.AutoFilters[filterIndex];
                    filter5.AddIconFilter(iconset, iconId);
                    #endregion
                    break;

                case "Advanced Filter":
                    fileName = "AdvancedFilter.xlsx";
                    #region AdvancedFilter

                    IRange filterRange   = sheet.Range["A8:G51"];
                    IRange criteriaRange = sheet.Range["A2:B5"];
                    if (rdb1 == "FilterIN")
                    {
                        sheet.AdvancedFilter(ExcelFilterAction.FilterInPlace, filterRange, criteriaRange, null, checkbox == "Unique");
                    }
                    else if (rdb1 == "FilterCopy")
                    {
                        IRange range = sheet.Range["I7:O7"];
                        range.Merge();
                        range.Text = "FilterCopy";
                        range.CellStyle.Font.RGBColor = Syncfusion.Drawing.Color.FromArgb(0, 112, 192);
                        range.HorizontalAlignment     = ExcelHAlign.HAlignCenter;
                        range.CellStyle.Font.Bold     = true;
                        IRange copyRange = sheet.Range["I8"];
                        sheet.AdvancedFilter(ExcelFilterAction.FilterCopy, filterRange, criteriaRange, copyRange, checkbox == "Unique");
                    }
                    break;
                    #endregion
                }

                workbook.Version = ExcelVersion.Excel2016;

                try
                {
                    MemoryStream result = new MemoryStream();
                    workbook.SaveAs(result);
                    result.Position = 0;


                    return(File(result, "Application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", fileName));
                }
                catch (Exception)
                {
                }

                //Close the workbook.
                workbook.Close();
                excelEngine.Dispose();
                return(View());
            }
        }
Beispiel #6
0
        /// <summary>
        /// Create a child shape with its specified properties and add into specified group shape
        /// </summary>
        /// <param name="autoShapeType">Represent the AutoShapeType of child shape</param>
        /// <param name="bounds">Represent the bounds of child shape to be placed</param>
        /// <param name="rotation">Represent the rotation of child shape</param>
        /// <param name="flipH">Represent the horizontal flip of child shape</param>
        /// <param name="flipV">Represent the vertical flip of child shape</param>
        /// <param name="fillColor">Represent the fill color of child shape</param>
        /// <param name="text">Represent the text that to be append in child shape</param>
        /// <param name="groupShape">Represent the group shape to add a child shape</param>
        /// <param name="wordDocument">Represent the Word document instance</param>
        private static void CreateChildShape(AutoShapeType autoShapeType, RectangleF bounds, float rotation, bool flipH, bool flipV, Syncfusion.Drawing.Color fillColor, string text, GroupShape groupShape, WordDocument wordDocument)
        {
            //Creates new shape to add into group
            Shape shape = new Shape(wordDocument, autoShapeType);

            //Sets height and width for shape
            shape.Height = bounds.Height;
            shape.Width  = bounds.Width;
            //Sets horizontal and vertical position
            shape.HorizontalPosition = bounds.X;
            shape.VerticalPosition   = bounds.Y;
            //Set rotation and flipH for the shape
            if (rotation != 0)
            {
                shape.Rotation = rotation;
            }
            if (flipH)
            {
                shape.FlipHorizontal = true;
            }
            if (flipV)
            {
                shape.FlipVertical = true;
            }
            //Applies fill color for shape
            if (fillColor != Syncfusion.Drawing.Color.White)
            {
                shape.FillFormat.Fill  = true;
                shape.FillFormat.Color = fillColor;
            }
            //Set wrapping style for shape
            shape.WrapFormat.TextWrappingStyle = TextWrappingStyle.InFrontOfText;
            //Sets horizontal and vertical origin
            shape.HorizontalOrigin = HorizontalOrigin.Page;
            shape.VerticalOrigin   = VerticalOrigin.Page;
            //Sets no line to RoundedRectangle shapes
            if (autoShapeType == AutoShapeType.RoundedRectangle)
            {
                shape.LineFormat.Line = false;
            }
            //Add paragraph for the shape textbody
            if (text != null)
            {
                IWParagraph paragraph = shape.TextBody.AddParagraph();
                //Set required textbody alignments
                shape.TextFrame.TextVerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                //Set required paragraph alignments
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                IWTextRange textRange = paragraph.AppendText(text);
                //Applies a required text formatting's
                textRange.CharacterFormat.FontName  = "Calibri";
                textRange.CharacterFormat.FontSize  = 15;
                textRange.CharacterFormat.TextColor = Syncfusion.Drawing.Color.White;
                textRange.CharacterFormat.Bold      = true;
                textRange.CharacterFormat.Italic    = true;
            }
            //Adds the specified shape to group shape
            groupShape.Add(shape);
        }
Beispiel #7
0
        private async void ViewReciept_Clicked(object sender, EventArgs e)
        {
            //  await Navigation.PushAsync(new NavigationPage(new RecieptPage(products,saleproducts,  paymentname)) );
            #region Fields
            //Create border color
            PdfColor borderColor     = new PdfColor(Color.FromArgb(255, 51, 181, 75));
            PdfBrush lightGreenBrush = new PdfSolidBrush(new PdfColor(Color.FromArgb(255, 218, 218, 221)));

            PdfBrush darkGreenBrush = new PdfSolidBrush(new PdfColor(Color.FromArgb(255, 51, 181, 75)));

            PdfBrush whiteBrush = new PdfSolidBrush(new PdfColor(Color.FromArgb(255, 255, 255, 255)));
            PdfPen   borderPen  = new PdfPen(borderColor, 1f);
            Stream   fontStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("IttezanPos.Assets.arial.ttf");
            //Create TrueType font
            PdfTrueTypeFont headerFont       = new PdfTrueTypeFont(fontStream, 9, PdfFontStyle.Bold);
            PdfTrueTypeFont arialRegularFont = new PdfTrueTypeFont(fontStream, 9, PdfFontStyle.Regular);
            PdfTrueTypeFont arialBoldFont    = new PdfTrueTypeFont(fontStream, 11, PdfFontStyle.Bold);


            const float margin       = 30;
            const float lineSpace    = 7;
            const float headerHeight = 90;
            #endregion

            #region header and buyer infomation
            //Create PDF with PDF/A-3b conformance
            PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A3B);
            //Set ZUGFeRD profile
            document.ZugferdConformanceLevel = ZugferdConformanceLevel.Basic;

            //Add page to the PDF
            PdfPage page = document.Pages.Add();

            PdfGraphics graphics = page.Graphics;

            //Get the page width and height
            float pageWidth  = page.GetClientSize().Width;
            float pageHeight = page.GetClientSize().Height;
            //Draw page border
            graphics.DrawRectangle(borderPen, new RectangleF(0, 0, pageWidth, pageHeight));

            //Fill the header with light Brush
            graphics.DrawRectangle(lightGreenBrush, new RectangleF(0, 0, pageWidth, headerHeight));

            RectangleF headerAmountBounds = new RectangleF(400, 0, pageWidth - 400, headerHeight);

            graphics.DrawString("INVOICE", headerFont, whiteBrush, new PointF(margin, headerAmountBounds.Height / 3));
            Stream imageStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("IttezanPos.Assets.ic_launcher.png");

            //Create a new PdfBitmap instance
            PdfBitmap image = new PdfBitmap(imageStream);

            //Draw the image
            graphics.DrawImage(image, new PointF(margin + 90, headerAmountBounds.Height / 2));
            graphics.DrawRectangle(darkGreenBrush, headerAmountBounds);

            graphics.DrawString("Amount", arialRegularFont, whiteBrush, headerAmountBounds,
                                new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle));
            graphics.DrawString("$" + products.amount_paid.ToString(), arialBoldFont, whiteBrush,
                                new RectangleF(400, lineSpace, pageWidth - 400, headerHeight + 15), new
                                PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle));



            PdfTextElement textElement = new PdfTextElement("Invoice Number: " + products.id.ToString(), arialRegularFont);

            PdfLayoutResult layoutResult = textElement.Draw(page, new PointF(headerAmountBounds.X - margin, 120));

            textElement.Text = "Date : " + DateTime.Now.ToString("dddd dd, MMMM yyyy");
            textElement.Draw(page, new PointF(layoutResult.Bounds.X, layoutResult.Bounds.Bottom + lineSpace));
            var dbpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "MyDb.db");
            var db     = new SQLiteConnection(dbpath);
            if (products.client_id != null)
            {
                var client = (db.Table <Client>().ToList().Where(clien => clien.id == int.Parse(products.client_id)).FirstOrDefault());
                textElement.Text = "Bill To:";
                layoutResult     = textElement.Draw(page, new PointF(margin, 120));

                textElement.Text = client.enname;
                layoutResult     = textElement.Draw(page, new PointF(margin, layoutResult.Bounds.Bottom + lineSpace));
                textElement.Text = client.address;
                layoutResult     = textElement.Draw(page, new PointF(margin, layoutResult.Bounds.Bottom + lineSpace));
                textElement.Text = client.email;
                layoutResult     = textElement.Draw(page, new PointF(margin, layoutResult.Bounds.Bottom + lineSpace));
                textElement.Text = client.phone;
                layoutResult     = textElement.Draw(page, new PointF(margin, layoutResult.Bounds.Bottom + lineSpace));
            }

            #endregion

            #region Invoice data
            PdfGrid        grid            = new PdfGrid();
            DataTable      dataTable       = new DataTable("EmpDetails");
            List <Product> customerDetails = new List <Product>();
            //Add columns to the DataTable
            dataTable.Columns.Add("ID");
            dataTable.Columns.Add("Name");
            dataTable.Columns.Add("Price");
            dataTable.Columns.Add("Qty");
            dataTable.Columns.Add("Disc");
            dataTable.Columns.Add("Total");

            //Add rows to the DataTable.
            foreach (var item in products.products)
            {
                Product customer = new Product();
                customer.id          = products.products.IndexOf(item) + 1;
                customer.Enname      = item.Enname;
                customer.sale_price  = item.sale_price;
                customer.quantity    = item.quantity;
                customer.discount    = item.discount;
                customer.total_price = item.total_price;
                customerDetails.Add(customer);
                dataTable.Rows.Add(new string[] { customer.id.ToString(), customer.Enname, customer.sale_price.ToString(),
                                                  customer.quantity.ToString(), customer.discount.ToString(), customer.total_price.ToString() });
            }

            //Assign data source.
            grid.DataSource = dataTable;


            grid.Columns[1].Width      = 150;
            grid.Style.Font            = arialRegularFont;
            grid.Style.CellPadding.All = 5;

            grid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable1Light);

            layoutResult = grid.Draw(page, new PointF(0, layoutResult.Bounds.Bottom + 40));

            textElement.Text = "Grand Total: ";
            textElement.Font = arialBoldFont;
            layoutResult     = textElement.Draw(page, new PointF(headerAmountBounds.X - 40, layoutResult.Bounds.Bottom +
                                                                 lineSpace));

            float totalAmount = float.Parse(products.total_price);
            textElement.Text = "$" + totalAmount.ToString();
            layoutResult     = textElement.Draw(page, new PointF(layoutResult.Bounds.Right + 4, layoutResult.Bounds.Y));

            //graphics.DrawString("$" + totalAmount.ToString(), arialBoldFont, whiteBrush,
            //    new RectangleF(400, lineSpace, pageWidth - 400, headerHeight + 15), new
            //    PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle));
            textElement.Text = "Total Discount: ";
            textElement.Font = arialBoldFont;
            layoutResult     = textElement.Draw(page, new PointF(headerAmountBounds.X - 40, layoutResult.Bounds.Bottom +
                                                                 lineSpace));

            float totalDisc = float.Parse(products.discount);
            textElement.Text = "$" + totalDisc.ToString();
            layoutResult     = textElement.Draw(page, new PointF(layoutResult.Bounds.Right + 4, layoutResult.Bounds.Y));

            //graphics.DrawString("$" + totalDisc.ToString(), arialBoldFont, whiteBrush,
            //    new RectangleF(400, lineSpace, pageWidth - 400, headerHeight + 15), new
            //    PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle));


            #endregion

            #region Seller information
            borderPen.DashStyle   = PdfDashStyle.Custom;
            borderPen.DashPattern = new float[] { 3, 3 };

            PdfLine line = new PdfLine(borderPen, new PointF(0, 0), new PointF(pageWidth, 0));
            layoutResult = line.Draw(page, new PointF(0, pageHeight - 100));

            textElement.Text = "IttezanPos";
            textElement.Font = arialRegularFont;
            layoutResult     = textElement.Draw(page, new PointF(margin, layoutResult.Bounds.Bottom + (lineSpace * 3)));
            textElement.Text = "Buradah,  AlQassim, Saudi Arabia";
            layoutResult     = textElement.Draw(page, new PointF(margin, layoutResult.Bounds.Bottom + lineSpace));
            textElement.Text = "Any Questions? ittezan.com";
            layoutResult     = textElement.Draw(page, new PointF(margin, layoutResult.Bounds.Bottom + lineSpace));

            #endregion

            //#region Create ZUGFeRD XML

            ////Create //ZUGFeRD Invoice
            //ZugferdInvoice invoice = new ZugferdInvoice("2058557939", DateTime.Now, CurrencyCodes.USD);

            ////Set ZUGFeRD profile to basic
            //invoice.Profile = ZugferdProfile.Basic;

            ////Add buyer details
            //invoice.Buyer = new UserDetails
            //{
            //    ID = "Abraham_12",
            //    Name = "Abraham Swearegin",
            //    ContactName = "Swearegin",
            //    City = "United States, California",
            //    Postcode = "9920",
            //    Country = CountryCodes.US,
            //    Street = "9920 BridgePointe Parkway"
            //};

            ////Add seller details
            //invoice.Seller = new UserDetails
            //{
            //    ID = "Adventure_123",
            //    Name = "AdventureWorks",
            //    ContactName = "Adventure support",
            //    City = "Austin,TX",
            //    Postcode = "78721",
            //    Country = CountryCodes.US,
            //    Street = "800 Interchange Blvd"
            //};


            //IEnumerable<Product> products = saleproducts;

            //foreach (Product product in products)
            //    invoice.AddProduct(product);


            //invoice.TotalAmount = totalAmount;

            //MemoryStream zugferdXML = new MemoryStream();
            //invoice.Save(zugferdXML);
            //#endregion

            #region Embed ZUGFeRD XML to PDF

            //Attach ZUGFeRD XML to PDF
            //PdfAttachment attachment = new PdfAttachment("ZUGFeRD-invoice.xml", zugferdXML);
            //attachment.Relationship = PdfAttachmentRelationship.Alternative;
            //attachment.ModificationDate = DateTime.Now;
            //attachment.Description = "ZUGFeRD-invoice";
            //attachment.MimeType = "application/xml";
            //document.Attachments.Add(attachment);
            #endregion
            //Creates an attachment
            MemoryStream stream = new MemoryStream();
            //    Stream invoiceStream = typeof(MainPage).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Assets.Data.ZUGFeRD-invoice.xml");

            PdfAttachment attachment = new PdfAttachment("ZUGFeRD-invoice.xml", stream);

            attachment.Relationship = PdfAttachmentRelationship.Alternative;

            attachment.ModificationDate = DateTime.Now;

            attachment.Description = "ZUGFeRD-invoice";

            attachment.MimeType = "application/xml";

            document.Attachments.Add(attachment);

            //Save the document into memory stream



            document.Save(stream);

            //Close the document

            document.Close(true);

            await Xamarin.Forms.DependencyService.Get <ISave>().SaveAndView("تقرير العملاء.pdf", "application/pdf", stream);
        }
Beispiel #8
0
        private void DrawHeaderOfDocument(PdfGraphics graphics)
        {
            graphics.DrawLine(new PdfPen(Color.FromArgb(255, 0, 0, 0))
            {
                Width = 0.25f
            }, 0, 5, _document.PageSettings.Width - 20, 5);

            graphics.DrawString(header1, _font10Regular, _brushGreyishBrownTwo,
                                new PointF(0, 10));
            graphics.DrawString(header2, _font10Regular, _brushGreyishBrownTwo,
                                new PointF(0, 25));
            graphics.DrawString(header3, _font10Regular, _brushGreyishBrownTwo,
                                new PointF(0, 40));
            graphics.DrawString(header4, _font10Regular, _brushGreyishBrownTwo,
                                new PointF(0, 55));
            graphics.DrawString(header5, _font10Regular, _brushGreyishBrownTwo,
                                new PointF(0, 70));

            graphics.DrawLine(new PdfPen(Color.FromArgb(255, 0, 0, 0))
            {
                Width = 0.25f
            }, 0, 90, _document.PageSettings.Width - 10, 90);

            graphics.DrawString(AppResources.BillingAddress, _font14Bold, _brushGreyishBrownTwo,
                                new PointF(0, 100));

            graphics.DrawString(string.IsNullOrEmpty(Customer.Name) ? "" :Customer.Name, _font10Regular, _brushGreyishBrownTwo,
                                new PointF(0, 125));
            graphics.DrawString(string.IsNullOrEmpty(Customer.ContactAddress) ? "" : Customer.ContactAddress.Replace("\n", " "), _font10Regular, _brushGreyishBrownTwo,
                                new PointF(0, 140));
            graphics.DrawString(string.IsNullOrEmpty(Customer.Website) ? "" :Customer.Website, _font10Regular, _brushGreyishBrownTwo,
                                new PointF(0, 155));
            graphics.DrawString(string.IsNullOrEmpty(Customer.Phone) ? "" : Customer.Phone, _font10Regular, _brushGreyishBrownTwo,
                                new PointF(0, 170));
            graphics.DrawString(string.IsNullOrEmpty(Customer.Email) ? "" : Customer.Email, _font10Regular, _brushGreyishBrownTwo,
                                new PointF(0, 185));


            graphics.DrawString(AppResources.OrderNumber + SaleOrder.ClientOrderRef, _font14Bold, _brushGreyishBrownTwo,
                                new PointF(0, 210));

            graphics.DrawString(AppResources.OrderDate, _font10Regular, _brushBlack,
                                new PointF(0, 230));
            graphics.DrawString(SaleOrder.CreateDate.ToString("G"), _font10Regular, _brushGreyishBrownTwo,
                                new PointF(0, 245));

            graphics.DrawString(AppResources.Prescriber, _font10Regular, _brushBlack,
                                new PointF(150, 230));
            graphics.DrawString(string.IsNullOrEmpty(SaleOrder.TrainerName) ? "" : SaleOrder.TrainerName, _font10Regular, _brushGreyishBrownTwo,
                                new PointF(150, 245));


            graphics.DrawString(AppResources.PaymentMethod, _font10Regular, _brushBlack,
                                new PointF(0, 260));
            graphics.DrawString(string.IsNullOrEmpty(SaleOrder.PaymentMethod) ? "" : SaleOrder.PaymentMethod, _font10Regular, _brushGreyishBrownTwo,
                                new PointF(0, 275));

            graphics.DrawString(AppResources.PaymentNote, _font10Regular, _brushBlack,
                                new PointF(150, 260));
            graphics.DrawString(string.IsNullOrWhiteSpace(SaleOrder.PaymentNote) ? "" : SaleOrder.PaymentNote, _font10Regular, _brushGreyishBrownTwo,
                                new PointF(150, 275));
        }
Beispiel #9
0
        public byte[] CreatePdfFile(QuotationsModel saleOrder, List <ProductQuotationModel> items, Partner customer, byte[] signature, bool generateFullVersion)
        {
            SaleOrder           = saleOrder.SaleOrder;
            OrderItems          = items;
            Customer            = customer;
            model               = saleOrder;
            Signature           = signature;
            GenerateFullVersion = generateFullVersion;

            //Create a new document
            _document = new PdfDocument();
            _document.PageSettings.Size        = PdfPageSize.A4;
            _document.PageSettings.Orientation = PdfPageOrientation.Portrait;
            _document.PageSettings.SetMargins(10, 10);

            PdfPage     page     = _document.Pages.Add();
            PdfGraphics graphics = page.Graphics;


            if (true)
            {
                var format = new PdfStringFormat();
                //format.NoClip = true;
                format.Alignment     = PdfTextAlignment.Center;
                format.WordWrap      = PdfWordWrapType.Word;
                format.LineAlignment = PdfVerticalAlignment.Bottom;

                PdfPageTemplateElement footer = new PdfPageTemplateElement(_document.Pages[0].GetClientSize().Width - 100, 30);

                PdfFont  font  = new PdfStandardFont(PdfFontFamily.Helvetica, 7);
                PdfBrush brush = new PdfSolidBrush(Color.Black);

                footer.Alignment = PdfAlignmentStyle.BottomCenter;

                footer.Graphics.DrawLine(new PdfPen(Color.FromArgb(255, 0, 0, 0))
                {
                    Width = 0.25f
                }, 0, 0, _document.Pages[0].GetClientSize().Width - 20, 0);
                footer.Graphics.DrawString(footerPage, font, brush, new RectangleF(0, 0, _document.Pages[0].GetClientSize().Width - 100, 30), format);

                _document.Template.Bottom = footer;
            }

            //CONTENT PRINCIPAL PAGE
            DrawPage(page, graphics);

            var stream = new MemoryStream();

            //save the document into stream

            _document.Save(stream);

            PdfDocumentStream = stream;

            ArrayBytes = stream.ToArray();

            //close the document
            _document.Close(true);

            Debug.WriteLine("End of creating file");

            return(ArrayBytes);
        }