예제 #1
0
        public static void Create(PdfViewModel pdfvm, Curriculum curriculum)
        {
            // CuriculumModel curriculum = db.Curiculums.Include("StudentId").Where(m => m.CuriculumId == pdfvm.curriculumId).FirstOrDefault();
            List <CurriculumTopic> curriculumTopics = curriculum.Topics.ToList();
            Student student = curriculum.Student;


            // TODO: Sort and group topics by first Certification
            SortedDictionary <string, List <Topic> > groupedTopics = new SortedDictionary <string, List <Topic> >();

            foreach (var topic in curriculumTopics)
            {
                string first = String.Empty;
                if (topic.Topic.Certificeringen.Count != 0)
                {
                    first = topic.Topic.Certificeringen.First().Naam;
                }

                if (!groupedTopics.ContainsKey(first))
                {
                    groupedTopics.Add(first, new List <Topic>());
                    groupedTopics[first].Add(topic.Topic);
                }
                else
                {
                    groupedTopics[first].Add(topic.Topic);
                }
            }

            PdfDocument document = new PdfDocument();
            PdfPage     page     = document.AddPage();
            XGraphics   gfx      = XGraphics.FromPdfPage(page);
            var         tf       = new XTextFormatter(gfx);

            XStringFormat stringFormat = new XStringFormat();

            stringFormat.LineAlignment = XLineAlignment.Near;
            stringFormat.Alignment     = XStringAlignment.Near;

            var basepath = AppDomain.CurrentDomain.BaseDirectory;
            var path     = String.Concat(basepath, "App_Data\\logo_itvitae_learning_liggend.png");

            //var path = Server.MapPath(@"~/App_Data/logo_itvitae_learning_liggend.png");
            XImage logo = XImage.FromFile(path);

            gfx.DrawImage(logo, new XPoint(430, 5));

            //Fonts
            XFont Calibri20Bold       = new XFont("calibri", 20, XFontStyle.Bold);
            XFont Calibri20BoldItalic = new XFont("calibri", 20, XFontStyle.BoldItalic);
            XFont LabelFont           = new XFont("calibri", 11, XFontStyle.Regular);

            //Title Header
            gfx.DrawString("Persoonlijk Curriculum", Calibri20Bold, XBrushes.Black,
                           new XRect(0, 20, page.Width, 0), XStringFormats.Center);
            gfx.DrawString("ITvitae learning", Calibri20BoldItalic, XBrushes.Black,
                           new XRect(0, 41, page.Width, 0), XStringFormats.Center);
            //XImage ITvitaeLogo = XImage.FromFile(string.Empty);
            //gfx.DrawImage(ITvitaeLogo, new XRect(0, 0, 0, 0));

            //30-100-30 -100 -75-100-30 -100 -30
            //0 |30 |130|160|260|335|435|465|565|595
            //Student Info
            int col1x = 30; int col2x = 135; int col3x = 335; int col4x = 435;
            int colwidth = 100; int rowheight = 12;
            int row1 = 60; int row2 = 80; int row3 = 100;

            DrawLabel("Naam:", col1x, row1, colwidth, rowheight, gfx);
            DrawLabel(student.VolledigeNaam, col2x, row1, colwidth, rowheight, gfx);

            DrawLabel("Geboortedatum:", col1x, row2, colwidth, rowheight, gfx);
            DrawLabel(pdfvm.DoB.ToShortDateString(), col2x, row2, colwidth, rowheight, gfx);

            DrawLabel("StartDatum:", col1x, row3, colwidth, rowheight, gfx);
            DrawLabel(pdfvm.StartDate.ToShortDateString(), col2x, row3, colwidth, rowheight, gfx);

            DrawLabel("Einddatum:", col3x, row3, colwidth, rowheight, gfx);
            DrawLabel(pdfvm.EndDate.ToShortDateString(), col4x, row3, colwidth, rowheight, gfx);

            DrawLabel("Niveau:", col3x, row1, colwidth, rowheight, gfx);
            DrawLabel(pdfvm.Niveau, col4x, row1, colwidth, rowheight, gfx);

            DrawLabel("Richting:", col3x, row2, colwidth, rowheight, gfx);
            DrawLabel(pdfvm.Course, col4x, row2, colwidth, rowheight, gfx);

            //Topics
            //595 into 3 columns starting on Y = 150
            int   YPointer = 150;
            int   topicColumnWidth = 159;
            int   topicColumn1 = 30; int topicColumn2 = 30 + topicColumnWidth; int topicColumn3 = 2 * topicColumnWidth + 60;
            XFont certFont = new XFont("calibri", 11, XFontStyle.Regular);
            XPen  pen      = new XPen(XColors.LightGray);

            //Add headers
            DrawLabel("Modules", topicColumn1, YPointer, topicColumnWidth, rowheight, gfx);
            if (pdfvm.Leerdoel)
            {
                DrawLabel("Leerdoelen", topicColumn2, YPointer, topicColumnWidth, rowheight, gfx);
            }
            if (pdfvm.Certificeringen)
            {
                DrawLabel("Certificeringen", topicColumn3, YPointer, topicColumnWidth, rowheight, gfx);
            }
            YPointer += rowheight;

            //List<Topic> topics = curriculum.Topics.ToList();
            List <CurriculumTopic> topics = curriculum.Topics.ToList();

            for (int i = 0; i < curriculum.Topics.Count; i++)
            {
                List <DrawStringListItem> drawList = new List <DrawStringListItem>();

                //Update YPointer;
                YPointer += 4;
                CurriculumTopic topic = topics[i];

                //measure topic
                XSize topicSize = gfx.MeasureString(topic.Topic.NaamCode, certFont);
                //make rect
                int    rectWidth    = topicColumnWidth;
                double rectRows     = 1;
                int    CertYPointer = 0;
                if (topicSize.Width > topicColumnWidth)
                {
                    rectRows = topicSize.Width / topicColumnWidth;
                    if (rectRows % 1 > 0)
                    {
                        rectRows++;
                    }
                    rectRows = Math.Floor(rectRows);
                }
                //check if new page is needed
                if (YPointer + (rowheight * rectRows) > 780)
                {
                    gfx = NewPage(document, out page, gfx, out tf, out YPointer, logo);
                }
                //Make topicrect
                XRect topicRect = new XRect(topicColumn1, 0, rectWidth, rowheight * rectRows);
                //Add string to drawlist
                drawList.Add(new DrawStringListItem(topic.Topic.NaamCode, certFont, XBrushes.Black, topicRect));

                if (pdfvm.Leerdoel)
                {
                    //measure leerdoel
                    XSize leerdoelSize = gfx.MeasureString(topic.Topic.Leerdoel, certFont);
                    //make rect
                    if (leerdoelSize.Width / topicColumnWidth > rectRows)
                    {
                        rectRows = leerdoelSize.Width / topicColumnWidth;
                        if (rectRows % 1 > 0)
                        {
                            rectRows++;
                        }
                        rectRows = Math.Floor(rectRows);
                    }
                    //check if new page is needed
                    if (YPointer + (rowheight * rectRows) > 780)
                    {
                        gfx = NewPage(document, out page, gfx, out tf, out YPointer, logo);
                    }
                    XRect leerdoelRect = new XRect(topicColumn2, 0, rectWidth, rowheight * rectRows);
                    //update height and y pointer
                    drawList.Add(new DrawStringListItem(topic.Topic.Leerdoel, certFont, XBrushes.Black, leerdoelRect));
                }

                if (pdfvm.Certificeringen)
                {
                    List <Certificering> certs = topic.Topic.Certificeringen.ToList();
                    for (int j = 0; j < certs.Count; j++)
                    {
                        //measure each cert
                        XSize certSize = gfx.MeasureString(certs[j].Naam, certFont);
                        //make rect for each cert
                        double certRows = 1;
                        if (certSize.Width / topicColumnWidth > certRows)
                        {
                            certRows = certSize.Width / topicColumnWidth;
                            if (certRows % 1 > 0)
                            {
                                certRows++;
                            }
                            certRows = Math.Floor(certRows);
                        }
                        XRect certRect = new XRect(topicColumn3, CertYPointer, rectWidth, rowheight * certRows);
                        //Add each cert to drawlist
                        drawList.Add(new DrawStringListItem(certs[j].Naam, certFont, XBrushes.Black, certRect));
                        //update CertYPointer for the next cert
                        CertYPointer += rowheight * (int)certRows;
                    }
                    //Check if certs go over the footer
                    if (YPointer + CertYPointer > 780)
                    {
                        gfx = NewPage(document, out page, gfx, out tf, out YPointer, logo);
                    }
                }

                //Draw all the things relative to YPointer
                gfx.DrawLine(pen, topicColumn1, YPointer - 2, topicColumn3 + topicColumnWidth, YPointer - 2);
                foreach (var item in drawList)
                {
                    XRect r = new XRect(item.Rect.X, item.Rect.Y + YPointer, item.Rect.Width, item.Rect.Height);
                    tf.DrawString(item.Text, item.Font, item.Brush, r);
                }
                YPointer += (rowheight * (int)rectRows) > CertYPointer ? (rowheight * (int)rectRows) : CertYPointer;
            }

            //add footers
            gfx.Dispose();
            int pageNumber = 1; int outOf = document.Pages.Count;

            foreach (PdfPage pdfPage in document.Pages)
            {
                gfx = XGraphics.FromPdfPage(pdfPage);
                int   footerY    = 802;
                XFont footerFont = new XFont("verdana", 10, XFontStyle.Italic);
                gfx.DrawLine(pen, 0, footerY, page.Width, footerY);
                gfx.DrawString($"Pagina {pageNumber}/{outOf}", footerFont, XBrushes.SlateGray, new XPoint(455, footerY + 20));
                gfx.DrawString("Versie 1.0", footerFont, XBrushes.SlateGray, new XPoint(65, footerY + 20));
                pageNumber++;
            }



            string filename = student + $"{ DateTime.Now.Millisecond.ToString()}.pdf";

            // $"Hello_{DateTime.Now.Millisecond.ToString()}.pdf";
            document.Save(filename);
            Process.Start(filename);
        }
예제 #2
0
        public static void setCard(XGraphics gfx, int cardNumber, String color, String imageBoxRound, ModelStudent obj, String themePath)
        {
            // Settings for width and height , font and size
            double labelValueY                   = 110;
            double labelValueX                   = 95;
            double labelValueX2                  = 385;
            string lableFontStatic               = "Comic Sans MS";
            string lableFontDynamic              = "Calibri (Body)";
            double fontStaticSize                = 6;
            double fontDynamicSize               = 9;
            double constantGapPictureAndWords    = 30;
            double constantYAxisIncrementPerCard = 300;


            XImage ximageTheme = XImage.FromFile(themePath);

            // assign new numbers based on card number


            if (ximageTheme.Size.Width < 340)
            {
                System.Windows.Forms.MessageBox.Show("Theme image width  is too small");
                return;
            }
            else if (ximageTheme.Size.Width >= 360)
            {
                System.Windows.Forms.MessageBox.Show("Theme image width is too much");
                return;
            }
            else if (ximageTheme.Size.Height < 220)
            {
                System.Windows.Forms.MessageBox.Show("Theme image Height  is too small");
                return;
            }
            else if (ximageTheme.Size.Height >= 240)
            {
                System.Windows.Forms.MessageBox.Show("Theme image Height is too much");
                return;
            }
            ximageTheme.Interpolate = false;
            if (cardNumber == 1)
            {
                gfx.DrawImage(ximageTheme, new XPoint(labelValueX - 60, labelValueY - 80));
            }
            else if (cardNumber == 2)
            {
                labelValueX = labelValueX2;
                gfx.DrawImage(ximageTheme, new XPoint(labelValueX2 - 60, labelValueY - 80));
            }
            else if (cardNumber == 3)
            {
                labelValueY = (1 * constantYAxisIncrementPerCard);
                gfx.DrawImage(ximageTheme, new XPoint(labelValueX - 60, labelValueY - 80));
            }
            else if (cardNumber == 4)
            {
                labelValueY = (1 * constantYAxisIncrementPerCard);
                labelValueX = labelValueX2;
                gfx.DrawImage(ximageTheme, new XPoint(labelValueX2 - 60, labelValueY - 80));
            }
            else if (cardNumber == 5)
            {
                labelValueY = (2 * constantYAxisIncrementPerCard) - 110;
                gfx.DrawImage(ximageTheme, new XPoint(labelValueX - 60, labelValueY - 80));
            }
            else if (cardNumber == 6)
            {
                labelValueY = (2 * constantYAxisIncrementPerCard) - 110;
                labelValueX = labelValueX2;
                gfx.DrawImage(ximageTheme, new XPoint(labelValueX2 - 60, labelValueY - 80));
            }
            else if (cardNumber == 7)
            {
                labelValueY = (3 * constantYAxisIncrementPerCard) - 220;
                gfx.DrawImage(ximageTheme, new XPoint(labelValueX - 60, labelValueY - 80));
            }
            else if (cardNumber == 8)
            {
                labelValueY = (3 * constantYAxisIncrementPerCard) - 220;
                labelValueX = labelValueX2;
                gfx.DrawImage(ximageTheme, new XPoint(labelValueX2 - 60, labelValueY - 80));
            }

            // set image frame
            if (imageBoxRound.Equals("boxedblue.png"))
            {
                XImage ximageBackground;
                ximageBackground = XImage.FromGdiPlusImage(Properties.Resources.boxedblue);
                gfx.DrawImage(ximageBackground, labelValueX - 50, labelValueY - 9, 75, 75);
            }
            else if (imageBoxRound.Equals("boxedgreen.png"))
            {
                XImage ximageBackground;
                ximageBackground = XImage.FromGdiPlusImage(Properties.Resources.boxedgreen);
                gfx.DrawImage(ximageBackground, labelValueX - 50, labelValueY - 9, 75, 75);
            }
            else if (imageBoxRound.Equals("boxedorange.png"))
            {
                XImage ximageBackground;
                ximageBackground = XImage.FromGdiPlusImage(Properties.Resources.boxedorange);
                gfx.DrawImage(ximageBackground, labelValueX - 50, labelValueY - 9, 75, 75);
            }
            else if (imageBoxRound.Equals("boxedred.png"))
            {
                XImage ximageBackground;
                ximageBackground = XImage.FromGdiPlusImage(Properties.Resources.boxedred);
                gfx.DrawImage(ximageBackground, labelValueX - 50, labelValueY - 9, 75, 75);
            }
            else if (imageBoxRound.Equals("roundblue.png"))
            {
                XImage ximageBackground;
                ximageBackground = XImage.FromGdiPlusImage(Properties.Resources.roundblue);
                gfx.DrawImage(ximageBackground, labelValueX - 50, labelValueY - 9, 75, 75);
            }
            else if (imageBoxRound.Equals("roundgreen.png"))
            {
                XImage ximageBackground;
                ximageBackground = XImage.FromGdiPlusImage(Properties.Resources.roundgreen);
                gfx.DrawImage(ximageBackground, labelValueX - 50, labelValueY - 9, 75, 75);
            }
            else if (imageBoxRound.Equals("roundorange.png"))
            {
                XImage ximageBackground;
                ximageBackground = XImage.FromGdiPlusImage(Properties.Resources.roundorange);
                gfx.DrawImage(ximageBackground, labelValueX - 50, labelValueY - 9, 75, 75);
            }

            /* else if (imageBoxRound.Equals("roundred.png"))
             * {
             *   XImage ximageBackground;
             *   ximageBackground = XImage.FromGdiPlusImage(Properties.Resources.roundred);
             *   gfx.DrawImage(ximageBackground, labelValueX - 50, labelValueY - 9, 75, 75);
             * } */

            XImage ximage;

            if (File.Exists(obj.studentImagePath))
            {
                ximage = XImage.FromFile(obj.studentImagePath);
            }
            else
            {
                ximage = XImage.FromGdiPlusImage(Properties.Resources.android_contact);
            }
            gfx.DrawImage(ximage, labelValueX - 45, labelValueY - 3, 62, 60);

            // name
            XFont fontNameLabel = new XFont(lableFontStatic, fontStaticSize, XFontStyle.BoldItalic);

            if (color.Equals("orange"))
            {
                gfx.DrawString("Name :", fontNameLabel, XBrushes.DarkOrange, labelValueX + constantGapPictureAndWords, labelValueY);
            }
            else if (color.Equals("blue"))
            {
                gfx.DrawString("Name :", fontNameLabel, XBrushes.Blue, labelValueX + constantGapPictureAndWords, labelValueY);
            }
            else if (color.Equals("red"))
            {
                gfx.DrawString("Name :", fontNameLabel, XBrushes.DarkRed, labelValueX + constantGapPictureAndWords, labelValueY);
            }
            else if (color.Equals("green"))
            {
                gfx.DrawString("Name :", fontNameLabel, XBrushes.Green, labelValueX + constantGapPictureAndWords, labelValueY);
            }

            XFont fontNameString = new XFont(lableFontDynamic, fontDynamicSize, XFontStyle.Bold);

            gfx.DrawString(obj.fullName, fontNameString, XBrushes.Black, labelValueX + constantGapPictureAndWords, labelValueY + 8);

            // DOB
            XFont fontDOBLabel = new XFont(lableFontStatic, fontStaticSize, XFontStyle.BoldItalic);

            if (color.Equals("orange"))
            {
                gfx.DrawString("Date Of Birth :", fontNameLabel, XBrushes.DarkOrange, labelValueX + constantGapPictureAndWords, labelValueY + 18);
            }
            else if (color.Equals("red"))
            {
                gfx.DrawString("Date Of Birth :", fontNameLabel, XBrushes.DarkRed, labelValueX + constantGapPictureAndWords, labelValueY + 18);
            }
            else if (color.Equals("green"))
            {
                gfx.DrawString("Date Of Birth :", fontNameLabel, XBrushes.Green, labelValueX + constantGapPictureAndWords, labelValueY + 18);
            }
            else
            {
                gfx.DrawString("Date Of Birth :", fontNameLabel, XBrushes.Blue, labelValueX + constantGapPictureAndWords, labelValueY + 18);
            }



            XFont fontDOBString = new XFont(lableFontDynamic, fontDynamicSize, XFontStyle.Bold);

            gfx.DrawString(obj.DOB, fontDOBString, XBrushes.Black, labelValueX + constantGapPictureAndWords, labelValueY + 28);


            // National Id
            XFont fontNationalIdLabel = new XFont(lableFontStatic, fontStaticSize, XFontStyle.BoldItalic);

            if (color.Equals("orange"))
            {
                gfx.DrawString("SRN :", fontNameLabel, XBrushes.DarkOrange, labelValueX + constantGapPictureAndWords, labelValueY + 38);
            }
            else if (color.Equals("red"))
            {
                gfx.DrawString("SRN :", fontNameLabel, XBrushes.DarkRed, labelValueX + constantGapPictureAndWords, labelValueY + 38);
            }
            else if (color.Equals("green"))
            {
                gfx.DrawString("SRN :", fontNameLabel, XBrushes.Green, labelValueX + constantGapPictureAndWords, labelValueY + 38);
            }
            else
            {
                gfx.DrawString("SRN :", fontNameLabel, XBrushes.Blue, labelValueX + constantGapPictureAndWords, labelValueY + 38);
            }


            XFont fontNationalIdString = new XFont(lableFontDynamic, fontDynamicSize, XFontStyle.Bold);

            gfx.DrawString(obj.nationalId, fontNationalIdString, XBrushes.Black, labelValueX + constantGapPictureAndWords, labelValueY + 48);
        }
예제 #3
0
        private static void createTableRow(XGraphics gfx, Teacher teacher)
        {
            XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
            XBrush          brush   = XBrushes.Black;
            XStringFormat   format  = new XStringFormat();

            format.LineAlignment = XLineAlignment.Center;

            XPen   xpen   = new XPen(XColors.Black, 0.5);
            XBrush xbrush = XBrushes.Bisque;

            XRect rect;
            XFont font;

            int currX = X_START - 30;

            string ordinalNum = ROW_COUNTER.ToString() + ".";

            rect             = new XRect(currX, CURR_Y, 28, ROW_HEIGHT);
            font             = new XFont("Arial", 10, XFontStyle.Regular, options);
            format.Alignment = XStringAlignment.Far;
            //gfx.DrawRectangle(xpen, xbrush, rect);
            gfx.DrawString(ordinalNum, font, brush, rect, format);

            currX = X_START;

            string teacherLastName = teacher.getLastName();

            rect             = new XRect(currX, CURR_Y, COL_WIDTH[0], ROW_HEIGHT);
            font             = new XFont("Arial", 10, XFontStyle.Regular, options);
            format.Alignment = XStringAlignment.Near;
            //gfx.DrawRectangle(xpen, xbrush, rect);
            gfx.DrawString(teacherLastName, font, brush, rect, format);

            currX += COL_WIDTH[0] + COL_GAP;

            string teacherName = teacher.getName();

            rect = new XRect(currX, CURR_Y, COL_WIDTH[1], ROW_HEIGHT);
            //gfx.DrawRectangle(xpen, xbrush, rect);
            gfx.DrawString(teacherName, font, brush, rect, format);

            currX += COL_WIDTH[1] + COL_GAP;

            string teacherTitle = teacher.getTitle();

            rect = new XRect(currX, CURR_Y, COL_WIDTH[2], ROW_HEIGHT);
            //gfx.DrawRectangle(xpen, xbrush, rect);
            gfx.DrawString(teacherTitle, font, brush, rect, format);

            currX += COL_WIDTH[2] + COL_GAP;

            string teacherEduRank = teacher.getEduRank();

            rect = new XRect(currX, CURR_Y, COL_WIDTH[3], ROW_HEIGHT);
            //gfx.DrawRectangle(xpen, xbrush, rect);
            gfx.DrawString(teacherEduRank, font, brush, rect, format);

            currX += COL_WIDTH[3] + COL_GAP;

            string teacherExtID = teacher.ExtID;

            rect = new XRect(currX, CURR_Y, COL_WIDTH[4], ROW_HEIGHT);
            //gfx.DrawRectangle(xpen, xbrush, rect);
            gfx.DrawString(teacherExtID, font, brush, rect, format);

            gfx.DrawLine(xpen, X_START - 20, CURR_Y + ROW_HEIGHT + 2, X_START + 475, CURR_Y + ROW_HEIGHT + 2);

            CURR_Y += ROW_HEIGHT + 4;
        }
