Exemplo n.º 1
0
        public async Task <IActionResult> Generate_V1_0(Guid id)
        {
            // var certifications = await _certificatesBaseRepository.GetAllAsync();
            // var certification = certifications.SingleOrDefault(x => x.Id == Guid.Parse(id.ToString()));
            var certification = new O2CCertificate()
            {
                Serial     = "А",
                Number     = "A0086061820",
                Firstname  = "Анна",
                Lastname   = "Янушкевич",
                Middlename = "Леонидовна",
                DateOfCert = new DateTime(2020, 02, 28).ConvertToUnixTime()
            };

            var content = " Центр Гипноза Антона Маркова" +
                          " https://antonmarkov.com/obuchenie/baza-sertifikatov-pfr/" +
                          " Сертификат " + certification.Serial + certification.Number +
                          "; Дата сертификации: " + certification.DateOfCert.Value.ConvertToDateTime();


            var image = Image.FromFile("Files/pft_template_cert.png");
            var cert  = new Bitmap(image);

            var qrGenerator = new QRCodeGenerator();
            var qrCodeData  = qrGenerator.CreateQrCode(
                " Центр Гипноза Антона Маркова" + " https://antonmarkov.com/obuchenie/baza-sertifikatov-pfr/" +
                " Сертификат " + certification.Serial + certification.Number +
                "; Дата сертификации: " + certification.DateOfCert.Value.ConvertToDateTime(),
                QRCodeGenerator.ECCLevel.Q);
            var qrCode = new QRCode(qrCodeData);

            var qrCodeImage = qrCode.GetGraphic(5);


            var bitmapClear = new Bitmap(cert.Width, cert.Height);

            using (var graphics = Graphics.FromImage(bitmapClear))
            {
                graphics.DrawImage(cert, 0, 0, cert.Width, cert.Height);

                var fio = certification.Lastname + " " + certification.Firstname +
                          " " + (string.IsNullOrEmpty(certification.Middlename)
                              ? ""
                              : "\n" + certification.Middlename); //certification.FIO.Replace(" ", "\r\n");
                var fullNumber = certification.Serial + certification.Number;
                ImageHelper.AddedText(fio, cert, graphics, "Arial", 95, Brushes.Black, 1550,
                                      StringAlignment.Center, StringAlignment.Center);

                //added serial_number
                ImageHelper.AddedText(fullNumber, cert, graphics, "Arial", 45, Brushes.Red, 2727,
                                      StringAlignment.Center, StringAlignment.Near);

                graphics.DrawImage(qrCodeImage, 1070, 2901, qrCodeImage.Width, qrCodeImage.Height);
                graphics.Save();
            }

            var bitmapBytes = ImageHelper.BitmapToBytes(bitmapClear); //Convert bitmap into a byte array

            return(File(bitmapBytes, "image/jpeg"));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Generate_terapia_V1_0(Guid id, long uniDate)
        {
            var certifications = await _certificatesBaseRepository.GetAllAsync();

            var    certification = certifications.SingleOrDefault(x => x.Id == Guid.Parse(id.ToString()));
            Bitmap bitmapClear;
            // foreach (var certification in certifications)
            // {
            var image = Image.FromFile("Files/template-hypnos.png");

            var cert = new Bitmap(image);


            bitmapClear = new Bitmap(cert.Width, cert.Height);
            using (Graphics graphics = Graphics.FromImage(bitmapClear))
            {
                graphics.DrawImage(cert, 0, 0, cert.Width, cert.Height);

                var fio = certification.Lastname + " " + certification.Firstname +
                          " " + (string.IsNullOrEmpty(certification.Middlename)
                                  ? " "
                                  : " " + certification.Middlename); //certification.FIO.Replace(" ", "\r\n");
                ImageHelper.AddedText(fio, cert, graphics, "Arial", 95, Brushes.Black, 1265, StringAlignment.Center,
                                      StringAlignment.Center);

                var date = uniDate.ConvertToDateTime();
                ImageHelper.AddedTextX(date.ToString("dd.MM.yyyy"), cert, graphics, "Arial", 68, Brushes.Black,
                                       2090,
                                       2539, StringAlignment.Center, StringAlignment.Center);
                ////added serial_number
                //ImageHelper.AddedText(certification.SerialNumber, cert, graphics, "Arial", 45, Brushes.Red, 2727, StringAlignment.Center, StringAlignment.Near);

                //graphics.DrawImage(qrCodeImage, 1070, 2901, qrCodeImage.Width, qrCodeImage.Height);
                graphics.Save();
                // bitmapClear.Save(fio + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            // }

            var bitmapBytes = ImageHelper.BitmapToBytes(bitmapClear);  //Convert bitmap into a byte array

            return(File(bitmapBytes, "image/jpeg"));
            // return Ok();
        }