Пример #1
0
 private PdfLayoutResult ReadFilledForm(PdfPage page, PdfLayoutResult result, PdfTextElement element, RapportVragenlijstVM answerlist)
 {
     foreach (var q in answerlist.Stappen)
     {
         if (q.TypeNaam.Equals("Foto") || q.TypeNaam.Equals("Enkel") || q.TypeNaam.Equals("Getal") || q.TypeNaam.Equals("Open"))
         {
             result = OutputSingleLine(page, result, element, q.Omschrijving, q.Antwoord);
         }
         else
         {
             string multiple = "";
             foreach (var m in q.MeerkeuzeAntwoord)
             {
                 multiple = multiple + m + ", ";
             }
             result = OutputSingleLine(page, result, element, q.Omschrijving, multiple);
         }
         DrawLine(page, result);
     }
     return(result);
 }
Пример #2
0
        private void InsertChart(PdfPage questionlistPage, PdfLayoutResult afterResult, PdfDocument document, PdfTextElement textelement, PdfGraphics graphics, RapportVragenlijstVM answerlist)
        {
            try
            {
                //Chart
                CreateChart(questionlistPage, afterResult, textelement, answerlist);

                string    path  = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\chart.png";
                PdfBitmap image = new PdfBitmap(path);
                graphics.DrawImage(image, new RectangleF(6, afterResult.Bounds.Bottom + 100, 500, 80));

                //PdfBitmap image = new PdfBitmap(File.Open("chart.png"));
                //image.Draw(page, 10, result.Bounds.Bottom + 60);
            }
            catch (Exception e)
            {
                MessageBox.Show("Er ging iets fout bij het genereren van de diagram.", "Waarschuwing");
            }
        }
Пример #3
0
        private void CreateChart(PdfPage page, PdfLayoutResult result, PdfTextElement element, RapportVragenlijstVM answerlist)
        {
            List <RapportVragenlijstStap> chartList = new List <RapportVragenlijstStap>();

            foreach (var x in answerlist.Stappen)
            {
                if (x.TypeNaam.Equals("Getal"))
                {
                    chartList.Add(x);
                }
            }

            CartesianChart Chart = new CartesianChart
            {
                DisableAnimations = true,
                Width             = 600,
                Height            = 400,
                Series            = new SeriesCollection
                {
                    new ColumnSeries
                    {
                        Values = new ChartValues <double> {
                            4, 3, 2, 5, 10
                        }
                    }
                }
            };

            Chart.AxisY.Add(new Axis
            {
                MinValue  = 0,
                MaxValue  = 10,
                Separator = new LiveCharts.Wpf.Separator
                {
                    Step      = 1,
                    IsEnabled = true
                }
            });

            string path = "chart.png";

            Chart.Update(true, true);
            SaveToPng(Chart, path);
        }