예제 #4
0
        public String invoicereport(int transaction_Id)
        {
            String strPathAndQuery = HttpContext.Current.Request.Url.PathAndQuery;
            String strUrl          = HttpContext.Current.Request.Url.AbsoluteUri.Replace(strPathAndQuery, "/");
            //string path ="E:\\Source";

            String path = getinvoicepaymentlink("GETinvoicereportdetails12");

            var newUploadPath = path;

            PdfDocument document = new PdfSharp.Pdf.PdfDocument();


            List <FavouriteModel> invoicedetails = getinvoicereport(transaction_Id);


            //document.Info.Title = "Study Certificate";
            PdfPage page = document.AddPage();

            page.Size = PageSize.A4;

            XGraphics      gfx = XGraphics.FromPdfPage(page);
            XTextFormatter tf  = new XTextFormatter(gfx);
            // var x1 = 40;
            XFont fonthead        = new XFont("Verdana", 13, XFontStyle.Bold);
            XFont fontbody        = new XFont("Times New Roman", 9, XFontStyle.Regular);
            XFont fontbodybold    = new XFont("Times New Roman", 11, XFontStyle.Bold);
            XFont subjectdata     = new XFont("Times New Roman", 10, XFontStyle.Regular);
            XFont subjectheader   = new XFont("Times New Roman", 10, XFontStyle.Bold);
            XFont subjectheader1  = new XFont("Times New Roman", 9, XFontStyle.Bold);
            XFont fontbodybold1   = new XFont("Times New Roman", 11, XFontStyle.Bold);
            XFont fontbodybold12  = new XFont("Times New Roman", 15, XFontStyle.Bold);
            XFont fontbodybold121 = new XFont("Times New Roman", 28, XFontStyle.Bold);
            XFont fontbodybold123 = new XFont("Times New Roman", 15, XFontStyle.Bold);
            XFont fontbodybold2   = new XFont("Times New Roman", 9, XFontStyle.Bold);
            XFont fontbodybold3   = new XFont("Times New Roman", 12, XFontStyle.Regular);


            var issdate = Convert.ToDateTime(invoicedetails[0].transaction_Date);
            var dat2    = issdate.ToString("dd/MM/yyyy");
            //school logo
            //getinvoicepaymentlink("GETinvoicereportdetails12");
            string uriPath = getinvoicepaymentlink("GETinvoicereportdetails");

            try
            {
                XImage image = XImage.FromFile(uriPath);
                gfx.DrawImage(image, 50, 20, 80, 80);
                if (!File.Exists(uriPath))
                {
                    throw new FileNotFoundException();
                }
            }
            catch (FileNotFoundException e)
            {
                // gfx.DrawImage(image, 260, x1, 80, 80);
            }


            int y = 0;

            y = y + 30;

            gfx.DrawString("INVOICE ", fontbodybold121, XBrushes.Black,
                           new XRect(450, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            y = y + 70;
            gfx.DrawString(invoicedetails[0].customerName.ToString(), fontbodybold123, XBrushes.Black,
                           new XRect(50, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            y = y + 18;
            gfx.DrawString("Mobile No:", fontbodybold3, XBrushes.Black,
                           new XRect(50, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            gfx.DrawString("" + invoicedetails[0].mobile_No.ToString(), fontbodybold3, XBrushes.Black,
                           new XRect(109, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            y = y + 20;
            gfx.DrawString("Bill To", fontbodybold1, XBrushes.Black,
                           new XRect(50, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            y = y + 15;
            gfx.DrawString("Email:", fontbodybold3, XBrushes.Black,
                           new XRect(50, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            gfx.DrawString("" + invoicedetails[0].email_id.ToString(), fontbodybold3, XBrushes.Black,
                           new XRect(95, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            y = y + 50;
            gfx.DrawRectangle(XBrushes.LightGray, new XRect(50, y, 500, y - 100));
            gfx.DrawString("Invoice Number ", fontbodybold1, XBrushes.Black,
                           new XRect(80, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            gfx.DrawString(" " + invoicedetails[0].transaction_Id.ToString(), subjectdata, XBrushes.Black,
                           new XRect(160, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            y = y + 20;
            gfx.DrawString("Date", fontbodybold1, XBrushes.Black,
                           new XRect(80, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            gfx.DrawString(dat2, subjectdata, XBrushes.Black,
                           new XRect(160, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            y = y + 20;
            gfx.DrawString("Payment Terms", fontbodybold1, XBrushes.Black,
                           new XRect(80, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            gfx.DrawString("Due On receipt", subjectdata, XBrushes.Black,
                           new XRect(160, y + 9, page.Width, page.Height),
                           XStringFormat.TopLeft);
            y = y + 20;
            gfx.DrawString("Due Date", fontbodybold1, XBrushes.Black,
                           new XRect(80, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            gfx.DrawString(dat2, subjectdata, XBrushes.Black,
                           new XRect(160, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            y = y + 20;

            y = y + 40;
            gfx.DrawString("DESCRIPTION", fontbodybold1, XBrushes.Black,
                           new XRect(50, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);

            gfx.DrawString("PRICE", fontbodybold1, XBrushes.Black,
                           new XRect(180, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);

            gfx.DrawString("DURATION", fontbodybold1, XBrushes.Black,
                           new XRect(320, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);


            gfx.DrawString("TOTAL", fontbodybold1, XBrushes.Black,
                           new XRect(450, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);

            y = y + 20;
            gfx.DrawLine(XPens.Gray, 50, y, 510, y);
            y = y + 10;
            gfx.DrawString(invoicedetails[0].category.ToString(), subjectdata, XBrushes.Black,
                           new XRect(50, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            gfx.DrawString(invoicedetails[0].transaction_Amount.ToString(), subjectdata, XBrushes.Black,
                           new XRect(455, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            gfx.DrawString("6 Months", subjectdata, XBrushes.Black,
                           new XRect(325, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            gfx.DrawString(invoicedetails[0].transaction_Amount.ToString(), subjectdata, XBrushes.Black,
                           new XRect(175, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            y = y + 30;
            gfx.DrawLine(XPens.Gray, 50, y, 510, y);
            //  y = y + 50;
            //  gfx.DrawString("Thank you", fontbodybold3, XBrushes.Black,
            //new XRect(50, y + 7, page.Width, page.Height),
            //XStringFormat.TopLeft);
            //       y = y + 15;
            //       gfx.DrawString("It is a long established fact that a reader will be distracted by the readable ", fontbodybold3, XBrushes.Black,
            //  new XRect(50, y + 7, page.Width, page.Height),
            //  XStringFormat.TopLeft);
            //       y = y + 15;
            //       gfx.DrawString("content of a page when looking at its layout.", fontbodybold3, XBrushes.Black,
            //new XRect(50, y + 7, page.Width, page.Height),
            //XStringFormat.TopLeft);
            try
            {
                string filename = "/InvoiceReport" + invoicedetails[0].transaction_Id + ".pdf";
                document.Save(newUploadPath + filename);
                if (!File.Exists(newUploadPath + filename))
                {
                    throw new System.IO.DirectoryNotFoundException();
                }
                Process process = new Process();
                process.StartInfo.UseShellExecute = true;
                process.StartInfo.FileName        = (newUploadPath + filename);
                //process.Start();
                return(newUploadPath + filename);
            }
            catch (System.IO.DirectoryNotFoundException e)
            {
                path = path.Replace("\\api\\", "\\Group\\");
                Directory.CreateDirectory(path);
                string filename2 = "/InvoiceReport.pdf";
                document.Save(path + filename2);
                Process process = new Process();
                process.StartInfo.UseShellExecute = true;
                process.StartInfo.FileName        = (path + filename2);
                //  process.Start();
                return(newUploadPath + filename2);
            }
        }
예제 #5
0
        public void printBill()
        {
            try
            {
                int    i         = 0;
                int    yPoint    = 0;
                string TenMonAn  = null;
                string SoLuong   = null;
                string DonGia    = null;
                string ThanhTien = null;
                string MaHoaDon  = null;
                if (idBanAn != null)
                {
                    ThanhTien = Double.Parse(HOADONBAN.Ins.getTongTienTheoBanAn(idBanAn).Rows[0][0].ToString()).ToString("#,##0");
                }

                // connetionString = "Data Source=THANHNGUYEN;Initial Catalog=QLKH;User ID=sa;Password=1334567701";
                // sql = "select TenMonAn,SoLuong,DonGia from TestHoaDon";
                // connection = new SqlConnection(connetionString);
                // connection.Open();
                // command = new SqlCommand(sql, connection);
                // adapter.SelectCommand = command;
                // adapter.Fill(ds);
                // connection.Close();
                DataTable   ds      = BLL.MONAN.Ins.getListMonTheoId(idBanAn);
                string      NgayBan = ds.Rows[0].ItemArray[4].ToString();
                PdfDocument pdf     = new PdfDocument();
                pdf.Info.Title = "Database to PDF";
                PdfPage   pdfPage = pdf.AddPage();
                XGraphics graph   = XGraphics.FromPdfPage(pdfPage);
                XFont     font    = new XFont("Verdana", 10, XFontStyle.Regular);
                XFont     Font_1  = new XFont("Verdana", 30, XFontStyle.Regular);
                yPoint = yPoint + 100;
                graph.DrawString("Hóa Đơn Bán", Font_1, XBrushes.Black, new XRect(40, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
                yPoint = yPoint + 50;
                graph.DrawString("khu phố 6 phường Linh Trung ", font, XBrushes.Black, new XRect(40, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
                yPoint = yPoint + 20;
                graph.DrawString("--------------------------------------------------------", font, XBrushes.Black, new XRect(40, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
                yPoint = yPoint + 20;
                graph.DrawString("Mã Hóa Đơn", font, XBrushes.Black, new XRect(40, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
                graph.DrawString(idBanAn, font, XBrushes.Black, new XRect(120, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
                yPoint = yPoint + 20;
                graph.DrawString("Ngày Bán", font, XBrushes.Black, new XRect(40, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
                graph.DrawString(NgayBan, font, XBrushes.Black, new XRect(120, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
                yPoint = yPoint + 20;
                graph.DrawString("--------------------------------------------------------", font, XBrushes.Black, new XRect(40, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
                yPoint = yPoint + 20;
                graph.DrawString("Tên Món Ăn", font, XBrushes.Black, new XRect(40, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
                graph.DrawString("Số Lượng", font, XBrushes.Black, new XRect(160, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
                graph.DrawString("Đơn Giá", font, XBrushes.Black, new XRect(250, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
                yPoint = yPoint + 20;
                for (i = 0; i <= ds.Rows.Count - 1; i++)
                {
                    TenMonAn = ds.Rows[i].ItemArray[1].ToString();
                    SoLuong  = ds.Rows[i].ItemArray[3].ToString();
                    DonGia   = ds.Rows[i].ItemArray[2].ToString();

                    graph.DrawString(TenMonAn, font, XBrushes.Black, new XRect(40, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);

                    graph.DrawString(SoLuong, font, XBrushes.Black, new XRect(160, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);

                    graph.DrawString(DonGia, font, XBrushes.Black, new XRect(250, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);

                    yPoint = yPoint + 20;
                }
                graph.DrawString("--------------------------------------------------------", font, XBrushes.Black, new XRect(40, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
                yPoint = yPoint + 20;
                graph.DrawString("Tổng Tiền", font, XBrushes.Black, new XRect(40, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);

                graph.DrawString(ThanhTien, font, XBrushes.Black, new XRect(250, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);

                string pdfFilename = "dbtopdf.pdf";
                pdf.Save(pdfFilename);
                Process.Start(pdfFilename);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #6
0
        public void Index(string layout)
        {
            String        text    = null;
            String        name    = null;
            String        company = null;
            ExpoesContext expo    = new ExpoesContext();
            bool          exC     = expo.Companies.Any(p => p.Email == User.Identity.Name);

            if (exC == true)
            {
                var Usr = expo.Companies.Single(p => p.Email == User.Identity.Name);
                text    = "Wystawca:" + User.Identity.Name;
                company = Usr.CompanyName;
            }
            bool exU = expo.Users.Any(p => p.Email == User.Identity.Name);

            if (exU == true)
            {
                var Usr = expo.Users.Single(p => p.Email == User.Identity.Name);
                text    = "Uczestnik:" + User.Identity.Name;
                company = "";
                name    = Usr.ForName + " " + Usr.SurName;
            }
            string      filename   = String.Format("{0}_tempfile.pdf", Guid.NewGuid().ToString("D").ToUpper());
            PdfDocument s_document = new PdfDocument();

            s_document.Info.Title    = "Your QRCode";
            s_document.Info.Author   = "ExpoApp";
            s_document.Info.Subject  = "Grenerating your QRCODE";
            s_document.Info.Keywords = "QRcode";
            PdfPage   page = s_document.AddPage();
            XGraphics gfx  = XGraphics.FromPdfPage(page);

            // GET: PDF
            QRCodeGenerator.ECCLevel eccLevel = (QRCodeGenerator.ECCLevel) 1;
            using (QRCodeGenerator qrGenerator = new QRCodeGenerator())
            {
                using (QRCodeData qrCodeData = qrGenerator.CreateQrCode(text, eccLevel))
                {
                    using (QRCode qrCode = new QRCode(qrCodeData))
                    {
                        Bitmap bitmap = new Bitmap(qrCode.GetGraphic(20, Color.Black, Color.White, true));
                        //pdf
                        //BitmapSource bitmapSource =
                        //  System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                        //    bitmap.GetHbitmap(),
                        //      IntPtr.Zero,
                        //      Int32Rect.Empty,
                        //      BitmapSizeOptions.FromEmptyOptions());
                        //Image i=Image.
                        XImage image   = XImage.FromGdiPlusImage((Image)bitmap);
                        XFont  font    = new XFont("Times New Roman", 20, XFontStyle.Bold);
                        XImage makieta = XImage.FromFile(HttpContext.Server.MapPath("~/Images/Expo/pdf/" + layout));
                        // Left position in point
                        gfx.DrawImage(makieta, 0, 0, page.Width, page.Height);
                        gfx.DrawImage(image, 120, 215, 75, 75);
                        gfx.DrawImage(image, 120, 640, 75, 75);
                        //gfx.DrawString(, font, XBrushes.Black,
                        // new XRect(0, 0, page.Width, page.Height),
                        //XStringFormats.Center);
                        gfx.DrawString(name, font, XBrushes.Black, new XRect(30, 175, 250, 20),
                                       XStringFormats.Center);
                        gfx.DrawString(company, font, XBrushes.Black, new XRect(30, 195, 250, 20),
                                       XStringFormats.Center);
                        gfx.DrawString(name, font, XBrushes.Black, new XRect(30, 600, 250, 20),
                                       XStringFormats.Center);
                        gfx.DrawString(company, font, XBrushes.Black, new XRect(30, 620, 250, 20),
                                       XStringFormats.Center);
                    }
                }
            }
            s_document.Save(HttpContext.Server.MapPath("~/temp/") + filename);
            Response.ContentType = "application/pdf";
            Response.TransmitFile(HttpContext.Server.MapPath("~/temp/") + filename);
            // ...and start a viewer
            //return Redirect("E:/temp/" + filename);
        }
예제 #7
0
    private void PrintVatAnalysis()
    {
        string   strfd = txtFromDate.Text;
        DateTime dat   = new DateTime();

        string[] strDate = strfd.Split('-');
        string   date    = strDate[0];
        string   Month   = strDate[1];
        string   Year    = strDate[2];

        strfd = Year + '-' + Month + '-' + date;
        string strto = txtToDate.Text;

        strDate = strto.Split('-');
        date    = strDate[0];
        Month   = strDate[1];
        Year    = strDate[2];
        strto   = Year + '-' + Month + '-' + date;


        dt = new Facade().GetVatAnalysis(strfd, strto); //dbHandler.GetDataTable(sql);
        //if (dt.Rows[0]["vat0"].ToString() == "")
        //    Label6.Text = "0.00";
        //else
        //    Label6.Text = dt.Rows[0]["vat0"].ToString();
        //if (dt.Rows[0]["vat6"].ToString() == "")
        //    Label7.Text = "0.00";
        //else
        //    Label7.Text = dt.Rows[0]["vat6"].ToString();
        //if (dt.Rows[0]["vat19"].ToString() == "")
        //    Label8.Text = "0.00";
        //else
        //    Label8.Text = dt.Rows[0]["vat19"].ToString();
        //if (dt.Rows[0]["price0"].ToString() == "")
        //    Label11.Text = "0.00";
        //else
        //    Label11.Text = dt.Rows[0]["price0"].ToString();
        //if (dt.Rows[0]["price6"].ToString() == "")
        //    Label12.Text = "0.00";
        //else
        //    Label12.Text = dt.Rows[0]["price6"].ToString();
        //if (dt.Rows[0]["price19"].ToString() == "")
        //    Label13.Text = "0.00";
        //else
        //    Label13.Text = dt.Rows[0]["price19"].ToString();


        // Create a new PDF document
        PdfDocument document = new PdfDocument();

        // Create an empty page
        PdfPage page = document.AddPage();

        // Get an XGraphics object for drawing
        XGraphics gfx = XGraphics.FromPdfPage(page);
        int       x = 80, y = 110;
        // Create a font
        XFont          font_hdr     = new XFont("Arial", 20, XFontStyle.Regular);
        XFont          font         = new XFont("Arial", 13, XFontStyle.Regular);
        XFont          font_small   = new XFont("Arial", 12, XFontStyle.Regular);
        XFont          font_smaller = new XFont("Arial", 10, XFontStyle.Regular);
        XRect          rec_hdr      = new XRect(180, 50, 200, 100);
        XRect          rec          = new XRect(-40, 85, 400, 50);
        XRect          rec_vb       = new XRect(x + 120, y, 110, 100);
        XRect          rec_va       = new XRect(x + 300, y, 150, 100);
        XRect          rec_vf       = new XRect(x, y + 25, 110, 100);
        XRect          rec_v0       = new XRect(x + 120, y + 25, 100, 100);
        XRect          rec_p0       = new XRect(x + 320, y + 25, 100, 100);
        XRect          rec_vs       = new XRect(x, y + 50, 110, 100);
        XRect          rec_v6       = new XRect(x + 120, y + 50, 100, 100);
        XRect          rec_p6       = new XRect(x + 320, y + 50, 100, 100);
        XRect          rec_vn       = new XRect(x, y + 75, 110, 100);
        XRect          rec_v19      = new XRect(x + 120, y + 75, 100, 100);
        XRect          rec_p19      = new XRect(x + 320, y + 75, 100, 100);
        XTextFormatter tf           = new XTextFormatter(gfx);
        XTextFormatter tf1          = new XTextFormatter(gfx);
        XTextFormatter tf2          = new XTextFormatter(gfx);

        tf.Alignment  = XParagraphAlignment.Right;
        tf1.Alignment = XParagraphAlignment.Center;
        tf2.Alignment = XParagraphAlignment.Left;
        // Draw the text
        //gfx.DrawString("Hello, World!", font, XBrushes.Black,new XRect(0, 0, page.Width, page.Height),XStringFormat.Center);
        gfx.DrawRectangle(new XSolidBrush(XColor.FromArgb(140, 204, 204, 204)), x - 30, y - 5, 500, 25);
        gfx.DrawRectangle(new XSolidBrush(XColor.FromArgb(80, 204, 204, 204)), x - 30, y + 20, 500, 75);
        tf1.DrawString("VAT Analysis", font_hdr, XBrushes.Black, rec_hdr);
        tf1.DrawString("Date Range: " + txtFromDate.Text + " to: " + txtToDate.Text + "", font, XBrushes.Black, rec);
        tf1.DrawString("VAT Basis", font, XBrushes.Black, rec_vb);
        tf1.DrawString("VAT Amount", font, XBrushes.Black, rec_va);
        tf2.DrawString("VAT free", font_small, XBrushes.Black, rec_vf);
        tf2.DrawString("VAT 6%", font_small, XBrushes.Black, rec_vs);
        tf2.DrawString("VAT 19%", font_small, XBrushes.Black, rec_vn);
        gfx.DrawString("€".PadRight(6), font_small, XBrushes.Black, rec_v0, XStringFormat.TopLeft);
        tf.DrawString(dt.Rows[0]["vat0"].ToString(), font_small, XBrushes.Black, rec_v0);
        gfx.DrawString("€".PadRight(6), font_small, XBrushes.Black, rec_v6, XStringFormat.TopLeft);
        tf.DrawString(dt.Rows[0]["vat6"].ToString(), font_small, XBrushes.Black, rec_v6);
        gfx.DrawString("€".PadRight(6), font_small, XBrushes.Black, rec_v19, XStringFormat.TopLeft);
        tf.DrawString(dt.Rows[0]["vat19"].ToString(), font_small, XBrushes.Black, rec_v19);
        //gfx.DrawString(Label11.Text, font, XBrushes.Black, x, y + 25, XStringFormat.TopLeft);
        gfx.DrawString("€".PadRight(6), font_small, XBrushes.Black, rec_p0, XStringFormat.TopLeft);
        tf.DrawString(dt.Rows[0]["price0"].ToString(), font_small, XBrushes.Black, rec_p0);
        gfx.DrawString("€".PadRight(6), font_small, XBrushes.Black, rec_p6, XStringFormat.TopLeft);
        tf.DrawString(dt.Rows[0]["price6"].ToString(), font_small, XBrushes.Black, rec_p6);
        gfx.DrawString("€".PadRight(6), font_small, XBrushes.Black, rec_p19, XStringFormat.TopLeft);
        tf.DrawString(dt.Rows[0]["price19"].ToString(), font_small, XBrushes.Black, rec_p19);
        gfx.DrawString("Page 1 of 1.", font_smaller, XBrushes.Black, 30, 780);
        // Save the document...
        //string filename = "HelloWorld.pdf";
        //document.Save(filename);
        // ...and start a viewer.
        MemoryStream stream = new MemoryStream();

        document.Save(stream, false);
        Response.Clear();
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-length", stream.Length.ToString());
        Response.BinaryWrite(stream.ToArray());
        Response.Flush();
        stream.Close();
        Response.End();
    }
        protected void btnExportPdf_Click(object sender, EventArgs e)
        {
            // Populate report
            PopulateGrid();

            var documentDirectory = String.Format("{0}\\Temp\\", System.AppDomain.CurrentDomain.BaseDirectory);
            var logoDirectory     = String.Format("{0}\\img\\", System.AppDomain.CurrentDomain.BaseDirectory);

            string destName = string.Format("ReportOutstandingVisit_{0}.pdf", DateTime.Now.ToString("yyyyMMddhhmmsss"));
            string destFile = string.Format("{0}{1}", documentDirectory, destName);

            string logoName = string.Format("SIAPS_USAID_Horiz.jpg");
            string logoFile = string.Format("{0}{1}", logoDirectory, logoName);

            string fontFile = string.Format("{0}\\arial.ttf", System.AppDomain.CurrentDomain.BaseDirectory);

            var linePosition   = 60;
            var columnPosition = 30;

            // Create document
            PdfDocument pdfDoc = new PdfDocument();

            // Create a new page
            PdfPage page = pdfDoc.AddPage();

            page.Orientation = PageOrientation.Landscape;

            // Get an XGraphics object for drawing
            XGraphics      gfx = XGraphics.FromPdfPage(page);
            XTextFormatter tf  = new XTextFormatter(gfx);
            XPen           pen = new XPen(XColor.FromArgb(255, 0, 0));

            // Logo
            XImage image = XImage.FromFile(logoFile);

            gfx.DrawImage(image, 10, 10);

            // Create a new font
            Uri fontUri = new Uri(fontFile);

            try
            {
                XPrivateFontCollection.Global.Add(fontUri, "#Arial");
            }
            catch
            {
            }

            XFont fontb = new XFont("Calibri", 10, XFontStyle.Bold | XFontStyle.Underline);
            XFont fontr = new XFont("Calibri", 10, XFontStyle.Regular);

            // Write header
            pdfDoc.Info.Title = "Outstanding Visit Report for " + DateTime.Now.ToString("yyyy-MM-dd HH:mm");
            gfx.DrawString("Outstanding Visit Report for " + DateTime.Now.ToString("yyyy-MM-dd HH:mm"), fontb, XBrushes.Black, new XRect(columnPosition, linePosition, page.Width.Point, 20), XStringFormats.TopLeft);

            // Write filter
            linePosition += 24;
            gfx.DrawString("Range From : " + txtSearchFrom.Value, fontr, XBrushes.Black, new XRect(columnPosition, linePosition, page.Width.Point, 20), XStringFormats.TopLeft);
            linePosition += 24;
            gfx.DrawString("Range To : " + txtSearchTo.Value, fontr, XBrushes.Black, new XRect(columnPosition, linePosition, page.Width.Point, 20), XStringFormats.TopLeft);

            // Write content
            var pageCount = 1;
            var rowCount  = 0;
            var cellCount = 0;

            ArrayList headerArray = new ArrayList();
            ArrayList widthArray  = new ArrayList();

            foreach (TableRow row in dt_basic.Rows)
            {
                rowCount += 1;
                cellCount = 0;

                linePosition  += 24;
                columnPosition = 30;

                if (linePosition >= 480)
                {
                    pageCount += 1;

                    page             = pdfDoc.AddPage();
                    page.Orientation = PageOrientation.Landscape;

                    linePosition = 60;

                    gfx = XGraphics.FromPdfPage(page);
                    tf  = new XTextFormatter(gfx);

                    // Logo
                    gfx.DrawImage(image, 10, 10);

                    gfx.DrawString("Outstanding Visit Report (Page " + pageCount.ToString() + ")", fontb, XBrushes.Black, new XRect(columnPosition, linePosition, page.Width.Point, 20), XStringFormats.TopLeft);

                    linePosition += 24;

                    /// rewrite column headers
                    foreach (var header in headerArray)
                    {
                        cellCount += 1;
                        var width = Convert.ToInt32(widthArray[cellCount - 1]);

                        gfx.DrawString(header.ToString(), fontb, XBrushes.Black, new XRect(columnPosition, linePosition, width, 20), XStringFormats.TopLeft);
                        columnPosition += width;
                    }

                    columnPosition = 30;
                    linePosition  += 24;
                    cellCount      = 0;
                }

                foreach (TableCell cell in row.Cells)
                {
                    int[] ignore = { };

                    if (!ignore.Contains(cellCount))
                    {
                        cellCount += 1;

                        if (rowCount == 1)
                        {
                            widthArray.Add((int)cell.Width.Value * 8);
                            headerArray.Add(cell.Text);

                            gfx.DrawString(cell.Text, fontb, XBrushes.Black, new XRect(columnPosition, linePosition, cell.Width.Value * 8, 20), XStringFormats.TopLeft);
                            columnPosition += (int)cell.Width.Value * 8;
                        }
                        else
                        {
                            var width = Convert.ToInt32(widthArray[cellCount - 1]);

                            tf.DrawString(cell.Text, fontr, XBrushes.Black, new XRect(columnPosition, linePosition, width, 20), XStringFormats.TopLeft);
                            columnPosition += width;
                        }
                    }
                }
            }

            pdfDoc.Save(destFile);

            Response.Clear();
            Response.Buffer          = true;
            Response.ContentEncoding = Encoding.UTF8;
            Response.ContentType     = "application/pdf";
            Response.AddHeader("content-disposition", String.Format("attachment;filename={0}", destName));
            Response.Charset     = "";
            this.EnableViewState = false;

            Response.WriteFile(destFile);
            Response.End();
        }
예제 #9
0
        public override void RenderPage(XGraphics gfx)
        {
            //base.RenderPage(gfx);

            XPoint[] origins = new XPoint[]
            {
                new XPoint(100, 200), new XPoint(300, 200),
                new XPoint(100, 400), new XPoint(300, 400),
                new XPoint(100, 600), new XPoint(350, 600),
            };

            XPoint         origin;
            XGraphicsState state;
            float          length = 100;

            // Not transformed
            origin = origins[0];
            DrawAxes(gfx, XPens.Black, origin, length);
            gfx.DrawString(this.properties.Font1.Text, this.properties.Font1.Font, this.properties.Font1.Brush, origin);

            // Translation
            state  = gfx.Save();
            origin = origins[1];
            DrawAxes(gfx, XPens.Black, origin, length);
            gfx.TranslateTransform(20, -30);
            DrawAxes(gfx, XPens.DarkGray, origin, length);
            gfx.DrawString(this.properties.Font1.Text, this.properties.Font1.Font, this.properties.Font1.Brush, origin);
            gfx.Restore(state);

#if true
            // Scaling
            state  = gfx.Save();
            origin = origins[2];
            DrawAxes(gfx, XPens.Black, origin, length);
            gfx.TranslateTransform(origin.X, origin.Y);
            gfx.ScaleTransform(1.3, 1.5);
            DrawAxes(gfx, XPens.DarkGray, new XPoint(), length);
            gfx.DrawString(this.properties.Font1.Text, this.properties.Font1.Font, this.properties.Font1.Brush, 0, 0);
            gfx.Restore(state);

            // Rotation
            state  = gfx.Save();
            origin = origins[3];
            DrawAxes(gfx, XPens.Black, origin, length);
            gfx.TranslateTransform(origin.X, origin.Y);
            gfx.RotateTransform(-45);
            DrawAxes(gfx, XPens.DarkGray, new XPoint(), length);
            gfx.DrawString(this.properties.Font1.Text, this.properties.Font1.Font, this.properties.Font1.Brush, 0, 0);
            gfx.Restore(state);

            // Skewing (or shearing)
            state  = gfx.Save();
            origin = origins[4];
            DrawAxes(gfx, XPens.Black, origin, length);
            gfx.TranslateTransform(origin.X, origin.Y);
            gfx.MultiplyTransform(new Matrix(1, -0.3f, -0.4f, 1, 0, 0));
            DrawAxes(gfx, XPens.DarkGray, new XPoint(), length);
            gfx.DrawString(this.properties.Font1.Text, this.properties.Font1.Font, this.properties.Font1.Brush, 0, 0);
            gfx.Restore(state);

            // Reflection
            state  = gfx.Save();
            origin = origins[5];
            DrawAxes(gfx, XPens.Black, origin, length);
            gfx.TranslateTransform(origin.X, origin.Y);
            gfx.MultiplyTransform(new Matrix(-1, 0, 0, -1, 0, 0));
            DrawAxes(gfx, XPens.DarkGray, new XPoint(), length);
            gfx.DrawString(this.properties.Font1.Text, this.properties.Font1.Font, this.properties.Font1.Brush, 0, 0);
            gfx.Restore(state);
#endif
        }
예제 #10
0
        public void Draw(XGraphics gfx, double mapSF)
        {
            if (_visible)
            {
                TransformsProvider tp        = new TransformsProvider(gfx);
                double             x         = 0.0;
                double             y         = 0.0;
                double             width     = this._intervalSize * mapSF;
                XBrush             fillColor = new XSolidBrush(XColor.FromName(this._fillColorName));
                XFont  font          = new XFont(_fontFamilyName, _fontSize, _fontStyle);
                XBrush fontColor     = new XSolidBrush(XColor.FromName(this._fontColorName));
                XRect  firstInterval = XRect.Empty;
                switch (Anchor)
                {
                case AnchorType.TopLeft:
                    x = tp.CmsToPts(this._x);
                    y = tp.CmsToPts(_y) + font.Height;
                    break;

                case AnchorType.BottomLeft:
                    x = tp.CmsToPts(this._x);
                    y = tp.CmsToPts(_y) - this._height;
                    break;

                case AnchorType.TopRight:
                    x = tp.CmsToPts(this._x) - (width * this._numIntervals) - (font.Size * 1.5) - ((this._unit.Length + 1) * font.Size);
                    y = tp.CmsToPts(_y) + font.Height;
                    break;

                case AnchorType.BottomRight:
                    x = tp.CmsToPts(this._x) - (width * this._numIntervals) - (font.Size * 1.5) - ((this._unit.Length + 1) * font.Size);
                    y = tp.CmsToPts(_y) - this._height;
                    break;

                default:
                    x = tp.CmsToPts(this._x);
                    y = tp.CmsToPts(_y) - this._height;
                    break;
                }
                for (int i = 0; i <= this._numIntervals - 1; i++)
                {
                    if (i == 0)
                    {
                        firstInterval = new XRect(x, y, width, this._height);
                        gfx.DrawRectangle(new XPen(XColors.Black), firstInterval);
                    }
                    else
                    {
                        if (i % 2 == 0)
                        {
                            gfx.DrawRectangle(new XPen(XColors.Black), x + (width * i), y, width, this._height);
                        }
                        else
                        {
                            gfx.DrawRectangle(new XPen(XColors.Black), fillColor, x + (width * i), y, width, this._height);
                        }
                    }
                }
                x = firstInterval.Left;
                y = firstInterval.Top - font.Height;
                for (int i = 1; i <= this._numIntervals; i++)
                {
                    gfx.DrawString((this._intervalSize * i).ToString(), font, fontColor, x + (width * i), y, XStringFormat.TopCenter);
                }
                gfx.DrawString(this._unit, font, fontColor, x + (width * this._numIntervals) + (font.Size * 1.5), y, XStringFormat.TopLeft);
            }
        }
예제 #11
0
        private void DrawReciept(int position, string amountInWords, XGraphics gfx, TransactionDetail transactionDetail)
        {
            var fontReciept    = new XFont("Times New Roman", 14, XFontStyle.Bold);
            var fontSchoolName = new XFont("Calisto MT", 18, XFontStyle.Bold);
            var font           = new XFont("Times New Roman", 10, XFontStyle.Regular);
            var fontItalic     = new XFont("Times New Roman", 10, XFontStyle.Italic);

            gfx.DrawString("Reciept", fontReciept, XBrushes.Black,
                           new XRect(170, position + 50, 270, position + 50), XStringFormat.Center);
            var fontSchoolAddress = new XFont("Times New Roman", 7, XFontStyle.Regular);

            gfx.DrawString("Reciept", fontReciept, XBrushes.Black,
                           new XRect(170, position + 50, 270, position + 50), XStringFormat.Center);
            gfx.DrawString(position > 0?"Accounts copy":"Student copy", fontSchoolAddress, XBrushes.Black,
                           new XRect(170, position + 60, 270, position + 60), XStringFormat.Center);

            gfx.DrawString(Constants.SchoolName, fontSchoolName, XBrushes.Black,
                           new XRect(330, position + 20, 270, position + 20), XStringFormat.Center);
            gfx.DrawString(Constants.SchoolAddress, fontSchoolAddress, XBrushes.Black,
                           new XRect(330, position + 30, 270, position + 30), XStringFormat.Center);
            gfx.DrawString(Constants.SchoolContactNumbers, fontSchoolAddress, XBrushes.Black,
                           new XRect(330, position + 40, 270, position + 40), XStringFormat.Center);

            gfx.DrawString("Reciept", fontReciept, XBrushes.Black,
                           new XRect(170, position + 50, 270, position + 50), XStringFormat.Center);
            gfx.DrawString("Date:", font, XBrushes.Black,
                           new XRect(60, position + 20, 10, position + 20), XStringFormat.Center);

            gfx.DrawString(DateTime.Now.Date.ToString("D"), font, XBrushes.Black,
                           new XRect(70, position + 20, 110, position + 20), XStringFormat.Center);
            gfx.DrawString("Reciept Number:", font, XBrushes.Black,
                           new XRect(80, position + 30, 10, position + 30), XStringFormat.Center);
            gfx.DrawString(transactionDetail.TransactionDetailsId.ToString(CultureInfo.InvariantCulture), font, XBrushes.Black,
                           new XRect(140, position + 30, 10, position + 30), XStringFormat.Center);

            gfx.DrawString("Student Name:", font, XBrushes.Black,
                           new XRect(80, position + 80, 10, position + 80), XStringFormat.Center);
            gfx.DrawString(transactionDetail.Student.StudentName, fontItalic, XBrushes.Black,
                           new XRect(180, position + 80, 10, position + 80), XStringFormat.Center);

            gfx.DrawString("Mother's Name:", font, XBrushes.Black,
                           new XRect(80, position + 90, 10, position + 90), XStringFormat.Center);
            gfx.DrawString(transactionDetail.Student.MotherName, fontItalic, XBrushes.Black,
                           new XRect(180, position + 90, 10, position + 90), XStringFormat.Center);

            gfx.DrawString("Father's Name:", font, XBrushes.Black,
                           new XRect(80, position + 100, 10, position + 100), XStringFormat.Center);
            gfx.DrawString(transactionDetail.Student.FatherName, fontItalic, XBrushes.Black,
                           new XRect(180, position + 100, 10, position + 100), XStringFormat.Center);


            gfx.DrawString("Class Name:", font, XBrushes.Black,
                           new XRect(80, position + 110, 10, position + 110), XStringFormat.Center);
            gfx.DrawString(transactionDetail.Student.Class1.ClassName, fontItalic, XBrushes.Black,
                           new XRect(180, position + 110, 10, position + 110), XStringFormat.Center);

            gfx.DrawString("Section Name:", font, XBrushes.Black,
                           new XRect(80, position + 120, 10, position + 120), XStringFormat.Center);
            gfx.DrawString(transactionDetail.Student.Section.SectionName, fontItalic, XBrushes.Black,
                           new XRect(180, position + 120, 10, position + 120), XStringFormat.Center);


            gfx.DrawString("Student Address:", font, XBrushes.Black,
                           new XRect(170, position + 80, 270, position + 80), XStringFormat.Center);
            gfx.DrawString(transactionDetail.Student.Address.AdrressLineOne, fontItalic, XBrushes.Black,
                           new XRect(310, position + 80, 270, position + 80), XStringFormat.Center);
            gfx.DrawString(transactionDetail.Student.Address.Village + ".", fontItalic, XBrushes.Black,
                           new XRect(310, position + 90, 270, position + 90), XStringFormat.Center);

            gfx.DrawString(transactionDetail.Student.Address.District + " " + transactionDetail.Student.Address.Pincode, fontItalic, XBrushes.Black,
                           new XRect(310, position + 100, 270, position + 100), XStringFormat.Center);

            gfx.DrawString("Amount:", font, XBrushes.Black,
                           new XRect(60, position + 150, 60, position + 150), XStringFormat.Center);

            gfx.DrawString("In words:", font, XBrushes.Black,
                           new XRect(180, position + 150, 120, position + 150), XStringFormat.Center);

            gfx.DrawString(amountInWords + " Rupees Only", fontItalic, XBrushes.Black, new XRect(320, position + 150, 200, position + 150), XStringFormat.Center);
            gfx.DrawString("paid on " + Convert.ToDateTime(transactionDetail.DatePaid).ToString("D"), font, XBrushes.Black,
                           new XRect(60, position + 160, 120, position + 160), XStringFormat.Center);

            gfx.DrawString(transactionDetail.AmountPaid.ToString(CultureInfo.InvariantCulture), fontItalic, XBrushes.Black,
                           new XRect(90, position + 150, 90, position + 150), XStringFormat.Center);

            gfx.DrawString("Note: This is an auto generated reciept.", font, XBrushes.Black,
                           new XRect(180, position + 180, 180, position + 180), XStringFormat.Center);
            gfx.DrawString("Signature:", font, XBrushes.Black,
                           new XRect(280, position + 180, 280, position + 180), XStringFormat.Center);
            var pen            = new XPen(XColors.Black, 0.1);
            var penBorderLine1 = new XPen(XColors.Black, 0.1);
            var penBorderLine2 = new XPen(XColors.Black, 0.1);

            penBorderLine1.DashStyle = XDashStyle.Dash;
            //gfx.DrawLine(pen, 120, position + 150 - 25, 240, position + 150 - 25);
            //gfx.DrawLine(pen, 120, position + 165 - 25, 240, position + 165 - 25);
            //gfx.DrawLine(pen, 120, position + 180 - 25, 240, position + 180 - 25);
            //gfx.DrawLine(pen, 120, position + 195 - 25, 240, position + 195 - 25);
            //gfx.DrawLine(pen, 120, position + 210 - 25, 240, position + 210 - 25);
            if (position < 0)
            {
                gfx.DrawLine(pen, 120, 255 - 25, 200, 255 - 25);
                gfx.DrawLine(pen, 290, 255 - 25, 550, 255 - 25);
                gfx.DrawLine(penBorderLine1, 0, 250, 650, 250);
            }

            gfx.DrawLine(penBorderLine1, 0, 300, 650, 300);
            gfx.DrawLine(penBorderLine2, 0, 300 + 350, 650, 300 + 350);
            penBorderLine2.DashStyle = XDashStyle.Dash;
        }
예제 #12
0
        /// <summary>
        /// Generates a barcode PDF and returns the number of barcodes generated
        /// </summary>
        /// <param name="outputPath"></param>
        /// <param name="numberOfPages"></param>
        /// <returns>The number of barcodes generated</returns>
        public int GenerateBarcodes(string outputPath)
        {
            if (NumberOfPages > 0)
            {
                PdfDocument document = new PdfDocument();
                document.Info.Title = "Inventory Barcodes";
                long barcodeToUse      = GeneratedBarcode.GetLatestBarcodeNumber() + 1;
                var  barcodesGenerated = new List <long>();
                for (int i = 0; i < NumberOfPages; i++)
                {
                    PdfPage page = document.AddPage();
                    page.Size = PageSize;

                    XGraphics gfx    = XGraphics.FromPdfPage(page);
                    XFont     font   = new XFont("Verdana", 20, XFontStyle.Bold);
                    XUnit     yCoord = XUnit.FromInch(1); // pixels
                    gfx.DrawString("Inventory Barcodes", font, XBrushes.Black,
                                   new XRect(0, yCoord, page.Width, page.Height), XStringFormats.TopCenter);

                    yCoord += XUnit.FromInch(0.7);

                    // Generate a barcode
                    var barcodeCreator = new BarcodeLib.Barcode();
                    barcodeCreator.ImageFormat  = ImageFormat.Jpeg;
                    barcodeCreator.IncludeLabel = false;
                    //barcodeCreator.IncludeLabel = true;
                    //barcodeCreator.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;
                    barcodeCreator.Alignment = BarcodeLib.AlignmentPositions.CENTER;

                    bool  isPageFull  = false;
                    XUnit imageHeight = XUnit.FromPoint(60);
                    while (!isPageFull)
                    {
                        var   isWidthFull = false;
                        XUnit xCoord      = XUnit.FromInch(1);
                        while (!isWidthFull)
                        {
                            var image = barcodeCreator.Encode(BarcodeType, barcodeToUse.ToString());
                            if (image != null)
                            {
                                // make sure images are a good size based on DPI
                                // TODO: There has got to be a better way to make things fairly consistent across computers
                                // with different DPI. This is ridiculous. I love WPF most of the time with its DPI
                                // help, but in this case.......ugh. Images come out a little blurry this way
                                // on computers with a non-192 DPI, but scanners will probably be OK.
                                double ratioTo192   = (192 / image.VerticalResolution);
                                int    resizeHeight = (int)(image.Height / ratioTo192);
                                int    resizeWidth  = (int)(image.Width / ratioTo192);
                                image = ResizeImage(image, resizeWidth, resizeHeight, (int)image.VerticalResolution);
                                // ok, now we can draw.
                                XImage pdfImage = XImage.FromBitmapSource(ConvertImageToBitmapImage(image));
                                gfx.DrawImage(pdfImage, xCoord, yCoord);
                                // now draw label
                                XFont barcodeFont = new XFont("Verdana", 16, XFontStyle.Bold);
                                // + 2 on the y coordinate there just to give it a teensy bit of space
                                gfx.DrawString(barcodeToUse.ToString(), barcodeFont, XBrushes.Black,
                                               new XRect(xCoord, yCoord + pdfImage.PointHeight + 2, pdfImage.PointWidth, 150), XStringFormats.TopCenter);
                                //
                                xCoord     += XUnit.FromPoint(pdfImage.PointWidth);
                                imageHeight = XUnit.FromPoint(pdfImage.PointHeight);
                                //var blah = XUnit.FromPoint(image.Width);
                                XUnit spaceBetweenBarcodes = XUnit.FromInch(0.75);
                                if (xCoord + XUnit.FromPoint(pdfImage.PointWidth) + spaceBetweenBarcodes > page.Width - XUnit.FromInch(1))
                                {
                                    isWidthFull = true;
                                }
                                barcodesGenerated.Add(barcodeToUse);
                                barcodeToUse++;
                                xCoord += spaceBetweenBarcodes;
                            }
                            else
                            {
                                // failure case
                                isWidthFull = true;
                                isPageFull  = true;
                                break;
                            }
                        }
                        yCoord += imageHeight;
                        yCoord += XUnit.FromInch(0.7);
                        if (yCoord + imageHeight > page.Height - XUnit.FromInch(1))
                        {
                            isPageFull = true;
                        }
                    }
                }
                if (!IsDryRun)
                {
                    // save the fact that we generated barcodes
                    GeneratedBarcode.AddGeneratedCodes(barcodesGenerated, DateTime.Now, 1);
                    // save the document and start the process for viewing the pdf
                    document.Save(outputPath);
                    Process.Start(outputPath);
                }
                return(barcodesGenerated.Count);
            }
            return(0);
        }
예제 #13
0
파일: Db.cs 프로젝트: ZhyvelM/Lab1
        public static void Export(string norm, string total)
        {
            XFont small = new XFont("Comic Sans MS", 14, XFontStyle.Regular);
            XFont middle = new XFont("Comic Sans MS", 18, XFontStyle.Regular);
            XFont xlarge = new XFont("Comic Sans MS", 24, XFontStyle.Regular);
            int   x = 40, y = 0;

            PdfDocument document = new PdfDocument();

            document.Info.Title = "Рацион";
            PdfPage   page = document.AddPage();
            XGraphics gfx  = XGraphics.FromPdfPage(page);

            gfx.DrawString("РАЦИОН", xlarge, XBrushes.Black, new XRect(0, y, page.Width, page.Height), XStringFormats.TopCenter);
            y += 35;
            gfx.DrawString("Информация о пользователе", middle, XBrushes.Black, new XRect(0, y, page.Width, page.Height), XStringFormats.TopCenter);
            y += 20;
            gfx.DrawString($"Имя: {instance.user.name}", small, XBrushes.Black, new XRect(x + 20, y, page.Width, page.Height), XStringFormats.TopLeft);
            y += 20;
            gfx.DrawString($"Возраст: {instance.user.age}", small, XBrushes.Black, new XRect(x + 20, y, page.Width, page.Height), XStringFormats.TopLeft);
            y += 20;
            gfx.DrawString($"Рост: {instance.user.height}", small, XBrushes.Black, new XRect(x + 20, y, page.Width, page.Height), XStringFormats.TopLeft);
            y += 20;
            gfx.DrawString($"Вес: {instance.user.weight}", small, XBrushes.Black, new XRect(x + 20, y, page.Width, page.Height), XStringFormats.TopLeft);
            y += 20;
            gfx.DrawString($"Активность: {instance.user.activity}", small, XBrushes.Black, new XRect(x + 20, y, page.Width, page.Height), XStringFormats.TopLeft);
            y += 30;
            gfx.DrawString($"Дневная норма: {norm}", xlarge, XBrushes.Black, new XRect(0, y, page.Width, page.Height), XStringFormats.TopCenter);
            foreach (Meal meal in instance.Meals.Values)
            {
                y += 35;
                if (y + 35 > page.Height)
                {
                    page = document.AddPage();
                    gfx  = XGraphics.FromPdfPage(page);
                    y    = 0;
                }
                gfx.DrawString(meal.name, middle, XBrushes.Green, new XRect(x + 20, y, page.Width, page.Height), XStringFormats.TopLeft);
                foreach (Product product in meal.Products.Values)
                {
                    y += 25;
                    if (y + 25 > page.Height)
                    {
                        page = document.AddPage();
                        gfx  = XGraphics.FromPdfPage(page);
                        y    = 0;
                    }
                    gfx.DrawString($"{product.Name}: {product.Gramms}г", small, XBrushes.Black, new XRect(x + 25, y, page.Width, page.Height), XStringFormats.TopLeft);
                }
            }
            y += 50;
            if (y > page.Height)
            {
                page = document.AddPage();
                gfx  = XGraphics.FromPdfPage(page);
                y    = 0;
            }
            gfx.DrawString($"Итог: {total}кал", xlarge, XBrushes.Black, new XRect(0, y, page.Width, page.Height), XStringFormats.TopCenter);
            document.Save("DailyRation.pdf");
        }
예제 #14
0
        private static void DrawLabel(string text, int x, int y, int width, int height, XGraphics gfx)
        {
            XFont LabelFont = new XFont("calibri", 11, XFontStyle.Regular);

            gfx.DrawString(text, LabelFont, XBrushes.Black, new XRect(x, y, width, height), XStringFormats.CenterLeft);
        }
예제 #15
0
        // This sample shows how to create an XForm object from scratch. You can think of such an
        // object as a template, that, once created, can be drawn frequently anywhere in your PDF document.
        protected override void DoWork()
        {
            // Create a new PDF document
            PdfDocument document = new PdfDocument();

            // Create a font
            XFont font = new XFont("Verdana", 16);

            // Create a new page
            PdfPage   page = document.AddPage();
            XGraphics gfx  = XGraphics.FromPdfPage(page, XPageDirection.Downwards);

            gfx.DrawString("XPdfForm Sample", font, XBrushes.DarkGray, 15, 25, XStringFormats.Default);

            // Step 1: Create an XForm and draw some graphics on it

            // Create an empty XForm object with the specified width and Height
            // A form is bound to its target document when it is created. The reason is that the form can
            // share fonts and other objects with its target document.
            XForm form = new XForm(document, XUnit.FromMillimeter(70), XUnit.FromMillimeter(55));

            // Create an XGraphics object for drawing the contents of the form.
            XGraphics formGfx = XGraphics.FromForm(form);

            // Draw a large transparent rectangle to visualize the area the form occupies
            XColor back = XColors.Orange;

            back.A = 0.2;
            XSolidBrush brush = new XSolidBrush(back);

            formGfx.DrawRectangle(brush, -10000, -10000, 20000, 20000);

            // On a form you can draw...

            // ... text
            formGfx.DrawString("Text, Graphics, Images, and Forms", new XFont("Verdana", 10, XFontStyle.Regular), XBrushes.Navy, 3, 0, XStringFormats.TopLeft);
            XPen pen = XPens.LightBlue.Clone();

            pen.Width = 2.5;

            // ... graphics like Bйzier curves
            formGfx.DrawBeziers(pen, XPoint.ParsePoints("30,120 80,20 100,140 175,33.3"));

            // ... raster images like GIF files
            XGraphicsState state = formGfx.Save();

            formGfx.RotateAtTransform(17, new XPoint(30, 30));
            formGfx.DrawImage(XImage.FromFile("AltData/PDFsharp/dev/XGraphicsLab/images/Test.gif"), 20, 20);
            formGfx.Restore(state);

            // ... and forms like XPdfForm objects
            state = formGfx.Save();
            formGfx.RotateAtTransform(-8, new XPoint(165, 115));
            formGfx.DrawImage(XPdfForm.FromFile("AltData/PDFsharp/PDFs/SomeLayout.pdf"), new XRect(140, 80, 50, 50 * Math.Sqrt(2)));
            formGfx.Restore(state);

            // When you finished drawing on the form, dispose the XGraphic object.
            formGfx.Dispose();


            // Step 2: Draw the XPdfForm on your PDF page like an image

            // Draw the form on the page of the document in its original size
            gfx.DrawImage(form, 20, 50);

#if true
            // Draw it stretched
            gfx.DrawImage(form, 300, 100, 250, 40);

            // Draw and rotate it
            const int d = 25;
            for (int idx = 0; idx < 360; idx += d)
            {
                gfx.DrawImage(form, 300, 480, 200, 200);
                gfx.RotateAtTransform(d, new XPoint(300, 480));
            }
#endif

            // Save the document...
            const string filename = "XForms_tempfile.pdf";
            document.Save(filename);
            // ...and start a viewer.
            Diagnostics.ProcessHelper.Start(filename);
        }
예제 #16
0
        public FileResult PrintDetails(int id)
        {
            string pdfFilename = "";
            string line        = "";

            try
            {
                List <GetOrderDetail>  bkryList      = new List <GetOrderDetail>();
                List <BKRY_ITEMS>      lstBKRY_ITEMS = new List <BKRY_ITEMS>();
                List <GetOrderDetail2> bkrList2      = new List <GetOrderDetail2>();
                using (BKRY_MNGT_SYSEntities db = new BKRY_MNGT_SYSEntities())
                {
                    bkryList = db.GetOrderDetails.Where(x => x.OrderId == id).ToList <GetOrderDetail>();
                    foreach (var item in bkryList)
                    {
                        line += "Bakery System " + " \n";
                        line += "*****************************************************" + " \n";
                        line += "Order # : " + item.OrderId + " \n";
                        line += "Person Name : " + item.personname + " \n";
                        line += "Address : " + item.address + " \n";
                        line += "Street : " + item.street + " \n";
                        line += "PostCode : " + item.postCode + " \n";
                        line += "Email  : " + item.email + " \n";
                        line += "Order On  : " + Convert.ToDateTime(item.Orderon).ToLongDateString() + " \n";
                        line += "*****************************************************" + " \n";
                        line += "Item Details" + "\n";
                        decimal pp = 0;
                        foreach (var Oitem in JsonConvert.DeserializeObject <List <BKRY_ITEMS> >(item.OrderDetails))
                        {
                            line += "Product : " + Oitem.name + " Quantity : " + Oitem.quantity + " Price : " + Oitem.price + " \n";
                            pp   += (Convert.ToDecimal(Oitem.price) * Convert.ToDecimal(Oitem.quantity));
                        }
                        line += "*****************************************************" + " \n";
                        line += "Total : " + pp + " \n ";
                    }
                }
                int         yPoint = 0;
                PdfDocument pdf    = new PdfDocument();
                pdf.Info.Title = "Bakery System Order No #" + id;
                PdfPage   pdfPage = pdf.AddPage();
                XGraphics graph   = XGraphics.FromPdfPage(pdfPage);
                XFont     font    = new XFont("Verdana", 8, XFontStyle.Regular);
                //graph.DrawString(line, font, XBrushes.Black, pdfPage.Width.Point, pdfPage.Height.Point);
                foreach (var item in line.Split('\n'))
                {
                    graph.DrawString(item, font, XBrushes.Black, new XRect(40, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
                    yPoint = yPoint + 10;
                }


                pdfFilename = Server.MapPath("~/Temp/txttopdf" + DateTime.Now.ToString("mmddyyyyhhMMss") + ".pdf");
                pdf.Save(pdfFilename);
            }
            catch (Exception ex)
            {
            }
            byte[] fileBytes = System.IO.File.ReadAllBytes(pdfFilename);
            string fileName  = "txttopdf" + DateTime.Now.ToString("mmddyyyyhhMMss") + ".pdf";

            return(File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName));
        }
        /// <summary>
        /// Draws the horizontal X axis.
        /// </summary>
        internal override void Draw()
        {
            XGraphics         gfx  = _rendererParms.Graphics;
            ChartRendererInfo cri  = (ChartRendererInfo)_rendererParms.RendererInfo;
            AxisRendererInfo  xari = cri.xAxisRendererInfo;

            double xMin          = xari.MinimumScale;
            double xMax          = xari.MaximumScale;
            double xMajorTick    = xari.MajorTick;
            double xMinorTick    = xari.MinorTick;
            double xMaxExtension = xari.MajorTick;

            // Draw tick labels. Each tick label will be aligned centered.
            int    countTickLabels = (int)xMax;
            double tickLabelStep   = xari.Height / countTickLabels;
            XPoint startPos        = new XPoint(xari.X + xari.Width - xari.MajorTickMarkWidth, xari.Y + tickLabelStep / 2);

            foreach (XSeries xs in xari.XValues)
            {
                for (int idx = countTickLabels - 1; idx >= 0; --idx)
                {
                    XValue xv        = xs[idx];
                    string tickLabel = xv._value;
                    XSize  size      = gfx.MeasureString(tickLabel, xari.TickLabelsFont);
                    gfx.DrawString(tickLabel, xari.TickLabelsFont, xari.TickLabelsBrush, startPos.X - size.Width, startPos.Y + size.Height / 2);
                    startPos.Y += tickLabelStep;
                }
            }

            // Draw axis.
            // First draw tick marks, second draw axis.
            double majorTickMarkStart = 0, majorTickMarkEnd = 0,
                   minorTickMarkStart = 0, minorTickMarkEnd = 0;

            GetTickMarkPos(xari, ref majorTickMarkStart, ref majorTickMarkEnd, ref minorTickMarkStart, ref minorTickMarkEnd);

            LineFormatRenderer lineFormatRenderer = new LineFormatRenderer(gfx, xari.LineFormat);

            XPoint[] points = new XPoint[2];

            // Minor ticks.
            if (xari.MinorTickMark != TickMarkType.None)
            {
                int    countMinorTickMarks = (int)(xMax / xMinorTick);
                double minorTickMarkStep   = xari.Height / countMinorTickMarks;
                startPos.Y = xari.Y;
                for (int x = 0; x <= countMinorTickMarks; x++)
                {
                    points[0].X = minorTickMarkStart;
                    points[0].Y = startPos.Y + minorTickMarkStep * x;
                    points[1].X = minorTickMarkEnd;
                    points[1].Y = points[0].Y;
                    lineFormatRenderer.DrawLine(points[0], points[1]);
                }
            }

            // Major ticks.
            if (xari.MajorTickMark != TickMarkType.None)
            {
                int    countMajorTickMarks = (int)(xMax / xMajorTick);
                double majorTickMarkStep   = xari.Height / countMajorTickMarks;
                startPos.Y = xari.Y;
                for (int x = 0; x <= countMajorTickMarks; x++)
                {
                    points[0].X = majorTickMarkStart;
                    points[0].Y = startPos.Y + majorTickMarkStep * x;
                    points[1].X = majorTickMarkEnd;
                    points[1].Y = points[0].Y;
                    lineFormatRenderer.DrawLine(points[0], points[1]);
                }
            }

            // Axis.
            if (xari.LineFormat != null)
            {
                points[0].X = xari.X + xari.Width;
                points[0].Y = xari.Y;
                points[1].X = xari.X + xari.Width;
                points[1].Y = xari.Y + xari.Height;
                if (xari.MajorTickMark != TickMarkType.None)
                {
                    points[0].Y -= xari.LineFormat.Width / 2;
                    points[1].Y += xari.LineFormat.Width / 2;
                }
                lineFormatRenderer.DrawLine(points[0], points[1]);
            }

            // Draw axis title.
            AxisTitleRendererInfo atri = xari._axisTitleRendererInfo;

            if (atri != null && atri.AxisTitleText != null && atri.AxisTitleText.Length > 0)
            {
                XRect rect = new XRect(xari.X, xari.Y + xari.Height / 2, atri.AxisTitleSize.Width, 0);
                gfx.DrawString(atri.AxisTitleText, atri.AxisTitleFont, atri.AxisTitleBrush, rect);
            }
        }
예제 #18
0
        static void Main()
        {
            // Create a new PDF document
            PdfDocument document = new PdfDocument();

            // Create a font
            XFont font = new XFont("Verdana", 14);

            // Create a page
            PdfPage   page = document.AddPage();
            XGraphics gfx  = XGraphics.FromPdfPage(page);

            // Create a PDF text annotation
            PdfTextAnnotation textAnnot = new PdfTextAnnotation();

            textAnnot.Title    = "This is the title";
            textAnnot.Subject  = "This is the subject";
            textAnnot.Contents = "This is the contents of the annotation.\rThis is the 2nd line.";
            textAnnot.Icon     = PdfTextAnnotationIcon.Note;

            gfx.DrawString("The first text annotation", font, XBrushes.Black, 30, 50, XStringFormats.Default());

            // Convert rectangle form world space to page space. This is necessary because the annotation is
            // placed relative to the bottom left corner of the page with units measured in point.
            XRect rect = gfx.Transformer.WorldToDefaultPage(new XRect(new XPoint(30, 60), new XSize(30, 30)));

            textAnnot.Rectangle = new PdfRectangle(rect);

            // Add the annotation to the page
            page.Annotations.Add(textAnnot);

            // Create another PDF text annotation which is open and transparent
            textAnnot          = new PdfTextAnnotation();
            textAnnot.Title    = "Annotation 2 (title)";
            textAnnot.Subject  = "Annotation 2 (subject)";
            textAnnot.Contents = "This is the contents of the 2nd annotation.";
            textAnnot.Icon     = PdfTextAnnotationIcon.Help;
            textAnnot.Color    = XColors.LimeGreen;
            textAnnot.Opacity  = 0.5;
            textAnnot.Open     = true;

            gfx.DrawString("The second text annotation (opened)", font, XBrushes.Black, 30, 140, XStringFormats.Default());

            rect = gfx.Transformer.WorldToDefaultPage(new XRect(new XPoint(30, 150), new XSize(30, 30)));
            textAnnot.Rectangle = new PdfRectangle(rect);

            // Add the 2nd annotation to the page
            page.Annotations.Add(textAnnot);


            // Create a so called rubber stamp annotion. I'm not sure if it is useful, but at least
            // it looks impressive...
            PdfRubberStampAnnotation rsAnnot = new PdfRubberStampAnnotation();

            rsAnnot.Icon  = PdfRubberStampAnnotationIcon.TopSecret;
            rsAnnot.Flags = PdfAnnotationFlags.ReadOnly;

            rect = gfx.Transformer.WorldToDefaultPage(new XRect(new XPoint(100, 400), new XSize(350, 150)));
            rsAnnot.Rectangle = new PdfRectangle(rect);

            // Add the rubber stamp annotation to the page
            page.Annotations.Add(rsAnnot);

            // PDF supports some more pretty types of annotations like PdfLineAnnotation, PdfSquareAnnotation,
            // PdfCircleAnnotation, PdfMarkupAnnotation (with the subtypes PdfHighlightAnnotation, PdfUnderlineAnnotation,
            // PdfStrikeOutAnnotation, and PdfSquigglyAnnotation), PdfSoundAnnotation, or PdfMovieAnnotation.
            // If you need one of them, feel encouraged to implement it. It is quite easy.

            // Save the document...
            const string filename = "Annotations_tempfile.pdf";

            document.Save(filename);
            // ...and start a viewer.
            Process.Start(filename);
        }
예제 #19
0
        private void GenerarPDF(BLReferencia referencia)
        {
            try
            {
                PdfDocument pdf = new PdfDocument();
                pdf.Info.Title = "Mi título";
                PdfPage   page  = pdf.AddPage();
                XGraphics graph = XGraphics.FromPdfPage(page);

                XFont fontRegular = new XFont("Verdana", 10, XFontStyle.Regular);
                XFont fontBold    = new XFont("Verdana", 10, XFontStyle.Bold);

                XTextFormatter tf = new XTextFormatter(graph);

                tf.Alignment = XParagraphAlignment.Justify;

                graph.DrawString(referencia.NombreClinica, fontRegular, XBrushes.Black, new XRect(20, 10, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
                graph.DrawString("Dr. " + referencia.NombreMedico, fontRegular, XBrushes.Black, new XRect(20, 22, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
                graph.DrawString("Código: " + referencia.CodigoMedico, fontRegular, XBrushes.Black, new XRect(20, 34, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
                graph.DrawString("Tel: " + referencia.TelefonoMedico, fontRegular, XBrushes.Black, new XRect(20, 46, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
                graph.DrawString("Correo: " + referencia.CorreoMedico, fontRegular, XBrushes.Black, new XRect(20, 58, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);

                graph.DrawString("Fecha: ", fontRegular, XBrushes.Black, new XRect(340, 10, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
                graph.DrawString(referencia.FechaReferencia, fontRegular, XBrushes.Black, new XRect(390, 10, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);

                graph.DrawString("Cédula: ", fontRegular, XBrushes.Black, new XRect(340, 22, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
                graph.DrawString(referencia.CedulaPaciente, fontRegular, XBrushes.Black, new XRect(390, 22, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);

                graph.DrawString("Nombre: ", fontRegular, XBrushes.Black, new XRect(340, 34, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
                graph.DrawString(referencia.NombrePaciente, fontRegular, XBrushes.Black, new XRect(390, 34, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);

                graph.DrawString("Edad: ", fontRegular, XBrushes.Black, new XRect(340, 46, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
                graph.DrawString(referencia.EdadPaciente, fontRegular, XBrushes.Black, new XRect(390, 46, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);

                graph.DrawString("Sexo: ", fontRegular, XBrushes.Black, new XRect(340, 58, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
                graph.DrawString(referencia.SexoPaciente, fontRegular, XBrushes.Black, new XRect(390, 58, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);

                tf.DrawString("Análisis: ", fontRegular, XBrushes.Black, new XRect(20, 100, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
                tf.DrawString(referencia.Analisis, fontRegular, XBrushes.Black, new XRect(20, 115, page.Width - 40, page.Height.Point), XStringFormats.TopLeft);

                tf.DrawString("Impresión Diagnóstica: ", fontRegular, XBrushes.Black, new XRect(20, 250, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
                tf.DrawString(referencia.ImpresionDiagnóstica, fontRegular, XBrushes.Black, new XRect(20, 265, page.Width - 40, page.Height.Point), XStringFormats.TopLeft);

                tf.DrawString("A: (Especialidad) ", fontRegular, XBrushes.Black, new XRect(20, 400, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
                tf.DrawString(referencia.Especialidad, fontRegular, XBrushes.Black, new XRect(20, 415, page.Width - 40, page.Height.Point), XStringFormats.TopLeft);

                tf.DrawString("Motivo de la Referencia: ", fontRegular, XBrushes.Black, new XRect(20, 450, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
                tf.DrawString(referencia.Motivo, fontRegular, XBrushes.Black, new XRect(20, 465, page.Width - 40, page.Height.Point), XStringFormats.TopLeft);

                tf.DrawString("Observaciones: ", fontRegular, XBrushes.Black, new XRect(20, 600, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
                tf.DrawString("", fontRegular, XBrushes.Black, new XRect(20, 615, page.Width - 40, page.Height.Point), XStringFormats.TopLeft);


                tf.Alignment = XParagraphAlignment.Center;
                tf.DrawString("__________________________", fontBold, XBrushes.Black, new XRect(0, 745, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
                tf.DrawString("Firma", fontRegular, XBrushes.Black, new XRect(0, 760, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);


                // Send PDF to browser
                MemoryStream stream = new MemoryStream();
                pdf.Save(stream, false);

                Response.Clear();
                Response.ContentType = "application/force-download";
                Response.AppendHeader("Content-Disposition", "attachment; filename=Referencia.pdf");
                Response.BinaryWrite(stream.ToArray());
                Response.Flush();
                stream.Close();
                Response.End();
            }
            catch (Exception ex)
            {
            }
        }
예제 #20
0
        //Create PDF document

        public object createPdf(FormCollection form, string path)
        {
            //Create new procurement object

            ProcurementModels procurement = new ProcurementModels()
            {
                Computer    = getComputerPDF(form).ToString(),
                Quantity    = Convert.ToInt32(getComputerQuantity(form)),
                InvoiceNo   = getInvoiceNo().ToString(),
                RequestDate = DateTime.Today
            };

            _db.ProcurementModels.Add(procurement);
            _db.SaveChanges();

            var supplier = (from c in _db.ComputerListModels where c.Name == procurement.Computer select c.SupplierName).FirstOrDefault();

            ViewBag.supplier = supplier;

            //Create Invoice PDF

            PdfDocument pdf = new PdfDocument();

            pdf.Info.Title = procurement.InvoiceNo;
            PdfPage pdfPage     = pdf.AddPage();
            string  pdfFilename = "Invoice_" + procurement.InvoiceNo + ".pdf";

            XGraphics graph = XGraphics.FromPdfPage(pdfPage);
            XFont     font  = new XFont("Verdana", 10, XFontStyle.Bold);
            XFont     font2 = new XFont("Verdana", 20, XFontStyle.Bold);

            graph.DrawString("New procurement request", font2,
                             XBrushes.Black,
                             new XRect(50, 50, 200, 0), XStringFormats.TopLeft);

            graph.DrawString("Supplier: " + supplier, font,
                             XBrushes.Black,
                             new XRect(50, 100, 200, 0), XStringFormats.TopLeft);

            graph.DrawString(pdfFilename, font,
                             XBrushes.Black,
                             new XRect(50, 130, 200, 0), XStringFormats.TopLeft);

            graph.DrawString("Quantity: " + procurement.Quantity, font,
                             XBrushes.Black,
                             new XRect(50, 160, 200, 0), XStringFormats.TopLeft);

            graph.DrawString("Computer: " + procurement.Computer, font,
                             XBrushes.Black,
                             new XRect(50, 190, 200, 0), XStringFormats.TopLeft);

            graph.DrawString("This request was made on " + procurement.RequestDate, font,
                             XBrushes.Black,
                             new XRect(50, 220, 200, 0), XStringFormats.TopLeft);

            graph.DrawString("Signature ", font,
                             XBrushes.Black,
                             new XRect(50, 250, 200, 0), XStringFormats.TopLeft);

            graph.DrawString("___________________", font,
                             XBrushes.Black,
                             new XRect(50, 280, 200, 0), XStringFormats.TopLeft);


            pdf.Save(path + getPDFFileName(procurement.InvoiceNo));

            //TempData for DownloadPDF
            TempData["pdfFilename"] = getPDFFileName(procurement.InvoiceNo);
            return(TempData["pdfFilename"]);
        }
예제 #21
0
    private void PrintSalesStatement()
    {
        #region variables
        double   bookPrice;
        double   cdPrice;
        double   sheetPrice;
        int      bookQty;
        int      cdQty;
        int      sheetQty;
        int      flag      = 0;
        int      pageCount = 1;
        string   strfd     = txtFromDate.Text;
        string[] strDate   = strfd.Split('-');
        string   date      = strDate[0];
        string   Month     = strDate[1];
        string   Year      = strDate[2];
        strfd = Year + '-' + Month + '-' + date;
        string strto = txtToDate.Text;
        strDate = strto.Split('-');
        date    = strDate[0];
        Month   = strDate[1];
        Year    = strDate[2];
        strto   = Year + '-' + Month + '-' + date;
        #endregion

        #region query

        DataTable dt1 = new Facade().GetReportByFromAndTo(strfd, strto, true, false, false); //dbHandler.GetDataTable(sql1);


//        string sql2 = @"select os.articlecode as ArticleCode,a.title as Title, Sum(unitprice) as Price,sum(os.quantity) as Quantity
//                    from orders o, ordersline os , article a
//                    where o.orderid = os.orderid
//                    and os.articlecode=a.articlecode
//                    and o.orderdate between '" + strfd + "' and '" + strto + @"'
//                    and (os.articlecode like 'c%' or os.articlecode like 'd%')
//                    group by os.articlecode,a.title
//                    order by Quantity desc, Price desc";

        DataTable dt2 = new Facade().GetReportByFromAndTo(strfd, strto, false, true, false); //dbHandler.GetDataTable(sql2);



        DataTable dt3 = new Facade().GetReportByFromAndTo(strfd, strto, false, false, true);

        #endregion
        // Create a new PDF document
        PdfDocument document = new PdfDocument();


        // Create an empty page
        PdfPage page = document.AddPage();

        // Get an XGraphics object for drawing
        XGraphics gfx = XGraphics.FromPdfPage(page);

        int x = 30, y = 80;



        // Create a font
        XFont font_hdr   = new XFont("Arial", 20, XFontStyle.Regular);
        XFont font       = new XFont("Arial", 15, XFontStyle.Regular);
        XFont font_small = new XFont("Arial", 10, XFontStyle.Regular);

        XPen pen      = new XPen(XColor.FromArgb(50, 0, 0, 0), 2);
        XPen totalPen = new XPen(XColor.FromName("black"), 1);


        XTextFormatter tf  = new XTextFormatter(gfx);
        XTextFormatter tf1 = new XTextFormatter(gfx);
        XTextFormatter tf2 = new XTextFormatter(gfx);
        tf.Alignment  = XParagraphAlignment.Right;
        tf1.Alignment = XParagraphAlignment.Center;
        tf2.Alignment = XParagraphAlignment.Left;


        int   i       = 0;
        XRect rec_hdr = new XRect(x + 200, y - 65, 300, 100);
        tf2.DrawString("Sales Statement", font_hdr, XBrushes.Black, rec_hdr);
        XRect rec = new XRect(x - 22, y - 35, 200, 100);
        tf.DrawString("Date Range: " + txtFromDate.Text + " to: " + txtToDate.Text + "", font_small, XBrushes.Black, rec);
        XRect rec_b = new XRect(x, y - 20, 200, 100);
        tf2.DrawString("Books", font, XBrushes.Black, rec_b);
        gfx.DrawLine(pen, 30, y + 3, 600, y + 3);
        gfx.DrawLine(pen, 30, y + 15, 600, y + 15);
        XRect rec1 = new XRect(x, y + 3, 570, 11);
        gfx.DrawRectangle(new XSolidBrush(XColor.FromArgb(120, 204, 204, 204)), rec1);
        tf2.DrawString("Article Code", font_small, XBrushes.Black, new XRect(x + 15, y + 5, 110, 100));
        tf.DrawString("Title", font_small, XBrushes.Black, new XRect(x + 70, y + 5, 110, 100));
        tf.DrawString("Quantity", font_small, XBrushes.Black, new XRect(x + 300, y + 5, 110, 100));
        tf.DrawString("Price", font_small, XBrushes.Black, new XRect(x + 400, y + 5, 110, 100));


        //double sum = dt1.Columns[2].com
        DataColumn sumofBookPrice = new DataColumn("sum", Type.GetType("System.Double"), "sum(Price)");
        dt1.Columns.Add(sumofBookPrice);


        DataColumn sumofBookQty = new DataColumn("qty", Type.GetType("System.Int32"), "sum(Quantity)");
        dt1.Columns.Add(sumofBookQty);

        DataColumn sumofCD = new DataColumn("sum", Type.GetType("System.Double"), "sum(Price)");
        dt2.Columns.Add(sumofCD);

        DataColumn sumofCDQty = new DataColumn("qty", Type.GetType("System.Int32"), "sum(Quantity)");
        dt2.Columns.Add(sumofCDQty);

        DataColumn sumofSheet = new DataColumn("sum", Type.GetType("System.Double"), "sum(Price)");
        dt3.Columns.Add(sumofSheet);

        DataColumn sumofSheetQty = new DataColumn("qty", Type.GetType("System.Int32"), "sum(Quantity)");
        dt3.Columns.Add(sumofSheetQty);

        try
        {
            bookPrice = Convert.ToDouble(dt1.Rows[0]["sum"].ToString());
            bookQty   = Convert.ToInt32(dt1.Rows[0]["qty"].ToString());
        }
        catch
        {
            bookPrice = 0.0;
            bookQty   = 0;
        }
        try
        {
            cdPrice = Convert.ToDouble(dt2.Rows[0]["sum"].ToString());
            cdQty   = Convert.ToInt32(dt1.Rows[0]["qty"].ToString());
        }
        catch
        {
            cdPrice = 0.0;
            cdQty   = 0;
        }
        try
        {
            sheetPrice = Convert.ToDouble(dt3.Rows[0]["sum"].ToString());
            sheetQty   = Convert.ToInt32(dt3.Rows[0]["qty"].ToString());
        }
        catch
        {
            sheetPrice = 0.0;
            sheetQty   = 0;
        }


        foreach (DataRow row in dt1.Rows)
        {
            y += 25;
            tf2.DrawString(dt1.Rows[i]["ArticleCode"].ToString(), font_small, XBrushes.Black, new XRect(x + 20, y, 110, 100));
            tf2.DrawString(dt1.Rows[i]["Title"].ToString(), font_small, XBrushes.Black, new XRect(x + 90, y, 300, 100));
            tf.DrawString(dt1.Rows[i]["Quantity"].ToString(), font_small, XBrushes.Black, new XRect(x + 300, y, 110, 100));
            tf.DrawString(dt1.Rows[i]["Price"].ToString(), font_small, XBrushes.Black, new XRect(x + 400, y, 110, 100));
            i++;
            if (gfx.PageSize.Height - y <= 100)
            {
                page          = document.AddPage();
                gfx           = XGraphics.FromPdfPage(page);
                tf            = new XTextFormatter(gfx);
                tf1           = new XTextFormatter(gfx);
                tf2           = new XTextFormatter(gfx);
                tf.Alignment  = XParagraphAlignment.Right;
                tf1.Alignment = XParagraphAlignment.Center;
                tf2.Alignment = XParagraphAlignment.Left;
                y             = 50;
                ++pageCount;
            }
        }
        gfx.DrawLine(totalPen, 380, y + 15, 580, y + 15);
        y += 25;
        tf.DrawString("Total", font_small, XBrushes.Black, new XRect(x + 220, y, 110, 125));
        tf.DrawString(bookQty.ToString(), font_small, XBrushes.Black, new XRect(x + 300, y, 110, 125));
        tf.DrawString(bookPrice.ToString(), font_small, XBrushes.Black, new XRect(x + 400, y, 110, 125));
        gfx.DrawLine(pen, 30, y + 15, 600, y + 15);
        i  = 0;
        y += 40;
        XRect rec_cd = new XRect(x, y, 200, 50);
        tf2.DrawString("CD/DVD", font, XBrushes.Black, rec_cd);
        gfx.DrawLine(pen, 30, y + 22, 600, y + 22);
        gfx.DrawLine(pen, 30, y + 36, 600, y + 36);
        XRect rec2 = new XRect(x, y + 22, 570, 15);
        gfx.DrawRectangle(new XSolidBrush(XColor.FromArgb(120, 204, 204, 204)), rec2);
        y += 20;

        tf2.DrawString("Article Code", font_small, XBrushes.Black, new XRect(x + 15, y + 5, 110, 100));
        tf.DrawString("Title", font_small, XBrushes.Black, new XRect(x + 70, y + 5, 110, 100));
        tf.DrawString("Quantity", font_small, XBrushes.Black, new XRect(x + 300, y + 5, 110, 100));
        tf.DrawString("Price", font_small, XBrushes.Black, new XRect(x + 400, y + 5, 110, 100));

        foreach (DataRow row in dt2.Rows)
        {
            y += 25;
            //x += 50;
            tf2.DrawString(dt2.Rows[i]["ArticleCode"].ToString(), font_small, XBrushes.Black, new XRect(x + 20, y, 110, 100));
            tf2.DrawString(dt2.Rows[i]["Title"].ToString(), font_small, XBrushes.Black, new XRect(x + 90, y, 300, 100));
            tf.DrawString(dt2.Rows[i]["Quantity"].ToString(), font_small, XBrushes.Black, new XRect(x + 300, y, 110, 100));
            tf.DrawString(dt2.Rows[i]["Price"].ToString(), font_small, XBrushes.Black, new XRect(x + 400, y, 110, 100));
            i++;
            if (gfx.PageSize.Height - y <= 100)
            {
                page          = document.AddPage();
                gfx           = XGraphics.FromPdfPage(page);
                tf            = new XTextFormatter(gfx);
                tf1           = new XTextFormatter(gfx);
                tf2           = new XTextFormatter(gfx);
                tf.Alignment  = XParagraphAlignment.Right;
                tf1.Alignment = XParagraphAlignment.Center;
                tf2.Alignment = XParagraphAlignment.Left;
                y             = 50;
                ++pageCount;
            }
        }

        gfx.DrawLine(totalPen, 380, y + 15, 580, y + 15);
        y += 25;
        tf.DrawString("Total", font_small, XBrushes.Black, new XRect(x + 220, y, 110, 125));
        tf.DrawString(cdQty.ToString(), font_small, XBrushes.Black, new XRect(x + 300, y, 110, 125));
        tf.DrawString(cdPrice.ToString(), font_small, XBrushes.Black, new XRect(x + 400, y, 110, 125));

        gfx.DrawLine(pen, 30, y + 15, 600, y + 15);
        i  = 0;
        y += 40;


        XRect rec_sm = new XRect(x, y, 200, 50);
        tf2.DrawString("Sheet Music", font, XBrushes.Black, rec_sm);
        gfx.DrawLine(pen, 30, y + 22, 600, y + 22);
        gfx.DrawLine(pen, 30, y + 36, 600, y + 36);
        XRect rec3 = new XRect(x, y + 22, 570, 15);
        gfx.DrawRectangle(new XSolidBrush(XColor.FromArgb(120, 204, 204, 204)), rec3);
        y += 20;

        tf2.DrawString("Article Code", font_small, XBrushes.Black, new XRect(x + 15, y + 5, 110, 100));
        tf.DrawString("Title", font_small, XBrushes.Black, new XRect(x + 70, y + 5, 110, 100));
        tf.DrawString("Quantity", font_small, XBrushes.Black, new XRect(x + 300, y + 5, 110, 100));
        tf.DrawString("Price", font_small, XBrushes.Black, new XRect(x + 400, y + 5, 110, 100));

        foreach (DataRow row in dt3.Rows)
        {
            y += 25;
            tf2.DrawString(dt3.Rows[i]["ArticleCode"].ToString(), font_small, XBrushes.Black, new XRect(x + 20, y, 110, 100));
            tf2.DrawString(dt3.Rows[i]["Title"].ToString(), font_small, XBrushes.Black, new XRect(x + 90, y, 300, 100));
            tf.DrawString(dt3.Rows[i]["Quantity"].ToString(), font_small, XBrushes.Black, new XRect(x + 300, y, 110, 100));
            tf.DrawString(dt3.Rows[i]["Price"].ToString(), font_small, XBrushes.Black, new XRect(x + 400, y, 110, 100));
            i++;
            if (gfx.PageSize.Height - y <= 100)
            {
                page          = document.AddPage();
                gfx           = XGraphics.FromPdfPage(page);
                tf            = new XTextFormatter(gfx);
                tf1           = new XTextFormatter(gfx);
                tf2           = new XTextFormatter(gfx);
                tf.Alignment  = XParagraphAlignment.Right;
                tf1.Alignment = XParagraphAlignment.Center;
                tf2.Alignment = XParagraphAlignment.Left;
                y             = 50;
                ++pageCount;
            }
        }

        gfx.DrawLine(totalPen, 380, y + 15, 580, y + 15);
        y += 25;
        tf.DrawString("Total", font_small, XBrushes.Black, new XRect(x + 220, y, 110, 125));
        tf.DrawString(sheetQty.ToString(), font_small, XBrushes.Black, new XRect(x + 300, y, 110, 125));
        tf.DrawString(sheetPrice.ToString(), font_small, XBrushes.Black, new XRect(x + 400, y, 110, 125));

        gfx.DrawLine(pen, 30, y + 15, 600, y + 15);
        MemoryStream sm = new MemoryStream();
        document.Save(sm, false);

        PdfDocument finalDoc  = PdfReader.Open(sm, PdfDocumentOpenMode.Import);
        PdfDocument outputDoc = new PdfDocument();
        for (int counter = 0; counter < document.Pages.Count; counter++)
        {
            PdfPage p = finalDoc.Pages[counter];
            outputDoc.AddPage(p);
            XGraphics xGraphics = XGraphics.FromPdfPage(outputDoc.Pages[counter]);

            tf            = new XTextFormatter(xGraphics);
            tf1           = new XTextFormatter(xGraphics);
            tf2           = new XTextFormatter(xGraphics);
            tf.Alignment  = XParagraphAlignment.Right;
            tf1.Alignment = XParagraphAlignment.Center;
            tf2.Alignment = XParagraphAlignment.Left;

            xGraphics.DrawString("Page " + (counter + 1) + " of " + pageCount + ".", font_small, XBrushes.Black, 30, xGraphics.PageSize.Height - 25);
            xGraphics.Dispose();
        }



        MemoryStream stream = new MemoryStream();
        //document.Save(stream, false);
        outputDoc.Save(stream, false);
        Response.Clear();
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-length", stream.Length.ToString());
        Response.BinaryWrite(stream.ToArray());
        Response.Flush();
        stream.Close();
        Response.End();
    }
예제 #22
0
        /// <summary>
        /// Traverse the form and writ the information to a Pdf Document.
        /// </summary>
        /// <param name="document">Pdf document to write to.</param>
        private void writeFormToPdf(PdfSharp.Pdf.PdfDocument document)
        {
            //define styles
            XFont header_style  = new XFont("Arial", 15, XFontStyle.Bold);
            XFont default_style = new XFont("Arial", 11, XFontStyle.Regular);
            XFont table_header  = new XFont("Arial", 12, XFontStyle.Bold);

            //header space before and after
            int header_space_before = 10;
            int header_space_after  = 5;

            //initialize the text variables
            XFont  font = default_style;
            double leftMargin = 40, topMargin = 20;

            //group header
            bool   group_header = true;
            bool   double_name  = false;
            string group_name   = "";

            //character size
            double text_size = 0;

            //space before or after styles
            double space_after = 0, space_before = 0;

            //text coordinates
            double x = 0, y = 0;

            //add first page to the document
            PdfPage   page = document.AddPage();
            XGraphics gfx  = XGraphics.FromPdfPage(page);

            XImage header = XImage.FromFile(Server.MapPath("~/Images/KinexusOrderFormHeader.jpeg"));
            XImage footer = XImage.FromFile(Server.MapPath("~/Images/KinexusOrderFormFooter.jpeg"));

            //draw the banner
            gfx.DrawImage(header, (page.Width / 2) - (header.Size.Width / 2), 0);

            /*
             * //draw the banner
             * gfx.DrawImage(header, (page.Width / 2) - (footer.PixelWidth * 46 / footer.HorizontalResolution) / 2, 0,
             * //size of the bannner with offset
             * footer.PixelWidth * 46 / footer.HorizontalResolution, footer.PixelHeight * 46 / footer.VerticalResolution);
             */

            //increment past the banner
            y += 100;

            //traverse the form and visit all controls
            foreach (Control c in Page.Form.Controls)
            {
                //control is a literal control
                if (c is LiteralControl)
                {
                    //skip it
                    continue;
                }

                //check if the control has an id and possible style tag
                if (c.ID != null && c.ID.Length >= 6)
                {
                    //get the style tag from the control id
                    string style_tag = c.ID.Substring(c.ID.Length - 6);

                    //if we get to a new group reset header
                    if (!group_header && !group_name.Equals(style_tag))
                    {
                        group_header = true;
                    }

                    //apply styles to or disable groups
                    switch (style_tag)
                    {
                    //apply style to header group
                    case "header":
                        font         = header_style;
                        space_before = header_space_before;
                        space_after  = header_space_after;
                        break;

                    //apply style to alternate address group
                    case "altadd":
                        //hide the group
                        if (ci_box_same_altadd.Checked)
                        {
                            continue;
                        }
                        //style the group
                        else
                        {
                            //apply a group header
                            if (group_header)
                            {
                                font         = header_style;
                                group_header = false;
                                group_name   = style_tag;
                                space_before = header_space_before;
                                space_after  = header_space_after;
                            }
                            //style for rest of group
                            else
                            {
                                font = default_style;
                            }
                        }

                        break;

                    //groups to skip
                    case "info":
                    case "survey":
                    case "hidden":
                        continue;

                    //default style
                    default:
                        font = default_style;
                        break;
                    }
                }

                //initilize the text variable
                string text = "";

                //if the control is a label
                if (c is Label)
                {
                    text      = ((Label)c).Text;
                    text_size = gfx.MeasureString(text, font).Height;
                    x         = 0;

                    //increment the line
                    y += text_size;

                    //apply space before style
                    y           += space_before;
                    space_before = 0;

                    //if another line will overflow the page create a new one
                    if (y + (text_size * 2) >= page.Height)
                    {
                        //create a new page
                        page = document.AddPage();
                        //get a graphics refence from the apge
                        gfx = XGraphics.FromPdfPage(page);
                        //reset the y position
                        y = 0 + topMargin;
                    }
                }
                //the control is of input type
                else
                {
                    //the control is a textbox
                    if (c is TextBox)
                    {
                        text = ((TextBox)c).Text;
                    }
                    //the contorl is a dropdown list
                    else if (c is DropDownList)
                    {
                        //set the text to the selected item
                        text = formatListItem(((DropDownList)c).Items[((DropDownList)c).SelectedIndex].Text.Trim());
                    }
                    //the control is a checkbox
                    else if (c is CheckBox)
                    {
                        //if the box is checked display a message, otherwise don't
                        text = ((CheckBox)c).Checked ? "x (checked)" : "";
                    }

                    //as long as string is not null
                    if (text.Length > 0)
                    {
                        //mesure the new size
                        text_size = gfx.MeasureString(text, font).Height;
                    }

                    //adjust the x position
                    x = page.Width / 2;
                }

                //if another line will fall in the margin
                if (y + (text_size * 4) >= page.Height)
                {
                    //create a new page
                    page = document.AddPage();
                    //get a graphics refence from the apge
                    gfx = XGraphics.FromPdfPage(page);
                    //reset the y position
                    y = 0 + topMargin;
                }

                //draw the text to the pdf
                gfx.DrawString(text, font, XBrushes.Black, new XRect(x + leftMargin, (y - text_size) + topMargin, page.Width, page.Height), XStringFormats.TopLeft);

                //apply space after style
                y          += space_after;
                space_after = 0;
            }

            //if the size of the table will overflow the page
            if (y + (text_size * 12) >= page.Height)
            {
                //create a new page
                page = document.AddPage();
                //get a graphics refence from the apge
                gfx = XGraphics.FromPdfPage(page);
                //reset the y position
                y = 0 + topMargin;
            }

            //set new margin for table
            leftMargin = 30;

            double subtotal = 0;

            //draw the requested products table from the post data
            for (int i = 1; i <= 10; i++)
            {
                //set up the header on the first run
                if (i == 1)
                {
                    //set the font to table header style
                    font = table_header;
                    //mesure the font size
                    text_size = gfx.MeasureString("Name:", font).Height;
                    //move down, leave some extra space above
                    y += 2 * text_size;
                    //reset the x position
                    x = 0;

                    //draw the name column header
                    gfx.DrawString("Name:", font, XBrushes.Black, new XRect(x + leftMargin, (y - text_size) + topMargin, page.Width, page.Height), XStringFormats.TopLeft);
                    //offset the drawing location
                    x += page.Width / 4;

                    //draw the id column header
                    gfx.DrawString("Id:", font, XBrushes.Black, new XRect(x + leftMargin, (y - text_size) + topMargin, page.Width, page.Height), XStringFormats.TopLeft);
                    //offset the drawing location
                    x += page.Width / 6;

                    //draw the amount column header
                    gfx.DrawString("Amount:", font, XBrushes.Black, new XRect(x + leftMargin, (y - text_size) + topMargin, page.Width, page.Height), XStringFormats.TopLeft);
                    //offset the drawing location
                    x += page.Width / 6;

                    //draw the price column header
                    gfx.DrawString("Price:", font, XBrushes.Black, new XRect(x + leftMargin, (y - text_size) + topMargin, page.Width, page.Height), XStringFormats.TopLeft);
                    //offset the drawing location
                    x += page.Width / 6;

                    //draw the cost column header
                    gfx.DrawString("Cost:", font, XBrushes.Black, new XRect(x + leftMargin, (y - text_size) + topMargin, page.Width, page.Height), XStringFormats.TopLeft);
                    //offset the drawing location
                    x += page.Width / 6;

                    //reset the style to the default style
                    font = default_style;
                }

                //the name field from the post data
                string name = Request.Form["prod_name" + i];
                //the id field from the post data
                string id = Request.Form["prod_id" + i];
                //the size field from the post data
                string size = Request.Form["prod_size" + i];
                //the amount field from the post data
                string amount = Request.Form["unit_number" + i];
                //the price field from the post data
                string price = Request.Form["unit_price" + i];
                //the cost field from the post data
                string cost = Request.Form["cost" + i];

                //if the cost is null or too short it invalidates the row
                if (cost == null || cost.Length < 2)
                {
                    //skip the row
                    continue;
                }

                //accumulate the total
                subtotal += Convert.ToDouble(cost.Substring(1));

                //calculate the size of the text
                text_size = gfx.MeasureString(name, font).Height;
                //reset the x position
                x = 0;
                //move the the page by the text size
                y += text_size;

                //the name needs be drawn over two lines
                if (gfx.MeasureString(name, font).Width > (page.Width / 5))         //splits up names that are greater size then page.Width / 5
                {
                    //draw the first line
                    gfx.DrawString(name.Substring(0, name.Length / 2), font, XBrushes.Black, new XRect(x + leftMargin, (y - text_size) + topMargin, page.Width, page.Height), XStringFormats.TopLeft);
                    y += text_size;

                    //draw the second line
                    gfx.DrawString(name.Substring(name.Length / 2), font, XBrushes.Black, new XRect(x + leftMargin, (y - text_size) + topMargin, page.Width, page.Height), XStringFormats.TopLeft);
                    y -= text_size;

                    //set that we need to offset for the second line
                    double_name = true;
                }
                //the name fits on one line
                else
                {
                    gfx.DrawString(name, font, XBrushes.Black, new XRect(x + leftMargin, (y - text_size) + topMargin, page.Width, page.Height), XStringFormats.TopLeft);
                }
                //offset the drawing location
                x += page.Width / 4;

                //draw the id data
                gfx.DrawString(id, font, XBrushes.Black, new XRect(x + leftMargin, (y - text_size) + topMargin, page.Width, page.Height), XStringFormats.TopLeft);
                //offset the drawing location
                x += page.Width / 6;

                //draw the amount data
                gfx.DrawString(amount, font, XBrushes.Black, new XRect(x + leftMargin, (y - text_size) + topMargin, page.Width, page.Height), XStringFormats.TopLeft);
                //offset the drawing location
                x += page.Width / 6;

                //draw the price data
                gfx.DrawString(price, font, XBrushes.Black, new XRect(x + leftMargin, (y - text_size) + topMargin, page.Width, page.Height), XStringFormats.TopLeft);
                //offset the drawing location
                x += page.Width / 6;

                //draw the cost data
                gfx.DrawString(cost, font, XBrushes.Black, new XRect(x + leftMargin, (y - text_size) + topMargin, page.Width, page.Height), XStringFormats.TopLeft);
                //offset the drawing location
                x += page.Width / 6;

                //if we have a name that is over two lines
                if (double_name)
                {
                    //account for the extra line of text
                    y += text_size;
                    //reset the flag
                    double_name = false;
                }
            }

            //adjust for the total
            y += text_size * 2;

            //set the width <-- approximate
            x = (3 * page.Width) / 4;

            //draw the total
            gfx.DrawString("Subtotal: $" + Convert.ToString(subtotal), font, XBrushes.Black, new XRect(x + leftMargin, (y - text_size) + topMargin, page.Width, page.Height), XStringFormats.TopLeft);

            text_size = gfx.MeasureString("Subtotal: $", font).Height;

            //leave some room after the subtotal line
            y += text_size * 5;

            //if only the banner will overflow we have to draw it on the next page..
            if ((y + footer.PixelHeight * 46 / footer.VerticalResolution) > page.Height)
            {
                //create a new page
                page = document.AddPage();
                //get a graphics refence from the apge
                gfx = XGraphics.FromPdfPage(page);
                //reset the y position
                y = 0 + topMargin;

                //draw the footer at the bottom of the page
                gfx.DrawImage(footer, (page.Width / 2) - (header.Size.Width / 2), page.Height - footer.Size.Height);

                /*
                 * //draw the footer at the bottom of the page
                 * gfx.DrawImage(footer, (page.Width / 2) - (footer.PixelWidth * 46 / footer.HorizontalResolution) / 2, page.Height - (footer.PixelHeight * 46 / footer.VerticalResolution),
                 *  //width, height with offset
                 * footer.PixelWidth * 46 / footer.HorizontalResolution, footer.PixelHeight * 46 / footer.VerticalResolution);
                 */
            }
            //banner will fit on the page
            else
            {
                //draw the footer at the bottom of the page
                gfx.DrawImage(footer, (page.Width / 2) - (header.Size.Width / 2), y);

                /*
                 * //draw the footer bottem of page
                 * gfx.DrawImage(footer, (page.Width / 2) - (footer.PixelWidth * 46 / footer.HorizontalResolution) / 2, y,
                 * //width, height with offset
                 * footer.PixelWidth * 46 / footer.HorizontalResolution, footer.PixelHeight * 46 / footer.VerticalResolution);
                 * */
            }
        }
예제 #23
0
        public void Generate(Teacher teacher, Payslip payslip, PayrollRecord payrollRecord, string filename)
        {
            var months = new string[] { "Janvier", "Février", "Mars", "Avril", "Mai", "Juin",
                                        "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre" };

            var template = PdfReader.Open("fiche_paie.pdf");

            var page = template.Pages[0];

            // Get an XGraphics object for drawing
            XGraphics gfx = XGraphics.FromPdfPage(page);

            // Create a font
            XFont titleFont  = new XFont("Calibri", 20, XFontStyle.Bold);
            XFont normalFont = new XFont("Calibri", 12);

            // Draw the text
            //gfx.DrawString("FICHE DE PAIE", titleFont, XBrushes.Black,
            //  new XRect(0, 0, page.Width, page.Height),
            //  XStringFormats.TopCenter);

            // Draw teacher info box
            //var teacherInfoRect = new XRect(50, 50, 150, 100);
            //XPen pen = new XPen(XColors.Black, 1);
            //gfx.DrawRectangle(pen, teacherInfoRect);



            // Draw Teacher info
            gfx.DrawString(teacher.Id.ToString(), normalFont, XBrushes.Black,
                           new XPoint(130, 114), XStringFormats.TopLeft);

            gfx.DrawString(teacher.CIN, normalFont, XBrushes.Black,
                           new XPoint(130, 129), XStringFormats.TopLeft);

            gfx.DrawString(teacher.FullName, normalFont, XBrushes.Black,
                           new XPoint(130, 144), XStringFormats.TopLeft);

            gfx.DrawString(teacher.Grade.ToString(), normalFont, XBrushes.Black,
                           new XPoint(130, 158), XStringFormats.TopLeft);

            gfx.DrawString(teacher.Status.ToString(), normalFont, XBrushes.Black,
                           new XPoint(130, 172), XStringFormats.TopLeft);

            gfx.DrawString(teacher.Speciality, normalFont, XBrushes.Black,
                           new XPoint(130, 188), XStringFormats.TopLeft);

            // Draw Payment info

            gfx.DrawString(months[payslip.Payment.PaymentDate.Month - 1] + " " + payslip.Payment.PaymentDate.Year, normalFont, XBrushes.Black,
                           new XPoint(382, 114), XStringFormats.TopLeft);

            gfx.DrawString(payslip.Payment.PaymentDate.ToString(), normalFont, XBrushes.Black,
                           new XPoint(382, 129), XStringFormats.TopLeft);

            gfx.DrawString(payslip.Payment.PaymentType.ToString(), normalFont, XBrushes.Black,
                           new XPoint(382, 144), XStringFormats.TopLeft);

            gfx.DrawString(payslip.Payment.Bank ?? "", normalFont, XBrushes.Black,
                           new XPoint(382, 158), XStringFormats.TopLeft);

            if (payslip.Payment.PaymentType == PaymentType.BankTransfer)
            {
                gfx.DrawString(payslip.Payment.Reference, normalFont, XBrushes.Black,
                               new XPoint(382, 172), XStringFormats.TopLeft);
            }
            else if (payslip.Payment.PaymentType == PaymentType.Check)
            {
                gfx.DrawString(payslip.Payment.Reference, normalFont, XBrushes.Black,
                               new XPoint(382, 188), XStringFormats.TopLeft);
            }

            // Draw payroll info
            gfx.DrawString(payrollRecord.HoursCount.ToString(), normalFont, XBrushes.Black,
                           new XPoint(36, 238), XStringFormats.TopLeft);

            gfx.DrawString(formatMoney(payrollRecord.Rate), normalFont, XBrushes.Black,
                           new XPoint(135, 238), XStringFormats.TopLeft);;

            gfx.DrawString(formatMoney(payrollRecord.GrossPay), normalFont, XBrushes.Black,
                           new XPoint(245, 238), XStringFormats.TopLeft);

            gfx.DrawString("15%", normalFont, XBrushes.Black,
                           new XPoint(350, 238), XStringFormats.TopLeft);

            gfx.DrawString(formatMoney(payrollRecord.Net), normalFont, XBrushes.Black,
                           new XPoint(447, 238), XStringFormats.TopLeft);

            // Draw total

            gfx.DrawString(formatMoney(payrollRecord.Net), normalFont, XBrushes.Black,
                           new XPoint(447, 636), XStringFormats.TopLeft);


            // Save the document...
            // const string filename = "HelloWorld.pdf";


            template.Save(filename);
            Process.Start(new ProcessStartInfo(/*Directory.GetCurrentDirectory() + "\\" +*/ filename)
            {
                UseShellExecute = true
            });

            // ...and start a viewer.
            //Process.Start(filename);
        }
예제 #24
0
        public static byte[] GenPDFFile(metka m_)
        {
            PdfDocument document = new PdfDocument();

            Zen.Barcode.Code128BarcodeDraw bc  = Zen.Barcode.BarcodeDrawFactory.Code128WithChecksum;
            Zen.Barcode.Code128BarcodeDraw bc1 = Zen.Barcode.BarcodeDrawFactory.Code128WithChecksum;
            double ilosc = 0;

            for (int i = 0; i < m_.il_stron; i++)
            {
                PdfPage page = document.AddPage();
                page.Size = PdfSharp.PageSize.A5;
                // Get an XGraphics object for drawing
                XGraphics gfx   = XGraphics.FromPdfPage(page);
                XFont     font  = new XFont("Verdana", 15, XFontStyle.BoldItalic);
                XFont     font1 = new XFont("Verdana", 10, XFontStyle.Regular);
                XFont     font2 = new XFont("Verdana", 15, XFontStyle.Regular);
                XFont     font3 = new XFont("Verdana", 8, XFontStyle.Regular);
                XFont     font4 = new XFont("Verdana", 8, XFontStyle.Italic);
                // kod kreskowy
                Image  im  = bc.Draw(m_.nr_zlec_galw.ToString(), 20, 2);
                XImage xim = XImage.FromGdiPlusImage(im);
                gfx.DrawImage(xim, new Point(20, 10));
                gfx.DrawString("Utw.: " + DateTime.Now.ToString(), font1, XBrushes.Black,
                               new XRect(210, 10, 300, 22),
                               XStringFormats.TopLeft);
                gfx.DrawString("Przez: " + m_.userid, font3, XBrushes.Black,
                               new XRect(210, 22, 300, 22),
                               XStringFormats.TopLeft);



                gfx.DrawString(m_.nazwa, font, XBrushes.Black,
                               new XRect(20, 40, 400, 22),
                               XStringFormats.TopLeft);


                gfx.DrawString(m_.kod_zlecenia + " (Kod zlecenia)", font1, XBrushes.Black,
                               new XRect(20, 65, 300, 22),
                               XStringFormats.TopLeft);
                gfx.DrawString(m_.kod_materialu_galw + " (Kod materialu)", font1, XBrushes.Black,
                               new XRect(20, 80, 300, 22),
                               XStringFormats.TopLeft);
                gfx.DrawString(m_.kolor, font2, XBrushes.Black,
                               new XRect(20, 95, 300, 22),
                               XStringFormats.TopLeft);



                gfx.DrawString("Ilość szt: " + m_.ilosc_szt[i].ToString(), font1, XBrushes.Black,
                               new XRect(255, 65, 300, 22),
                               XStringFormats.TopLeft);

                gfx.DrawString("Nr rysunku: " + m_.nr_rysunku, font1, XBrushes.Black,
                               new XRect(255, 80, 300, 22),
                               XStringFormats.TopLeft);
                gfx.DrawString("Zlec_IPO: " + m_.nr_zlec_galw, font1, XBrushes.Black,
                               new XRect(255, 95, 300, 22),
                               XStringFormats.TopLeft);


                baza_metekDataContext db1 = new baza_metekDataContext();
                var pow = from c in db1.GAL_POWIERZCHNIEs
                          where c.NR_RYS == m_.nr_rysunku && (bool)c.STATUS
                          select c;
                if (pow.Count() == 1)
                {
                    var pows = pow.Single();

                    gfx.DrawString("Pow: " + Math.Round((double)pows.POW, 3).ToString() + "(" + Math.Round(((double)pows.POW * m_.ilosc_szt[i]), 3).ToString() + ") dm2", font1, XBrushes.Black,
                                   new XRect(255, 110, 300, 22),
                                   XStringFormats.TopLeft);
                }

                gfx.DrawString("" + m_.komentarz, font4, XBrushes.Black,
                               new XRect(200, 125, 300, 22),
                               XStringFormats.TopLeft);

                ilosc = ilosc + m_.ilosc_szt[i];



                MemoryStream ms = new MemoryStream();
                m_.rysunek.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

                Image  n_rys    = System.Drawing.Image.FromStream(ms);
                double r_width  = 150;
                double ratio    = r_width / n_rys.Width;
                double r_height = (double)n_rys.Height * ratio;
                XImage rys      = XImage.FromGdiPlusImage(n_rys);

                gfx.DrawImage(rys, 15, 150, r_width, r_height);
                Image  im1  = bc.Draw("" + m_.nr_zlec_galw, 10, 2);
                XImage xim1 = XImage.FromGdiPlusImage(im1);
                gfx.DrawImage(xim1, new Point(15, 130));

                gfx.DrawString("  Belka   ,  il.szt", font4, XBrushes.Black,
                               new XRect(255, 140, 300, 22),
                               XStringFormats.TopLeft);


                XPen     pen    = new XPen(XColors.Black, 1);
                XPoint[] points = new XPoint[] { new XPoint(255, 150), new XPoint(355, 150), new XPoint(355, 190), new XPoint(255, 190), new XPoint(255, 150) };
                gfx.DrawLines(pen, points);

                points = new XPoint[] { new XPoint(355, 190), new XPoint(355, 230), new XPoint(255, 230), new XPoint(255, 190) };
                gfx.DrawLines(pen, points);
                points = new XPoint[] { new XPoint(355, 230), new XPoint(355, 270), new XPoint(255, 270), new XPoint(255, 230) };
                gfx.DrawLines(pen, points);
            }



            // Save the document...
            //string filename = "HelloWorld.pdf";
            MemoryStream str = new MemoryStream();

            document.Save(str, true);
            Metki_PDF m_pdf = new Metki_PDF();

            m_pdf.Nr_zlecenia = m_.nr_zlec_galw.ToString();
            m_pdf.Data_utw    = DateTime.Now;
            m_pdf.PDF         = str.ToArray();
            m_pdf.Ilosc       = (int)ilosc;
            baza_metekDataContext db = new baza_metekDataContext();

            db.Metki_PDFs.InsertOnSubmit(m_pdf);
            db.SubmitChanges();

            Metki_baza m = new Metki_baza();

            m.Data_utw    = DateTime.Now;
            m.Ilosc       = (int)m_.ilosc_szt[0];
            m.Nr_kodu     = m_.kod_zlecenia;
            m.Nr_zlecenia = m_.nr_zlec_galw.ToString();
            m.User_id     = "galwanika";
            db.Metki_bazas.InsertOnSubmit(m);
            db.SubmitChanges();

            return(str.ToArray());
        }
예제 #25
0
        public void CreatePDF(Sale sale)
        {
            // Her bruges classen pdfDocument.
            PdfDocument document = new PdfDocument();

            // Her laver jeg et pdf dokument og kalder det Faktura
            document.Info.Title = "Faktura";

            // Her laves en side
            PdfPage page = document.AddPage();

            // Get an XGraphics object for drawing
            XGraphics gfx = XGraphics.FromPdfPage(page);

            // Opret skrift størelse og stil
            XFont companyAndDebtor = new XFont("Calibri", 10, XFontStyle.Regular);
            XFont fakture          = new XFont("Calibri", 20, XFontStyle.Bold);
            XFont smallHeadLine    = new XFont("Calibri", 10, XFontStyle.Bold);
            XFont priceFat         = new XFont("Calibri", 10, XFontStyle.Bold);

            // Draw the text. Dette er hvad der skal være på teksten, og hvor det skal være. Der kan laves lige så mange som man vil
            //Kunde Oplysninger------------------------------------------------------------------------------------------------------------------------------
            if (sale.customer == null)
            {
            }
            else
            {
                gfx.DrawString((string)sale.customer.name, companyAndDebtor, XBrushes.Black,
                               new XRect(80, -270, page.Width, page.Height),
                               XStringFormats.CenterLeft);

                gfx.DrawString((string)sale.customer.address, companyAndDebtor, XBrushes.Black,
                               new XRect(80, -260, page.Width, page.Height),
                               XStringFormats.CenterLeft);

                gfx.DrawString((string)sale.customer.email, companyAndDebtor, XBrushes.Black,
                               new XRect(80, -250, page.Width, page.Height),
                               XStringFormats.CenterLeft);

                gfx.DrawString((string)sale.customer.phone, companyAndDebtor, XBrushes.Black,
                               new XRect(80, -230, page.Width, page.Height),
                               XStringFormats.CenterLeft);
            }

            //FAKTURA---------------------------------------------------------------------------------------------------------------------------------------
            gfx.DrawString("FAKTURA", fakture, XBrushes.Black,
                           new XRect(80, -170, page.Width, page.Height),
                           XStringFormats.CenterLeft);

            //Billede af Firmallogo---------------------------------------------------------------------------------------
            //Mangler


            //Firma informationer----------------------------------------------------------------------------------------------------------------------------
            gfx.DrawString("AnimalHouse", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -300, page.Width, page.Height),
                           XStringFormats.CenterRight);

            gfx.DrawString("Snudesvej 1", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -290, page.Width, page.Height),
                           XStringFormats.CenterRight);

            gfx.DrawString("7100 Vejle", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -280, page.Width, page.Height),
                           XStringFormats.CenterRight);


            //BankOplysninger------------------------------------------------------------------------------------------------------------------------------
            gfx.DrawString("Bank ", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -250, page.Width, page.Height),
                           XStringFormats.CenterRight);

            gfx.DrawString("Reg. Nr:3141", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -240, page.Width, page.Height),
                           XStringFormats.CenterRight);

            gfx.DrawString("Konto Nr:5926535897932384 ", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -230, page.Width, page.Height),
                           XStringFormats.CenterRight);

            gfx.DrawString("Ordrenummer " + sale.saleID.ToString(), companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -180, page.Width, page.Height),
                           XStringFormats.CenterRight);

            gfx.DrawString("Dato " + sale.salesDay.ToString("dd-MM-yyyy"), companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -170, page.Width, page.Height),
                           XStringFormats.CenterRight);

            //Navn på vare antal pris beløb-------------------------------------------------------------------------------------------------------------
            //varens navn
            gfx.DrawString("Vare", companyAndDebtor, XBrushes.Black,
                           new XRect(80, -130, page.Width, page.Height),
                           XStringFormats.CenterLeft);

            //Antal
            gfx.DrawString("Antal", companyAndDebtor, XBrushes.Black,
                           new XRect(-80, -130, page.Width, page.Height),
                           XStringFormats.Center);

            //Stykpris
            gfx.DrawString("Stykpris", companyAndDebtor, XBrushes.Black,
                           new XRect(90, -130, page.Width, page.Height),
                           XStringFormats.Center);

            //I alt
            gfx.DrawString("I alt", companyAndDebtor, XBrushes.Black,
                           new XRect(200, -130, page.Width, page.Height),
                           XStringFormats.Center);

            gfx.DrawString("___________________________________________________________________________________________ ", smallHeadLine, XBrushes.Black,
                           new XRect(80, -125, page.Width, page.Height),
                           XStringFormats.CenterLeft);

            int lineSpace = 0;

            for (int i = 0; i < sale.saleLineItems.Count; i++)
            {
                //Her bliver Variablen sat til 15. så hver gange der bliver kørt GetLeaseOrders(tilføjet en ny vare linje bliver der pludset 15 til y aksens position)
                lineSpace = 15 * i;

                //varens navn
                gfx.DrawString((string)sale.saleLineItems[i].item.name, companyAndDebtor, XBrushes.Black,
                               new XRect(80, -110 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterLeft);

                //Antal
                gfx.DrawString(sale.saleLineItems[i].amount.ToString(), companyAndDebtor, XBrushes.Black,
                               new XRect(-80, -110 + lineSpace, page.Width, page.Height),
                               XStringFormats.Center);

                //Stykpris
                gfx.DrawString((sale.saleLineItems[i].price.ToString() + " Kr"), companyAndDebtor, XBrushes.Black,
                               new XRect(90, -110 + lineSpace, page.Width, page.Height),
                               XStringFormats.Center);

                //I alt
                decimal priceSum = sale.Price();
                gfx.DrawString((priceSum.ToString() + " Kr"), companyAndDebtor, XBrushes.Black,
                               new XRect(200, -110 + lineSpace, page.Width, page.Height),
                               XStringFormats.Center);
            }

            //Hvis det er erhvers person
            if (sale.customer != null)
            {
                if (sale.customer.GetType() == typeof(BusinessCustomer))
                {
                    gfx.DrawString("Total: ", priceFat, XBrushes.Black,
                                   new XRect(400, -20 + lineSpace, page.Width, page.Height),
                                   XStringFormats.CenterLeft);



                    gfx.DrawString(sale.Price() + " Kr", companyAndDebtor, XBrushes.Black,
                                   new XRect(-60, -20 + lineSpace, page.Width, page.Height),
                                   XStringFormats.CenterRight);

                    gfx.DrawString("___________________________ ", smallHeadLine, XBrushes.Black,
                                   new XRect(400, -15 + lineSpace, page.Width, page.Height),
                                   XStringFormats.CenterLeft);
                }

                else
                {
                    decimal momsPrice         = sale.Moms();
                    decimal totalPriceInkMoms = sale.TotalPriceInkMoms();

                    gfx.DrawString("Netto: ", companyAndDebtor, XBrushes.Black,
                                   new XRect(400, -20 + lineSpace, page.Width, page.Height),
                                   XStringFormats.CenterLeft);

                    gfx.DrawString("Moms (25%): ", companyAndDebtor, XBrushes.Black,
                                   new XRect(400, -5 + lineSpace, page.Width, page.Height),
                                   XStringFormats.CenterLeft);

                    gfx.DrawString("Total ink. Moms: ", priceFat, XBrushes.Black,
                                   new XRect(400, 10 + lineSpace, page.Width, page.Height),
                                   XStringFormats.CenterLeft);

                    //Viser den totate nettopris
                    gfx.DrawString(sale.Price() + " Kr", companyAndDebtor, XBrushes.Black,
                                   new XRect(-60, -20 + lineSpace, page.Width, page.Height),
                                   XStringFormats.CenterRight);

                    //Viser prisen på momsen
                    gfx.DrawString(momsPrice.ToString() + " Kr", companyAndDebtor, XBrushes.Black,
                                   new XRect(-60, -5 + lineSpace, page.Width, page.Height),
                                   XStringFormats.CenterRight);


                    //viser den totale pris ink moms
                    gfx.DrawString(totalPriceInkMoms.ToString() + " Kr", priceFat, XBrushes.Black,
                                   new XRect(-60, 10 + lineSpace, page.Width, page.Height),
                                   XStringFormats.CenterRight);

                    gfx.DrawString("___________________________ ", smallHeadLine, XBrushes.Black,
                                   new XRect(400, 15 + lineSpace, page.Width, page.Height),
                                   XStringFormats.CenterLeft);
                }
            }
            else
            {
                decimal momsPrice         = sale.Moms();
                decimal totalPriceInkMoms = sale.TotalPriceInkMoms();

                gfx.DrawString("Netto: ", companyAndDebtor, XBrushes.Black,
                               new XRect(400, -20 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterLeft);

                gfx.DrawString("Moms (25%): ", companyAndDebtor, XBrushes.Black,
                               new XRect(400, -5 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterLeft);

                gfx.DrawString("Total ink. Moms: ", priceFat, XBrushes.Black,
                               new XRect(400, 10 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterLeft);

                //Viser den totate nettopris
                gfx.DrawString(sale.Price() + " Kr", companyAndDebtor, XBrushes.Black,
                               new XRect(-60, -20 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterRight);

                //Viser prisen på momsen
                gfx.DrawString(momsPrice.ToString() + " Kr", companyAndDebtor, XBrushes.Black,
                               new XRect(-60, -5 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterRight);


                //viser den totale pris ink moms
                gfx.DrawString(totalPriceInkMoms.ToString() + " Kr", priceFat, XBrushes.Black,
                               new XRect(-60, 10 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterRight);

                gfx.DrawString("___________________________ ", smallHeadLine, XBrushes.Black,
                               new XRect(400, 15 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterLeft);
            }

            gfx.DrawString("___________________________________________________________________________________________ ", smallHeadLine, XBrushes.Black,
                           new XRect(80, -100 + lineSpace, page.Width, page.Height),
                           XStringFormats.CenterLeft);

            //Her Laves navnet på filen
            string filename = "Faktura" + sale.saleID.ToString() + ".pdf";

            //Dette er til at gemme pdf
            document.Save(filename);
        }
예제 #26
0
        public static byte[] GenPDFFile_A4_new(metka m_)
        {
            PdfDocument document = new PdfDocument();

            Zen.Barcode.Code128BarcodeDraw bc  = Zen.Barcode.BarcodeDrawFactory.Code128WithChecksum;
            Zen.Barcode.Code128BarcodeDraw bc1 = Zen.Barcode.BarcodeDrawFactory.Code128WithChecksum;
            DB2DataContext db2 = new DB2DataContext();

            bool tylko_poler_wyk = false;// m_.komentarz.Contains("!!");


            int ilosc = 0;

            for (int i = 0; i < m_.il_stron; i++)
            {
                PdfPage page = document.AddPage();
                page.Size = PdfSharp.PageSize.A4;
                // Get an XGraphics object for drawing
                XGraphics gfx   = XGraphics.FromPdfPage(page);
                XFont     font  = new XFont("Verdana", 15, XFontStyle.Bold);
                XFont     font1 = new XFont("Verdana", 10, XFontStyle.Regular);
                XFont     font2 = new XFont("Verdana", 8, XFontStyle.Regular);
                XFont     font3 = new XFont("Verdana", 8, XFontStyle.Italic);

                // kod kreskowy
                Image  im  = bc.Draw(m_.nr_zlec_szlif + "_" + (i + 1).ToString(), 35, 2);
                XImage xim = XImage.FromGdiPlusImage(im);
                gfx.DrawImage(xim, new Point(10, 10));
                gfx.DrawString("Utw.: " + DateTime.Now.ToString(), font1, XBrushes.Black,
                               new XRect(210, 10, 300, 22),
                               XStringFormats.TopLeft);



                gfx.DrawString(m_.nazwa, font, XBrushes.Black,
                               new XRect(5, 40, 400, 22),
                               XStringFormats.Center);



                gfx.DrawString("Kod części: " + m_.kod_zlecenia + " (partia nr " + (i + 1).ToString() + " z " + m_.il_stron.ToString() + ")", font1, XBrushes.Black,
                               new XRect(5, 65, 300, 22),
                               XStringFormats.TopLeft);
                gfx.DrawString("Ilość szt: " + m_.ilosc_szt[i].ToString(), font1, XBrushes.Black,
                               new XRect(240, 65, 300, 22),
                               XStringFormats.TopLeft);
                ilosc = (int)m_.ilosc_szt[0];
                gfx.DrawString("Nr rysunku: " + m_.nr_rysunku, font1, XBrushes.Black,
                               new XRect(5, 80, 300, 22),
                               XStringFormats.TopLeft);



                //gfx.DrawString("Kod po wykonczeniu: " + m_.kod_po_wykonczeniu, font1, XBrushes.Black,
                //  new XRect(5, 95, 300, 22),
                // XStringFormats.TopLeft);
                gfx.DrawString("Kolor: " + m_.kolor, font1, XBrushes.Black,
                               new XRect(240, 75, 300, 22),
                               XStringFormats.TopLeft);
                gfx.DrawString("Nr_zlec: " + m_.nr_zlec_szlif, font1, XBrushes.Black,
                               new XRect(240, 95, 300, 22),
                               XStringFormats.TopLeft);

                var rw = from c in db2.IPO_ZDAWKA_PW
                         where c.RW_PW == "RW" && c.Nr_zlecenia_IPO == m_.nr_zlec_szlif
                         group c by new { c.Magazyn_IPO, c.Nr_indeksu } into fgr

                    select new { Magazyn_IPO = fgr.Key.Magazyn_IPO, Nr_indeksu = fgr.Key.Nr_indeksu, Ilosc = fgr.Sum(g => g.Ilosc) };
                int poz = 105;
                foreach (var d in rw.Where(c => c.Ilosc != 0))
                {
                    gfx.DrawString(d.Magazyn_IPO + " " + d.Nr_indeksu + " :" + d.Ilosc.ToString(), font1, XBrushes.Black,
                                   new XRect(240, poz, 300, 22),
                                   XStringFormats.TopLeft);



                    poz = poz + 10;
                }



                double st = 170;
                szlif_operacjeDataContext db1 = new szlif_operacjeDataContext();
                var oper = from c in db1.Marszruty_szlifiernia_s
                           where c.Id_wyrobu == m_.kod_zlecenia
                           orderby c.Nr_kol_operacji ascending
                           select new { c.Id_operacji, OPERACJA = c.Id_operacji + " " + c.Nazwa_operacji, c.IloscSztZm, c.NormaZatwierdzona, c.Nazwa_operacji, c.Nr_kol_operacji };

                if (tylko_poler_wyk)
                {
                    oper = oper.Where(x => x.Nazwa_operacji == "Polerowanie wykańczające");
                }
                else
                {
                    oper = oper.Where(x => x.Nazwa_operacji != "Polerowanie wykańczające");
                }

                foreach (var o in oper)
                {
                    string wst = "";

                    if (o.NormaZatwierdzona.Contains("*"))
                    {
                        wst = "*";
                    }
                    if (!o.Nr_kol_operacji.Value.ToString().EndsWith("0"))
                    {
                        wst = "A" + wst;                                                     //operacja nie kończy się na zero - to alternatywa!!!
                    }
                    //jeżeli wst zawiera A to drukuj pochyłą czcionką
                    if (wst.Contains("A"))
                    {
                        gfx.DrawString(wst + o.OPERACJA, font3, XBrushes.Black,
                                       new XRect(240, st, 300, 22),
                                       XStringFormats.TopLeft);
                    }
                    //lub normalną jeżeli nie alternatywna
                    else
                    {
                        gfx.DrawString(wst + o.OPERACJA, font2, XBrushes.Black,
                                       new XRect(240, st, 300, 22),
                                       XStringFormats.TopLeft);
                    }


                    im  = bc1.Draw("OPER_" + o.Id_operacji.ToString(), 15, 2);
                    xim = XImage.FromGdiPlusImage(im);
                    gfx.DrawImage(xim, new Point(230, (int)(st + 15)));
                    gfx.DrawString(((decimal)((decimal)m_.ilosc_szt[i] * 480m) / (decimal)o.IloscSztZm).ToString("####.#") + "/" + o.IloscSztZm.ToString(), font1, XBrushes.Black,
                                   new XRect(240, st + 26, 300, 22),
                                   XStringFormats.TopLeft);
                    st = st + 55;
                }


                MemoryStream ms = new MemoryStream();
                m_.rysunek.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

                Image  n_rys    = System.Drawing.Image.FromStream(ms);
                double r_width  = 150;
                double ratio    = r_width / n_rys.Width;
                double r_height = (double)n_rys.Height * ratio;
                XImage rys      = XImage.FromGdiPlusImage(n_rys);

                gfx.DrawImage(rys, 10, 130, r_width, r_height);
                Image  im1  = bc.Draw(m_.kod_zlecenia, 20, 3);
                XImage xim1 = XImage.FromGdiPlusImage(im1);
                gfx.DrawImage(xim1, new Point(15, 150 + (int)r_height));
            }



            // Save the document...
            //string filename = "HelloWorld.pdf";
            MemoryStream str = new MemoryStream();

            document.Save(str, true);
            Metki_PDF m_pdf = new Metki_PDF();

            m_pdf.Nr_zlecenia = m_.nr_zlec_szlif.ToString();
            m_pdf.Data_utw    = DateTime.Now;
            m_pdf.PDF         = str.ToArray();
            m_pdf.Ilosc       = ilosc;
            baza_metekDataContext db = new baza_metekDataContext();

            db.Metki_PDFs.InsertOnSubmit(m_pdf);
            db.SubmitChanges();


            return(str.ToArray());
        }
예제 #27
0
        /// <summary>
        /// Draws the vertical Y axis.
        /// </summary>
        internal override void Draw()
        {
            AxisRendererInfo yari = ((ChartRendererInfo)_rendererParms.RendererInfo).yAxisRendererInfo;

            double yMin       = yari.MinimumScale;
            double yMax       = yari.MaximumScale;
            double yMajorTick = yari.MajorTick;
            double yMinorTick = yari.MinorTick;

            XMatrix matrix = new XMatrix();

            matrix.TranslatePrepend(-yari.InnerRect.X, yMax);
            matrix.Scale(1, yari.InnerRect.Height / (yMax - yMin), XMatrixOrder.Append);
            matrix.ScalePrepend(1, -1); // mirror horizontal
            matrix.Translate(yari.InnerRect.X, yari.InnerRect.Y, XMatrixOrder.Append);

            // Draw axis.
            // First draw tick marks, second draw axis.
            double majorTickMarkStart = 0, majorTickMarkEnd = 0,
                   minorTickMarkStart = 0, minorTickMarkEnd = 0;

            GetTickMarkPos(yari, ref majorTickMarkStart, ref majorTickMarkEnd, ref minorTickMarkStart, ref minorTickMarkEnd);

            XGraphics          gfx                     = _rendererParms.Graphics;
            LineFormatRenderer lineFormatRenderer      = new LineFormatRenderer(gfx, yari.LineFormat);
            LineFormatRenderer minorTickMarkLineFormat = new LineFormatRenderer(gfx, yari.MinorTickMarkLineFormat);
            LineFormatRenderer majorTickMarkLineFormat = new LineFormatRenderer(gfx, yari.MajorTickMarkLineFormat);

            XPoint[] points = new XPoint[2];

            // Draw minor tick marks.
            if (yari.MinorTickMark != TickMarkType.None)
            {
                for (double y = yMin + yMinorTick; y < yMax; y += yMinorTick)
                {
                    points[0].X = minorTickMarkStart;
                    points[0].Y = y;
                    points[1].X = minorTickMarkEnd;
                    points[1].Y = y;
                    matrix.TransformPoints(points);
                    minorTickMarkLineFormat.DrawLine(points[0], points[1]);
                }
            }

            double lineSpace = yari.TickLabelsFont.GetHeight(); // old: yari.TickLabelsFont.GetHeight(gfx);
            int    cellSpace = yari.TickLabelsFont.FontFamily.GetLineSpacing(yari.TickLabelsFont.Style);
            double xHeight   = yari.TickLabelsFont.Metrics.XHeight;

            XSize labelSize = new XSize(0, 0);

            labelSize.Height = lineSpace * xHeight / cellSpace;

            int countTickLabels = (int)((yMax - yMin) / yMajorTick) + 1;

            for (int i = 0; i < countTickLabels; ++i)
            {
                double y   = yMin + yMajorTick * i;
                string str = y.ToString(yari.TickLabelsFormat);

                labelSize.Width = gfx.MeasureString(str, yari.TickLabelsFont).Width;

                // Draw major tick marks.
                if (yari.MajorTickMark != TickMarkType.None)
                {
                    labelSize.Width += yari.MajorTickMarkWidth * 1.5;
                    points[0].X      = majorTickMarkStart;
                    points[0].Y      = y;
                    points[1].X      = majorTickMarkEnd;
                    points[1].Y      = y;
                    matrix.TransformPoints(points);
                    majorTickMarkLineFormat.DrawLine(points[0], points[1]);
                }
                else
                {
                    labelSize.Width += SpaceBetweenLabelAndTickmark;
                }

                // Draw label text.
                XPoint[] layoutText = new XPoint[1];
                layoutText[0].X = yari.InnerRect.X + yari.InnerRect.Width - labelSize.Width;
                layoutText[0].Y = y;
                matrix.TransformPoints(layoutText);
                layoutText[0].Y += labelSize.Height / 2; // Center text vertically.
                gfx.DrawString(str, yari.TickLabelsFont, yari.TickLabelsBrush, layoutText[0]);
            }

            // Draw axis.
            if (yari.LineFormat != null && yari.LineFormat.Width > 0)
            {
                points[0].X = yari.InnerRect.X + yari.InnerRect.Width;
                points[0].Y = yMin;
                points[1].X = yari.InnerRect.X + yari.InnerRect.Width;
                points[1].Y = yMax;
                matrix.TransformPoints(points);
                if (yari.MajorTickMark != TickMarkType.None)
                {
                    // yMax is at the upper side of the axis
                    points[1].Y -= yari.LineFormat.Width / 2;
                    points[0].Y += yari.LineFormat.Width / 2;
                }
                lineFormatRenderer.DrawLine(points[0], points[1]);
            }

            // Draw axis title
            if (yari._axisTitleRendererInfo != null && yari._axisTitleRendererInfo.AxisTitleText != "")
            {
                RendererParameters parms = new RendererParameters();
                parms.Graphics     = gfx;
                parms.RendererInfo = yari;
                double width = yari._axisTitleRendererInfo.Width;
                yari._axisTitleRendererInfo.Rect  = yari.InnerRect;
                yari._axisTitleRendererInfo.Width = width;
                AxisTitleRenderer atr = new AxisTitleRenderer(parms);
                atr.Draw();
            }
        }
예제 #28
0
 private static void Println(string s, XGraphics gfx)
 {
     gfx.DrawString(s, font, XBrushes.Black, x, y);
     y += lineHeight;
 }
예제 #29
0
        /// <summary>
        /// Renders a single paragraph.
        /// </summary>
        void GenerateReport(PdfDocument document)
        {
            //PdfPage page = document.AddPage();
            PdfPage page = document.Pages[0];

            XGraphics gfx = XGraphics.FromPdfPage(page);

            // HACK²
            gfx.MUH  = PdfFontEncoding.Unicode;
            gfx.MFEH = PdfFontEmbedding.Default;

            XFont font = new XFont("Verdana", 4, XFontStyle.Regular);



            // map image origin
            //gfx.DrawString("O", font, XBrushes.Red, new XRect(5, 5, 108, 161), XStringFormats.Center);


            // ovmap image origin
            //gfx.DrawString("X", font, XBrushes.Red, new XRect(5, 5, 798, 1144), XStringFormats.Center);



            //gfx.DrawString("+", font, XBrushes.Red, new XRect(5, 5, 100, 1299), XStringFormats.Center);



            //XImage ximg = XImage.FromFile(mapImagePth);
            XImage ximg = XImage.FromGdiPlusImage(mimg);

            //ximg.Interpolate = true;
            Point ipt = new Point(58, 86);

            //gfx.SmoothingMode = XSmoothingMode.HighQuality;
            gfx.DrawImage(ximg, ipt);



            //gfx.DrawImage(ximg, ipt.X, ipt.Y, ApplyTransform(ximg.PointWidth), ApplyTransform(ximg.PointHeight));


            /*
             * XImage ximg_ov = XImage.FromFile(ovmapImagePth);
             * Point ov_ipt = new Point(398, 580);
             * gfx.DrawImage(ximg_ov, ov_ipt);
             */

            //String ovmapImageTPth = @"C:\inetpub\wwwroot\ms6\output\ov\ov13_mxd_a.png";

            /*
             * XImage ximg_ov = XImage.FromFile(ovmapImagePth);
             *
             * Point ov_ipt = new Point(408, 570);
             * //gfx.DrawImage(ximg_ov, ov_ipt);
             * gfx.DrawImage(ximg_ov, ov_ipt.X, ov_ipt.Y,97,130);
             */
            /*
             * double rminx = 1218342.661;
             * double rminy = 500202.9879;
             * double rmaxx = 1397365.953;
             * double rmaxy = 738900.7105;
             * double rxw = 179023.292;
             * double rxh = 238697.7226;
             * double img_width = 97.0;
             * double img_height = 130.0;
             */
            double rminx      = 1232659.28962;
            double rminy      = 498047.976697;
            double rmaxx      = 1390211.37295;
            double rmaxy      = 739801.448919;
            double rxw        = 157552.0833;
            double rxh        = 241753.4722;
            double img_width  = 87;
            double img_height = 133;
            double qx         = minx + ((maxx - minx) / 2.0);
            double qy         = miny + ((maxy - miny) / 2.0);

            double pct_x = (qx - rminx) / rxw;
            double pct_y = (qy - rminy) / rxh;

            double px_x = pct_x * img_width;
            double px_y = (1.0 - pct_y) * img_height;

            double ul_px = ((minx - rminx) / rxw) * img_width;
            double ul_py = (1.0 - ((maxy - rminy) / rxh)) * img_height;

            double qwidth_pct = (maxx - minx) / (rmaxx - rminx);
            double qhght_pct  = (maxy - miny) / (rmaxy - rminy);

            double px_width = qwidth_pct * img_width;
            double px_hgt   = qhght_pct * img_height;


            //Debug.Print(String.Format("qx/qy: {0}  {1}    pct_x/pct_y: {2}  {3}   px_x/px_y:  {4}  {5} ", qx, qy, pct_x, pct_y, px_x, px_y));



            // option #1 - using graphics object directly on image
            Image ovImg = Image.FromFile(ovmapImageTPth);

            using (Graphics g = Graphics.FromImage(ovImg))
            {
                Pen myPen = new Pen(System.Drawing.Color.Red, 5);
                System.Drawing.Font myFont = new System.Drawing.Font("Helvetica", 15, FontStyle.Bold);
                Brush myBrush = new SolidBrush(System.Drawing.Color.Red);
                g.DrawString("x", myFont, myBrush, new PointF((float)px_x, (float)px_y));
                g.DrawRectangle(myPen, (float)ul_px, (float)ul_py, (float)px_width, (float)px_hgt);
            }

            ovImg.Save(ovmapImagePth);
            XImage ximg_ov = XImage.FromFile(ovmapImagePth);



            XImage ximgn = XImage.FromFile(northimgpth);

            //ximg.Interpolate = true;
            Point iptn = new Point(520, 570);

            //gfx.SmoothingMode = XSmoothingMode.HighQuality;
            gfx.DrawImage(ximgn, iptn);



            Point ov_ipt = new Point(400, 570);
            //gfx.DrawImage(ximg_ov, ov_ipt);

            //gfx.DrawImage(ximg_ov, ov_ipt.X, ov_ipt.Y, 97, 130);

            RectangleF srcR  = new RectangleF(0, 0, (int)img_width, (int)img_height);
            RectangleF destR = new RectangleF(ov_ipt.X, ov_ipt.Y, (int)img_width, (int)img_height);

            gfx.DrawImage(ximg_ov, destR, srcR, XGraphicsUnit.Point);

            // option #2 - using pdf object directly on report



            // XPen peno = new XPen(XColors.Aqua, 0.5);

            //gfx.DrawRectangle(peno, 408, 570,  95,  128);

            //peno = new XPen(XColors.DodgerBlue, 0.5);

            //gfx.DrawRectangle(peno, 354, 570, 200, 128);



            XPen pen = new XPen(XColors.Black, 0.5);

            gfx.DrawRectangle(pen, 29, 59, 555, 643);


            XPen pen2 = new XPen(XColors.Black, 0.8);

            gfx.DrawRectangle(pen, 29, 566, 555, 136);


            XPen   pen3  = new XPen(XColors.HotPink, 0.5);
            XBrush brush = XBrushes.LightPink;

            gfx.DrawRectangle(pen, brush, 29, 705, 555, 43);



            Document doc = new Document();



            // You always need a MigraDoc document for rendering.

            Section sec = doc.AddSection();
            // Add a single paragraph with some text and format information.
            Paragraph para = sec.AddParagraph();

            para.Format.Alignment  = ParagraphAlignment.Justify;
            para.Format.Font.Name  = "Verdana";
            para.Format.Font.Size  = Unit.FromPoint(6);
            para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray;
            para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray;
            //para.AddText("Duisism odigna acipsum delesenisl ");
            //para.AddFormattedText("ullum in velenit", TextFormat.Bold);

            para.AddText("Okaloosa County makes every effort to produce the most accurate information possible. No warranties, expressed or implied, are provided for the data herein, its use or interpretation. The assessment information is from the last certified taxroll. All data is subject to change before the next certified taxroll. PLEASE NOTE THAT THE GIS MAPS ARE FOR ASSESSMENT PURPOSES ONLY NEITHER OKALOOSA COUNTY NOR ITS EMPLOYEES ASSUME RESPONSIBILITY FOR ERRORS OR OMISSIONS ---THIS IS NOT A SURVEY---");


            //para.Format.Borders.Distance = "1pt";
            //para.Format.Borders.Color = Colors.Orange;

            // Create a renderer and prepare (=layout) the document
            MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc);
            docRenderer.PrepareDocument();

            // Render the paragraph. You can render tables or shapes the same way.  29, 705, 555, 43
            docRenderer.RenderObject(gfx, XUnit.FromPoint(38), XUnit.FromPoint(710), XUnit.FromPoint(535), para);



            Section section = doc.AddSection();



            MigraDoc.DocumentObjectModel.Tables.Table table = section.AddTable();
            table.Style         = "Table";
            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     = 0;
            table.Format.Font.Name    = "Verdana";
            table.Format.Font.Size    = Unit.FromPoint(6);
            table.Rows.Height         = Unit.FromInch(0.203);

            /*
             * // Before you can add a row, you must define the columns
             * Column column = table.AddColumn("1cm");
             * column.Format.Alignment = ParagraphAlignment.Center;
             *
             * column = table.AddColumn("2.5cm");
             * column.Format.Alignment = ParagraphAlignment.Right;
             *
             * column = table.AddColumn("3cm");
             * column.Format.Alignment = ParagraphAlignment.Right;
             *
             * column = table.AddColumn("3.5cm");
             * column.Format.Alignment = ParagraphAlignment.Right;
             *
             * column = table.AddColumn("2cm");
             * column.Format.Alignment = ParagraphAlignment.Center;
             *
             * column = table.AddColumn("4cm");
             * column.Format.Alignment = ParagraphAlignment.Right;
             *
             * // 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 = MigraDoc.DocumentObjectModel.Colors.Blue;
             * row.Cells[0].AddParagraph("Item");
             * row.Cells[0].Format.Font.Bold = false;
             * row.Cells[0].Format.Alignment = ParagraphAlignment.Left;
             * row.Cells[0].VerticalAlignment = VerticalAlignment.Bottom;
             * row.Cells[0].MergeDown = 1;
             * row.Cells[1].AddParagraph("Title and Author");
             * row.Cells[1].Format.Alignment = ParagraphAlignment.Left;
             * row.Cells[1].MergeRight = 3;
             * row.Cells[5].AddParagraph("Extended Price");
             * row.Cells[5].Format.Alignment = ParagraphAlignment.Left;
             * row.Cells[5].VerticalAlignment = VerticalAlignment.Bottom;
             * row.Cells[5].MergeDown = 1;
             *
             *
             * row = table.AddRow();
             * row.HeadingFormat = true;
             * row.Format.Alignment = ParagraphAlignment.Center;
             * row.Format.Font.Bold = true;
             * row.Shading.Color = MigraDoc.DocumentObjectModel.Colors.BlueViolet;
             * row.Cells[1].AddParagraph("Quantity");
             * row.Cells[1].Format.Alignment = ParagraphAlignment.Left;
             * row.Cells[2].AddParagraph("Unit Price");
             * row.Cells[2].Format.Alignment = ParagraphAlignment.Left;
             * row.Cells[3].AddParagraph("Discount (%)");
             * row.Cells[3].Format.Alignment = ParagraphAlignment.Left;
             * row.Cells[4].AddParagraph("Taxable");
             * row.Cells[4].Format.Alignment = ParagraphAlignment.Left;
             */


            Column column = table.AddColumn(Unit.FromInch(0.31));

            column.Format.Alignment = ParagraphAlignment.Center;

            column = table.AddColumn(Unit.FromInch(2.0));
            column.Format.Alignment = ParagraphAlignment.Right;

            column = table.AddColumn(Unit.FromInch(0.8));
            column.Format.Alignment = ParagraphAlignment.Right;

            column = table.AddColumn(Unit.FromInch(1.0));
            column.Format.Alignment = ParagraphAlignment.Right;

            Row row = table.AddRow();

            row.HeadingFormat    = true;
            row.Format.Alignment = ParagraphAlignment.Center;
            row.Format.Font.Bold = true;
            row.Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[0].AddParagraph("Okaloosa County Property Appraiser  -  2013 Certified Values");
            row.Cells[0].Format.Font.Bold  = false;
            row.Cells[0].Format.Alignment  = ParagraphAlignment.Center;
            row.Cells[0].VerticalAlignment = VerticalAlignment.Center;
            row.Cells[0].MergeRight        = 3;

            row = table.AddRow();
            row.Shading.Color = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[0].AddParagraph("Parcel: " + obCama.pinstr);
            row.Cells[0].Format.Font.Bold  = false;
            row.Cells[0].Format.Alignment  = ParagraphAlignment.Left;
            row.Cells[0].VerticalAlignment = VerticalAlignment.Center;
            row.Cells[0].MergeRight        = 3;


            row = table.AddRow();
            row.Cells[0].Shading.Color = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[0].AddParagraph("Name");
            row.Cells[0].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[1].AddParagraph(obCama.owner);
            row.Cells[1].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[1].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[2].AddParagraph("Land Value:");
            row.Cells[2].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[2].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[3].AddParagraph("$" + String.Format("{0:#,#######0}", obCama.landval));
            row.Cells[3].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[3].Format.Alignment = ParagraphAlignment.Left;



            row = table.AddRow();
            row.Cells[0].Shading.Color = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[0].AddParagraph("Site");
            row.Cells[0].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[1].AddParagraph(obCama.site_addr);
            row.Cells[1].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[1].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[2].AddParagraph("Building Value");
            row.Cells[2].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[2].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[3].AddParagraph("$" + String.Format("{0:#,#######0}", obCama.bldval));
            row.Cells[3].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[3].Format.Alignment = ParagraphAlignment.Left;



            row = table.AddRow();
            row.Cells[0].Shading.Color = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[0].AddParagraph("Sale");
            row.Cells[0].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[1].AddParagraph(obCama.sale_info);
            row.Cells[1].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[1].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[2].AddParagraph("Misc Value");
            row.Cells[2].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[2].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[3].AddParagraph("$" + String.Format("{0:#,#######0}", obCama.miscval));
            row.Cells[3].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[3].Format.Alignment = ParagraphAlignment.Left;


            row = table.AddRow();
            row.Cells[0].Shading.Color = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[0].AddParagraph("\nMail\n");
            row.Cells[0].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[0].MergeDown = 3;

            //row.Cells[1].AddParagraph(obCama.mail_addr);
            row.Cells[1].AddParagraph(obCama.mail_addr_1);
            row.Cells[1].AddParagraph(obCama.mail_addr_2);

            row.Cells[1].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[1].Format.Alignment = ParagraphAlignment.Left;
            row.Cells[1].MergeDown        = 3;

            row.Cells[2].AddParagraph("Just Value");
            row.Cells[2].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[2].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[3].AddParagraph("$" + String.Format("{0:#,#######0}", obCama.justval));
            row.Cells[3].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[3].Format.Alignment = ParagraphAlignment.Left;


            row = table.AddRow();

            row.Cells[2].AddParagraph("Assessed Value");
            row.Cells[2].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[2].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[3].AddParagraph("$" + String.Format("{0:#,#######0}", obCama.assdval));
            row.Cells[3].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[3].Format.Alignment = ParagraphAlignment.Left;



            row = table.AddRow();

            row.Cells[2].AddParagraph("Exempt Value");
            row.Cells[2].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[2].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[3].AddParagraph("$" + String.Format("{0:#,#######0}", obCama.exempt_val));
            row.Cells[3].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[3].Format.Alignment = ParagraphAlignment.Left;



            row = table.AddRow();

            row.Cells[2].AddParagraph("Taxable Value");
            row.Cells[2].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[2].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[3].AddParagraph("$" + String.Format("{0:#,#######0}", obCama.taxblval));
            row.Cells[3].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[3].Format.Alignment = ParagraphAlignment.Left;


            // Create a renderer and prepare (=layout) the document
            //MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc);
            docRenderer.PrepareDocument();

            // Render the paragraph. You can render tables or shapes the same way.
            docRenderer.RenderObject(gfx, XUnit.FromInch(0.4025), XUnit.FromInch(7.88), XUnit.FromInch(3.85), table);

            //table.SetEdge(0, 0, 2, 2, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.Single, 0.75, MigraDoc.DocumentObjectModel.Colors.Yellow);

            // table.SetEdge(0, 0, 6, 2, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.Single, 0.75, MigraDoc.DocumentObjectModel.Colors.Yellow);


            XFont    font2       = new XFont("Verdana", 5, XFontStyle.Regular);
            DateTime tdate       = DateTime.Now;
            String   datestr     = tdate.ToString("MMM dd,yyy");
            String   metadataMSG = String.Format("map created {0}", datestr);

            gfx.DrawString(metadataMSG, font2, XBrushes.Black, new XRect(480, 769, 100, 20), XStringFormats.Center);

            /*
             * double xp = 0;
             * double yp = 0;
             * int numticks = 10;
             *
             * double w_inc = page.Width.Value / (double)numticks;
             * double h_inc = page.Height.Value / (double)numticks;
             *
             * for (int x = 0; x < numticks; x++)
             * {
             * for (int y = 0; y < numticks; y++)
             * {
             *
             *     xp = (double)x * w_inc;
             *     yp = (double)y * h_inc;
             *
             *     XUnit xu_x = new XUnit(xp, XGraphicsUnit.Point);
             *     XUnit xu_y = new XUnit(yp, XGraphicsUnit.Point);
             *
             *     xu_x.ConvertType(XGraphicsUnit.Inch);
             *     xu_y.ConvertType(XGraphicsUnit.Inch);
             *
             *     gfx.DrawString("+", font, XBrushes.Red, new XRect( xp,  yp, 5, 5), XStringFormats.Center);
             *     String lbl = String.Format("{0},{1}-{2},{3}", (int)xp, (int)yp, xu_x.Value, xu_y.Value);
             *     gfx.DrawString(lbl, font, XBrushes.Red, new XRect( xp + 5,  yp + 5, 5, 5), XStringFormats.Center);
             *
             *
             * }
             *
             * }
             */
        }
        private static PdfDocument CreateDocument(IEnumerable <CardData> cards, DateTime fileChanged)
        {
            var pageWdith  = XUnit.FromInch(2.5);
            var pageHeight = XUnit.FromInch(3.5);


            PdfDocument document = new PdfDocument();

            document.Info.Title    = "Aktions Karten";
            document.Info.Subject  = "Die Aktionskarten des spiels";
            document.Info.Author   = "Arbeitstitel Karthago";
            document.Info.Keywords = "Karten, Aktion, Karthago";


            var maxOccurenceOfCard = cards.Max(x => x.Metadata.Times);
            int counter            = 0;
            var total = cards.Sum(x => x.Metadata.Times);

            foreach (var card in cards)
            {
                for (int t = 0; t < card.Metadata.Times; t++)
                {
                    counter++;

                    PdfPage page = document.AddPage();

                    page.Width  = new XUnit(pageWdith.Millimeter, XGraphicsUnit.Millimeter);
                    page.Height = new XUnit(pageHeight.Millimeter, XGraphicsUnit.Millimeter);


                    XGraphics gfx = XGraphics.FromPdfPage(page);
                    // HACK²
                    gfx.MUH = PdfFontEncoding.Unicode;
                    //gfx.MFEH = PdfFontEmbedding.Default;

                    XFont font = new XFont("Verdana", 13, XFontStyle.Regular);



                    var costSize = new XSize(new XUnit(23, XGraphicsUnit.Millimeter), font.Height);

                    var costMarginRight = new XUnit(5, XGraphicsUnit.Millimeter);



                    var costRect = new XRect(pageWdith - costSize.Width - costMarginRight, new XUnit(5, XGraphicsUnit.Millimeter), costSize.Width, costSize.Height);

                    var actionRect = new XRect(costMarginRight, new XUnit(5, XGraphicsUnit.Millimeter), pageWdith - costMarginRight - costMarginRight, costSize.Height);

                    gfx.DrawRoundedRectangle(XPens.Red, XBrushes.IndianRed, actionRect, new XSize(10, 10));
                    gfx.DrawRoundedRectangle(XPens.Purple, XBrushes.MediumPurple, costRect, new XSize(10, 10));


                    gfx.DrawString($"{card.Metadata.Cost:n0} ¤", font, XBrushes.Black,
                                   costRect, XStringFormats.CenterRight);

                    var actionTextRect = actionRect;
                    actionTextRect.Offset(new XUnit(3, XGraphicsUnit.Millimeter), 0);

                    gfx.DrawString($"Aktion", font, XBrushes.Black,
                                   actionTextRect, XStringFormats.CenterLeft);

                    for (int i = 0; i < maxOccurenceOfCard; i++)
                    {
                        var rect = new XRect(new XUnit(3, XGraphicsUnit.Millimeter) + new XUnit(6, XGraphicsUnit.Millimeter) * i, pageHeight - new XUnit(8.5, XGraphicsUnit.Millimeter), new XUnit(3, XGraphicsUnit.Millimeter), new XUnit(3, XGraphicsUnit.Millimeter));

                        if (i + 1 <= card.Metadata.Times)
                        {
                            gfx.DrawEllipse(XBrushes.Green, rect);
                        }
                        else
                        {
                            gfx.DrawEllipse(XPens.Green, rect);
                        }
                    }


                    var dateRec  = new XRect(new XUnit(3, XGraphicsUnit.Millimeter), pageHeight - new XUnit(2.5, XGraphicsUnit.Millimeter), new XUnit(3, XGraphicsUnit.Millimeter), new XUnit(3, XGraphicsUnit.Millimeter));
                    var dateFont = new XFont("Verdana", 7, XFontStyle.Regular);
                    gfx.DrawString(fileChanged.ToString(), dateFont, XBrushes.Gray, dateRec.TopLeft);
                    gfx.DrawString($"{counter}/{total}", dateFont, XBrushes.Gray, new XRect(0, 0, pageWdith - new XUnit(3, XGraphicsUnit.Millimeter), pageHeight - new XUnit(2.5, XGraphicsUnit.Millimeter)), XStringFormats.BottomRight);

                    // Create a new MigraDoc document
                    var doc = new Document();
                    doc.Info.Title   = "Aktions Karten";
                    doc.Info.Subject = "Die Aktionskarten des spiels";
                    doc.Info.Author  = "Arbeitstitel Karthago";


                    doc.DefaultPageSetup.PageWidth  = new Unit(pageWdith.Inch, UnitType.Inch);
                    doc.DefaultPageSetup.PageHeight = new Unit(pageHeight.Inch, UnitType.Inch);

                    doc.DefaultPageSetup.LeftMargin   = new Unit(5, UnitType.Millimeter);
                    doc.DefaultPageSetup.RightMargin  = new Unit(5, UnitType.Millimeter);
                    doc.DefaultPageSetup.BottomMargin = new Unit(10, UnitType.Millimeter);
                    doc.DefaultPageSetup.TopMargin    = new Unit(15, UnitType.Millimeter);

                    doc.DefineStyles();

                    //Cover.DefineCover(document);
                    //DefineTableOfContents(document);

                    DefineContentSection(doc);
                    card.Content.HandleBlocks(doc);


                    // Create a renderer and prepare (=layout) the document
                    MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc);
                    docRenderer.PrepareDocument();

                    //XRect rect = new XRect(new XPoint(Unit.FromCentimeter(1).Value, Unit.FromCentimeter(3).Value), new XSize((pageWdith.Value - Unit.FromCentimeter(2).Value), (pageHeight.Value - Unit.FromCentimeter(4).Value)));

                    // Use BeginContainer / EndContainer for simplicity only. You can naturaly use you own transformations.
                    //XGraphicsContainer container = gfx.BeginContainer(rect, A4Rect, XGraphicsUnit.Point);

                    // Draw page border for better visual representation
                    //gfx.DrawRectangle(XPens.LightGray, A4Rect);

                    // Render the page. Note that page numbers start with 1.
                    docRenderer.RenderPage(gfx, 1);

                    // Note: The outline and the hyperlinks (table of content) does not work in the produced PDF document.

                    // Pop the previous graphical state
                    //gfx.EndContainer(container);
                }
            }
            // card back
            {
                PdfPage page = document.AddPage();

                page.Width  = new XUnit(pageWdith.Millimeter, XGraphicsUnit.Millimeter);
                page.Height = new XUnit(pageHeight.Millimeter, XGraphicsUnit.Millimeter);


                XGraphics gfx = XGraphics.FromPdfPage(page);
                // HACK²
                gfx.MUH = PdfFontEncoding.Unicode;
                //gfx.MFEH = PdfFontEmbedding.Default;

                XFont font            = new XFont("Verdana", 36, XFontStyle.Regular);
                var   costSize        = new XSize(new XUnit(23, XGraphicsUnit.Millimeter), font.Height);
                var   costMarginRight = new XUnit(5, XGraphicsUnit.Millimeter);
                var   titleRect       = new XRect(0, 0, pageWdith, pageHeight);
                gfx.DrawString($"Aktion", font, XBrushes.DarkRed,
                               titleRect, XStringFormats.Center);
            }



            //DefineParagraphs(document);
            //DefineTables(document);
            //DefineCharts(document);

            return(document);
        }