public async Task <IActionResult> Generate()
        {
            BarCodeApi api = new BarCodeApi(AppKey, AppSid);

            Assembly myAssembly = Assembly.GetExecutingAssembly();
            Stream   myStream   = myAssembly.GetManifestResourceStream("BarcodeExample.Card.png");
            Bitmap   srcBmp     = new Bitmap(myStream);

            string tmp = Path.GetTempFileName();

            using (Stream response =
                       api.BarCodeGetBarCodeGenerate(
                           new BarCodeGetBarCodeGenerateRequest("Hello from conholdate.cloud!", "QR", "png")))
            {
                var qr  = new Bitmap(response);
                var bmp = new Bitmap(srcBmp.Width, srcBmp.Height);
                using (Graphics graphics = Graphics.FromImage(bmp))
                {
                    graphics.DrawImage(srcBmp, 0, 0, srcBmp.Width, srcBmp.Height);
                    graphics.DrawImage(qr, srcBmp.Width - qr.Width - 10, 10);
                }

                using (FileStream stream = System.IO.File.Create(tmp))
                {
                    bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                }
            }

            FileStream res = new FileStream(tmp, FileMode.Open);

            return(File(res, "application/octet-stream", "CardWithQr.png"));
        }
Пример #2
0
        public IActionResult Generate(string text)
        {
            string jwt = Utils.GetJwt(Request);

            string baseUrl = "https://api-qa.aspose.cloud";//v3.0";
            var    conf    = new Configuration();

            conf.ApiBaseUrl = baseUrl;
            conf.JwtToken   = jwt;
            conf.ApiVersion = ApiVersion.V3;
            conf.AuthType   = AuthType.ExternalAuth;
            BarCodeApi api = new BarCodeApi(conf);

            Assembly myAssembly = Assembly.GetExecutingAssembly();
            Stream   myStream   = myAssembly.GetManifestResourceStream("BarcodeExample.Card.png");
            Bitmap   srcBmp     = new Bitmap(myStream);

            string tmp = Path.GetTempFileName();

            using (Stream response =
                       api.BarCodeGetBarCodeGenerate(
                           new BarCodeGetBarCodeGenerateRequest(text, "QR", "png")))
            {
                var qr  = new Bitmap(response);
                var bmp = new Bitmap(srcBmp.Width, srcBmp.Height);
                using (Graphics graphics = Graphics.FromImage(bmp))
                {
                    graphics.DrawImage(srcBmp, 0, 0, srcBmp.Width, srcBmp.Height);
                    graphics.DrawImage(qr, srcBmp.Width - qr.Width - 10, 10);
                }

                using (FileStream stream = System.IO.File.Create(tmp))
                {
                    bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                }
            }

            FileStream res = new FileStream(tmp, FileMode.Open);

            return(File(res, "application/octet-stream", "CardWithQr.png"));
        }
Пример #3
0
        public ActionResult GenerateTicket(string TicketNo, string FlightNo, string Name, DateTime FlightDate,
                                           string From, string To, string Class, string Seat, string Age, string Phone, string Gender)
        {
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine(TicketNo).AppendLine(FlightNo).AppendLine(Name).AppendLine(FlightDate.ToString())
                .AppendLine(From).AppendLine(To).AppendLine(Class).AppendLine(Seat).AppendLine(Age).AppendLine(Phone).AppendLine(Gender);
                string fileName    = Guid.NewGuid().ToString();
                string pdfFileName = fileName + ".pdf";
                using (var file = System.IO.File.OpenRead(Path.Combine(_hostingEnvironment.WebRootPath, "ticket_template.pdf")))
                {
                    var response = _pdfApi.UploadFile(pdfFileName, file);
                }
                using (Stream barcodeResponse = _barCodeApi.BarCodeGetBarCodeGenerate(new BarCodeGetBarCodeGenerateRequest(Crc32.ComputeChecksum(Encoding.UTF8.GetBytes(sb.ToString())).ToString(), "Code128", "png")))
                {
                    _pdfApi.PostInsertImage(pdfFileName, 1, 350, 600, 450, 700, image: barcodeResponse);
                }
                Fields fields = new Fields(List: new List <Field>()
                {
                    new Field(Name: "TicketNumber", Values: new List <string> {
                        TicketNo
                    }),
                    new Field(Name: "FlightNumber", Values: new List <string> {
                        FlightNo
                    }),
                    new Field(Name: "Date", Values: new List <string> {
                        FlightDate.ToShortDateString()
                    }),
                    new Field(Name: "Time", Values: new List <string> {
                        FlightDate.ToShortTimeString()
                    }),
                    new Field(Name: "From", Values: new List <string> {
                        From
                    }),
                    new Field(Name: "To", Values: new List <string> {
                        To
                    }),
                    new Field(Name: "Class", Values: new List <string> {
                        Class
                    }),
                    new Field(Name: "Seat", Values: new List <string> {
                        Seat
                    }),
                    new Field(Name: "Name", Values: new List <string> {
                        Name
                    }),
                    new Field(Name: "Age", Values: new List <string> {
                        Age
                    }),
                    new Field(Name: "Phone", Values: new List <string> {
                        Phone
                    }),
                    new Field(Name: "Gender", Values: new List <string> {
                        Gender
                    }),
                });
                _pdfApi.PutUpdateFields(pdfFileName, fields);

                /*
                 * string pdfFileNamePage2 = fileName + "_Page2.pdf";
                 * using (var file = System.IO.File.OpenRead(Path.Combine(_hostingEnvironment.WebRootPath, "second_page.html")))
                 * {
                 *  _htmlApi.PostConvertDocumentToPdf(file, pdfFileNamePage2);
                 * }
                 * _pdfApi.PostAppendDocument(pdfFileName, pdfFileNamePage2);
                 */
                MemoryStream ms = new MemoryStream();
                using (Stream response = _pdfApi.DownloadFile(pdfFileName))
                {
                    response.CopyTo(ms);
                    ms.Position = 0;
                    return(new FileStreamResult(ms, "application/pdf"));
                }
            }
            catch (ApiException ex)
            {
                return(new StatusCodeResult(ex.ErrorCode));
            }
        }