Пример #4
0
        private void CreatePdf(RapportVragenlijstVM answerlist)
        {
            Guid   mySerialNumber = Guid.NewGuid();
            string pdfName        = mySerialNumber + ".pdf";

            using (PdfDocument document = new PdfDocument())
            {
                //Add a page to the document
                PdfPage frontPage        = document.Pages.Add();
                PdfPage questionlistPage = document.Pages.Add();

                //Create PDF graphics for a page
                PdfGraphics graphics = frontPage.Graphics;
                //Set the standard font
                PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
                //Brush
                PdfBrush solidBrush = new PdfSolidBrush(new PdfColor(126, 151, 173));

                //Image
                try
                {
                    string    path        = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
                    string    correctPath = path.Substring(0, path.Length - 10) + "\\resources\\images\\festispec.png";
                    PdfBitmap image       = new PdfBitmap(correctPath);
                    graphics.DrawRectangle(solidBrush, new RectangleF(7, 00, 500, 80));
                    graphics.DrawImage(image, new RectangleF(7, 00, 500, 80));
                }
                catch (Exception e)
                {
                }

                //Show header information
                PdfGrid         table  = new PdfGrid();
                PdfLayoutResult result = table.Draw(frontPage, new PointF(0, 0));
                solidBrush = new PdfSolidBrush(new PdfColor(126, 151, 173));
                RectangleF bounds = new RectangleF(0, result.Bounds.Bottom + 90, graphics.ClientSize.Width, 30);
                //Draws a rectangle to place the heading in that region.
                graphics.DrawRectangle(solidBrush, bounds);
                //Creates a font for adding the heading in the page
                PdfFont        subHeadingFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 14);
                PdfTextElement element        = new PdfTextElement("Rapport: " + SelectedInspectie.Inspecteur.Naam + " " + SelectedInspectie.Inspecteur.Achternaam, subHeadingFont);
                element.Brush = PdfBrushes.White;

                //Draws the heading on the page
                result = element.Draw(frontPage, new PointF(10, result.Bounds.Bottom + 98));
                string currentDate = "DATUM: " + DateTime.Now.ToString("dd/MM/yyyy");
                //Measures the width of the text to place it in the correct location
                SizeF  textSize     = subHeadingFont.MeasureString(currentDate);
                PointF textPosition = new PointF(graphics.ClientSize.Width - textSize.Width - 10, result.Bounds.Y);
                //Draws the date by using DrawString method
                graphics.DrawString(currentDate, subHeadingFont, element.Brush, textPosition);
                PdfFont timesRoman = new PdfStandardFont(PdfFontFamily.TimesRoman, 10, PdfFontStyle.Bold);
                //Creates text elements to add the address and draw it to the page.
                element       = new PdfTextElement("ID: " + SelectedInspectie.Inspecteur.Id, timesRoman);
                element.Brush = new PdfSolidBrush(new PdfColor(126, 155, 203));
                result        = element.Draw(frontPage, new PointF(10, result.Bounds.Bottom + 12));
                element       = new PdfTextElement("Mail: " + SelectedInspectie.Inspecteur.Email, timesRoman);
                element.Brush = new PdfSolidBrush(new PdfColor(126, 155, 203));
                result        = element.Draw(frontPage, new PointF(10, result.Bounds.Bottom + 8));
                element       = new PdfTextElement("Telefoonnummer: " + SelectedInspectie.Inspecteur.Telefoonnummer, timesRoman);
                element.Brush = new PdfSolidBrush(new PdfColor(126, 155, 203));
                result        = element.Draw(frontPage, new PointF(10, result.Bounds.Bottom + 8));

                DrawLine(frontPage, result);

                element       = new PdfTextElement("Bedrijf: " + SelectedInspectie.CustomerName, timesRoman);
                element.Brush = new PdfSolidBrush(new PdfColor(126, 155, 203));
                result        = element.Draw(frontPage, new PointF(10, result.Bounds.Bottom + 12));
                element       = new PdfTextElement("Uitgevoerd op: " + SelectedInspectie.InspectieDatum, timesRoman);
                element.Brush = new PdfSolidBrush(new PdfColor(126, 155, 203));
                result        = element.Draw(frontPage, new PointF(10, result.Bounds.Bottom + 8));

                bounds = new RectangleF(0, result.Bounds.Bottom + 10, frontPage.Graphics.ClientSize.Width, 30);
                frontPage.Graphics.DrawRectangle(new PdfSolidBrush(new PdfColor(126, 151, 173)), bounds);

                //QuestionList options
                //Show header information
                PdfGrid         layout       = new PdfGrid();
                PdfLayoutResult afterResult  = table.Draw(questionlistPage, new PointF(0, 0));
                RectangleF      secondBounds = new RectangleF(0, afterResult.Bounds.Bottom + 90, graphics.ClientSize.Width, 30);
                //Draws a rectangle to place the heading in that region.
                graphics.DrawRectangle(solidBrush, secondBounds);
                element       = new PdfTextElement(SelectedInspectie.Naam, font);
                element.Brush = PdfBrushes.White;

                //Heading
                secondBounds = new RectangleF(0, afterResult.Bounds.Bottom + 10, questionlistPage.Graphics.ClientSize.Width, 30);
                questionlistPage.Graphics.DrawRectangle(new PdfSolidBrush(new PdfColor(126, 151, 173)), secondBounds);

                element       = new PdfTextElement(SelectedInspectie.Naam, subHeadingFont);
                element.Brush = new PdfSolidBrush(new PdfColor(126, 155, 203));
                afterResult   = element.Draw(questionlistPage, new PointF(10, afterResult.Bounds.Bottom + 45));

                DrawLine(questionlistPage, afterResult);

                //Read the questionlist
                afterResult = ReadFilledForm(questionlistPage, afterResult, element, answerlist);
                InsertChart(questionlistPage, afterResult, document, element, graphics, answerlist);
                CreateInputField(questionlistPage, afterResult, document);
                document.Save(pdfName);
            }
            //Show confirmation message
            ShowMessage(pdfName);
        }