示例#1
0
        public async Task <IActionResult> GenerateDocument(int Id, string tokenId)
        {
            var LabTest = _context.TblLabTests
                          .Include(x => x.MethodNavigation)
                          .Include(x => x.BiodataNavigation)
                          .Include(x => x.BiodataNavigation.GenderNavigation)
                          .Include(x => x.TblLabTestsIndicatorsValues)
                          .Include(x => x.TblLabTestsSpecimen)
                          .FirstOrDefault(x => x.Id == Id);

            if (LabTest == null)
            {
                return(NotFound());
            }

            //Loads or opens an existing word document through Open method of WordDocument class
            Stream fs = new FileStream("Templates/result.docx", FileMode.Open, FileAccess.Read, FileShare.Read);

            WordDocument document = new WordDocument(fs, FormatType.Docx);

            if (document.Sections.Count < 1)
            {
                throw new Exception("Result template empty. Please contact your Application support.");
            }
            IWSection section = document.Sections[0];

            IWTable table = section.Tables[0];

            WParagraph p = (WParagraph)table.Rows[0].Cells[1].ChildEntities[0];

            p.AppendText(LabTest.BiodataNavigation.Fullname);

            p = (WParagraph)table.Rows[1].Cells[1].ChildEntities[0];
            string gardian = LabTest.BiodataNavigation.LegalGardianName;

            gardian = string.IsNullOrEmpty(gardian) ? "-" : gardian;
            p.AppendText(gardian);

            p = (WParagraph)table.Rows[2].Cells[1].ChildEntities[0];

            p.AppendText(LabTest.BiodataNavigation.Dateofbirth.ToString("dd/MMM/yyyy"));

            //skip 3


            //Repos.GenderRepos genders = new Repos.GenderRepos();


            int g_id = 1;

            foreach (var g in _context.TlkpGenders)
            {
                string tmp = g.Gender.Substring(0, 2).Trim().Trim('=');
                try
                {
                    p = (WParagraph)table.Rows[3].Cells[g_id].ChildEntities[0];
                    WCheckBox checkbox = p.AppendCheckBox();

                    if (LabTest.BiodataNavigation.Gender == g_id)
                    {
                        checkbox.Checked = true;
                    }

                    p.AppendText(" " + tmp);

                    g_id++;
                }
                catch
                {
                }
            }

            p = (WParagraph)table.Rows[4].Cells[1].ChildEntities[0];
            p.AppendText(LabTest.BiodataNavigation.EpidNo);

            //skip 5 for local phone number
            p = (WParagraph)table.Rows[5].Cells[1].ChildEntities[0];
            p.AppendText(LabTest.BiodataNavigation.LocalPhone ?? "-");

            p = (WParagraph)table.Rows[6].Cells[1].ChildEntities[0];
            p.AppendText(LabTest.BiodataNavigation.HomePhone ?? "-");

            p = (WParagraph)table.Rows[7].Cells[1].ChildEntities[0];
            p.AppendText(LabTest.BiodataNavigation.ResidentialAddress);

            //next table
            table = section.Tables[1];

            p = (WParagraph)table.Rows[0].Cells[1].ChildEntities[0];
            p.AppendText(LabTest.MethodNavigation.Methodname);

            int k = 1;


            foreach (var i in LabTest.TblLabTestsIndicatorsValues)
            {
                var iname = _context.TlkpTestIndicators.FirstOrDefault(x => x.Id == i.Indicator).IndicatorName;

                p = (WParagraph)table.Rows[k].Cells[0].ChildEntities[0];
                p.AppendText(iname);

                p = (WParagraph)table.Rows[k].Cells[1].ChildEntities[0];
                p.AppendText(i.IndicatorValue.Value.ToString());

                k++;
            }



            /*Dictionary<int, string> _dict = new Dictionary<int, string> {
             *  { 1, "POSITIVE"},
             *  { 2, "NEGATIVE"},
             *  { 97, "NO RESULT"}
             * };*/
            var p1 = (WParagraph)table.Rows[k].Cells[0].ChildEntities[0];

            p = (WParagraph)table.Rows[k].Cells[1].ChildEntities[0];
            WCheckBox checkbox1 = p.AppendCheckBox();

            if (LabTest.Interpretation == 2)
            {
                checkbox1.Checked = true;
                p1.AppendText("INTERPRETATION: NEGATIVE RESULT");
            }
            else if (LabTest.Interpretation > 2)
            {
                p1.AppendText("INTERPRETATION: UNKNOWN");
            }

            p.AppendText(" NEGATIVE");

            p         = (WParagraph)table.Rows[k + 1].Cells[1].ChildEntities[0];
            checkbox1 = p.AppendCheckBox();
            if (LabTest.Interpretation == 1)
            {
                checkbox1.Checked = true;
                p1.AppendText("INTERPRETATION: POSITIVE RESULT");
            }

            p.AppendText(" POSITIVE");

            //next table
            table = section.Tables[2];

            DateTime d1 = DateTime.Today;               // any date will do

            p = (WParagraph)table.Rows[0].Cells[1].ChildEntities[0];
            p.AppendText(LabTest.TestingDate.Value.ToString("dd/MMM/yyyy"));

            p = (WParagraph)table.Rows[1].Cells[1].ChildEntities[0];
            TimeSpan t   = LabTest.TestingTime.Value;
            string   chg = (d1 + t).ToString("hh:mm tt");

            p.AppendText(chg);

            p = (WParagraph)table.Rows[2].Cells[1].ChildEntities[0];
            p.AppendText(LabTest.ReportingDate.Value.ToString("dd/MMM/yyyy"));

            p   = (WParagraph)table.Rows[3].Cells[1].ChildEntities[0];
            t   = LabTest.ReportingTime.Value;
            chg = (d1 + t).ToString("hh:mm tt");
            p.AppendText(chg);

            //next table
            table = section.Tables[3];

            //Repos.SpecimenRepos _specimen = new Repos.SpecimenRepos();

            k = 1;
            foreach (var s in LabTest.TblLabTestsSpecimen)
            {
                bool other = s.Specimen == 99;

                var sname = _context.TlkpSpecimen.FirstOrDefault(x => x.Id == s.Specimen).Type;
                p = (WParagraph)table.Rows[k].Cells[0].ChildEntities[0];

                IWTextRange textRange = p.AppendText(sname + (other ? " (Specify)" : ""));
                textRange.CharacterFormat.FontSize = 8;


                p.ApplyStyle(BuiltinStyle.BlockText);
                p = (WParagraph)table.Rows[k].Cells[1].ChildEntities[0];
                if (other && !string.IsNullOrEmpty(s.SpecimenOther))
                {
                    textRange = p.AppendText(s.SpecimenOther);
                    textRange.CharacterFormat.FontSize = 10;
                }

                p         = (WParagraph)table.Rows[k].Cells[2].ChildEntities[0];
                checkbox1 = p.AppendCheckBox();
                if (s.Checked)
                {
                    checkbox1.Checked = true;
                }

                k++;
            }


            //
            //table = section.Tables[1];
            // p = (WParagraph)table.Rows[6].Cells[1].ChildEntities[0];
            //p.AppendText(LabTest.BioData.ResidentialAddress);


            DocIORenderer render = new DocIORenderer();
            //Converts Word document to PDF.
            PdfDocument pdfDocument = render.ConvertToPDF(document);

            //Release the resources used by the Word document and DocIO Renderer objects.

            render.Dispose();
            render.Dispose();
            document.Dispose();

            //add barcode
            PdfQRBarcode barcode = new PdfQRBarcode();

            barcode.ErrorCorrectionLevel = PdfErrorCorrectionLevel.High;
            //Set XDimension
            barcode.XDimension = 2.5f;
            //https://localhost:44353/LabTests/Details/
            string endpoint = configuration.GetConnectionString("ServerEndpoint");

            barcode.Text = string.Format("{0}LabTests/Details/{1}", endpoint, Id);
            //Creating new PDF Document
            //PdfDocument doc = new PdfDocument();
            //Adding new page to PDF document
            PdfPage page = pdfDocument.Pages[0];

            //Printing barcode on to the Pdf.
            //barcode.Draw(page, new PointF(25, 70));
            barcode.Draw(page, new PointF(250, 650));

            if (!string.IsNullOrEmpty(tokenId))
            {
                Response.Cookies.Append("fileDownloadToken", tokenId);
            }

            MemoryStream stream = new MemoryStream();

            //document.Save(stream, FormatType.Docx);
            pdfDocument.Save(stream);
            //return File(stream, "application/msword", "Sample.docx");
            return(File(stream.ToArray(), "application/octet-stream", "Draft.pdf"));
            //return RedirectToAction(nameof(Index));
        }
        private async void BarcodeSample()
        {
            MemoryStream stream = new MemoryStream();

            //Create a new instance of PdfDocument class.
            using (PdfDocument document = new PdfDocument())
            {
                //Add a new page to the document.
                PdfPage page = document.Pages.Add();

                //Create Pdf graphics for the page
                PdfGraphics g = page.Graphics;

                //Create a solid brush
                PdfBrush brush = PdfBrushes.Black;

                #region 2D Barcode

                //Set the font
                PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 15f, PdfFontStyle.Bold);

                PdfPen pen   = new PdfPen(brush, 0.5f);
                float  width = page.GetClientSize().Width;

                float xPos = page.GetClientSize().Width / 2;

                PdfStringFormat format = new PdfStringFormat();
                format.Alignment = PdfTextAlignment.Center;

                // Draw String
                g.DrawString("2D Barcodes", font, brush, new PointF(xPos, 10), format);

                #region QR Barcode
                font = new PdfStandardFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Bold);
                g.DrawString("QR Barcode", font, brush, new PointF(10, 90));

                //Create QR barcode
                PdfQRBarcode qrBarcode = new PdfQRBarcode();

                //Set input mode
                qrBarcode.InputMode = InputMode.BinaryMode;

                //Set error correction level
                qrBarcode.ErrorCorrectionLevel = PdfErrorCorrectionLevel.High;

                //Set dimension
                qrBarcode.XDimension = 4;

                //Add data
                qrBarcode.Text = "Syncfusion Essential Studio Enterprise edition $995";

                //Draw barcode on Pdf page
                qrBarcode.Draw(page, new PointF(25, 120));

                font = new PdfStandardFont(PdfFontFamily.TimesRoman, 9, PdfFontStyle.Regular);

                g.DrawString("Input Type :   Eight Bit Binary", font, brush, new PointF(250, 160));
                g.DrawString("Encoded Data : Syncfusion Essential Studio Enterprise edition $995", font, brush, new PointF(250, 180));

                g.DrawLine(pen, new PointF(0, 320), new PointF(width, 320));

                #endregion

                #region Datamatrix
                font = new PdfStandardFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Bold);
                g.DrawString("DataMatrix Barcode", font, brush, new PointF(10, 340));

                PdfDataMatrixBarcode dataMatrixBarcode = new PdfDataMatrixBarcode("5575235 Win7 4GB 64bit 7Jun2010");

                // Set dimension for each block
                dataMatrixBarcode.XDimension = 4;

                // Draw the barcode
                dataMatrixBarcode.Draw(page, new PointF(25, 540));

                font = new PdfStandardFont(PdfFontFamily.TimesRoman, 9, PdfFontStyle.Regular);

                g.DrawString("Symbol Type : Square", font, brush, new PointF(250, 590));
                g.DrawString("Encoded Data : 5575235 Win7 4GB 64bit 7Jun2010", font, brush, new PointF(250, 610));

                pen = new PdfPen(brush, 0.5f);
                g.DrawLine(pen, new PointF(0, 700), new PointF(width, 700));

                string text = "TYPE 3523 - ETWS/N FE- SDFHW 06/08";

                dataMatrixBarcode = new PdfDataMatrixBarcode(text);

                // rectangular matrix
                dataMatrixBarcode.Size = PdfDataMatrixSize.Size16x48;

                dataMatrixBarcode.XDimension = 4;

                dataMatrixBarcode.Draw(page, new PointF(25, 400));

                g.DrawString("Symbol Type : Rectangle", font, brush, new PointF(250, 420));
                g.DrawString("Encoded Data : " + text, font, brush, new PointF(250, 440));

                pen = new PdfPen(brush, 0.5f);
                #endregion
                #endregion



                page = document.Pages.Add();
                g    = page.Graphics;

                //Set the font
                font = new PdfStandardFont(PdfFontFamily.Helvetica, 15f, PdfFontStyle.Bold);

                // Draw String
                g.DrawString("1D/Linear Barcodes", font, brush, new PointF(150, 10));

                // Set string format.
                format          = new PdfStringFormat();
                format.WordWrap = PdfWordWrapType.Word;

                #region Code39
                // Drawing Code39 barcode
                PdfCode39Barcode barcode = new PdfCode39Barcode();

                // Setting height of the barcode
                barcode.BarHeight = 45;
                barcode.Text      = "CODE39$";

                //Printing barcode on to the Pdf.
                barcode.Draw(page, new PointF(25, 70));

                font = new PdfStandardFont(PdfFontFamily.TimesRoman, 9, PdfFontStyle.Regular);

                g.DrawString("Type : Code39", font, brush, new PointF(200, 80));
                g.DrawString("Allowed Characters : 0-9, A-Z,a dash(-),a dot(.),$,/,+,%, SPACE", font, brush, new PointF(200, 100));

                g.DrawLine(pen, new PointF(0, 150), new PointF(width, 150));
                #endregion

                #region Code39Extended
                // Drawing Code39Extended barcode
                PdfCode39ExtendedBarcode barcodeExt = new PdfCode39ExtendedBarcode();

                // Setting height of the barcode
                barcodeExt.BarHeight = 45;
                barcodeExt.Text      = "CODE39Ext";

                //Printing barcode on to the Pdf.
                barcodeExt.Draw(page, new PointF(25, 200));

                font = new PdfStandardFont(PdfFontFamily.TimesRoman, 9, PdfFontStyle.Regular);

                g.DrawString("Type : Code39Ext", font, brush, new PointF(200, 210));
                g.DrawString("Allowed Characters : 0-9 A-Z a-z ", font, brush, new PointF(200, 230));

                g.DrawLine(pen, new PointF(0, 270), new PointF(width, 270));
                #endregion

                #region Code11Barcode
                // Drawing Code11  barcode
                PdfCode11Barcode barcode11 = new PdfCode11Barcode();

                // Setting height of the barcode
                barcode11.BarHeight = 45;
                barcode11.Text      = "012345678";
                barcode11.EncodeStartStopSymbols = true;

                //Printing barcode on to the Pdf.
                barcode11.Draw(page, new PointF(25, 300));

                font = new PdfStandardFont(PdfFontFamily.TimesRoman, 9, PdfFontStyle.Regular);

                g.DrawString("Type : Code 11", font, brush, new PointF(200, 310));
                g.DrawString("Allowed Characters : 0-9, a dash(-) ", font, brush, new PointF(200, 330));

                g.DrawLine(pen, new PointF(0, 370), new PointF(width, 370));
                #endregion

                #region Codabar
                // Drawing CodaBarcode
                PdfCodabarBarcode codabar = new PdfCodabarBarcode();

                // Setting height of the barcode
                codabar.BarHeight = 45;
                codabar.Text      = "0123";

                //Printing barcode on to the Pdf.
                codabar.Draw(page, new PointF(25, 400));

                font = new PdfStandardFont(PdfFontFamily.TimesRoman, 9, PdfFontStyle.Regular);

                g.DrawString("Type : Codabar", font, brush, new PointF(200, 410));
                g.DrawString("Allowed Characters : A,B,C,D,0-9,-$,:,/,a dot(.),+ ", font, brush, new PointF(200, 430));

                g.DrawLine(pen, new PointF(0, 470), new PointF(width, 470));
                #endregion

                #region Code32
                PdfCode32Barcode code32 = new PdfCode32Barcode();

                code32.Font = font;

                // Setting height of the barcode
                code32.BarHeight           = 45;
                code32.Text                = "01234567";
                code32.TextDisplayLocation = TextLocation.Bottom;
                code32.EnableCheckDigit    = true;
                code32.ShowCheckDigit      = true;

                //Printing barcode on to the Pdf.
                code32.Draw(page, new PointF(25, 500));

                g.DrawString("Type : Code32", font, brush, new PointF(200, 500));
                g.DrawString("Allowed Characters : 1 2 3 4 5 6 7 8 9 0 ", font, brush, new PointF(200, 520));

                g.DrawLine(pen, new PointF(0, 580), new PointF(width, 580));

                #endregion

                #region Code93
                PdfCode93Barcode code93 = new PdfCode93Barcode();

                // Setting height of the barcode
                code93.BarHeight = 45;
                code93.Text      = "ABC 123456789";

                //Printing barcode on to the Pdf.
                code93.Draw(page, new PointF(25, 600));

                g.DrawString("Type : Code93", font, brush, new PointF(200, 600));
                g.DrawString("Allowed Characters : 1 2 3 4 5 6 7 8 9 0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z - . $ / + % SPACE ", font, brush, new RectangleF(200, 620, 300, 200), format);

                g.DrawLine(pen, new PointF(0, 680), new PointF(width, 680));
                #endregion

                #region Code93Extended
                PdfCode93ExtendedBarcode code93ext = new PdfCode93ExtendedBarcode();

                //Setting height of the barcode
                code93ext.BarHeight = 45;
                code93ext.EncodeStartStopSymbols = true;
                code93ext.Text = "(abc) 123456789";

                //Printing barcode on to the Pdf.
                page = document.Pages.Add();
                code93ext.Draw(page, new PointF(25, 50));

                g = page.Graphics;
                g.DrawString("Type : Code93 Extended", font, brush, new PointF(200, 50));
                g.DrawString("Allowed Characters : All 128 ASCII characters ", font, brush, new PointF(200, 70));

                g.DrawLine(pen, new PointF(0, 120), new PointF(width, 120));
                #endregion

                #region Code128
                PdfCode128ABarcode barcode128A = new PdfCode128ABarcode();

                // Setting height of the barcode
                barcode128A.BarHeight              = 45;
                barcode128A.Text                   = "ABCD 12345";
                barcode128A.EnableCheckDigit       = true;
                barcode128A.EncodeStartStopSymbols = true;
                barcode128A.ShowCheckDigit         = true;

                //Printing barcode on to the Pdf.
                barcode128A.Draw(page, new PointF(25, 135));

                g.DrawString("Type : Code128 A", font, brush, new PointF(200, 135));
                g.DrawString("Allowed Characters : NUL (0x00) SOH (0x01) STX (0x02) ETX (0x03) EOT (0x04) ENQ (0x05) ACK (0x06) BEL (0x07) BS (0x08) HT (0x09) LF (0x0A) VT (0x0B) FF (0x0C) CR (0x0D) SO (0x0E) SI (0x0F) DLE (0x10) DC1 (0x11) DC2 (0x12) DC3 (0x13) DC4 (0x14) NAK (0x15) SYN (0x16) ETB (0x17) CAN (0x18) EM (0x19) SUB (0x1A) ESC (0x1B) FS (0x1C) GS (0x1D) RS (0x1E) US (0x1F) SPACE (0x20) \" ! # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ / ]^ _  ", font, brush, new RectangleF(200, 155, 300, 200), format);

                g.DrawLine(pen, new PointF(0, 250), new PointF(width, 250));

                PdfCode128BBarcode barcode128B = new PdfCode128BBarcode();

                // Setting height of the barcode
                barcode128B.BarHeight              = 45;
                barcode128B.Text                   = "12345 abcd";
                barcode128B.EnableCheckDigit       = true;
                barcode128B.EncodeStartStopSymbols = true;
                barcode128B.ShowCheckDigit         = true;

                //Printing barcode on to the Pdf.
                barcode128B.Draw(page, new PointF(25, 280));

                g.DrawString("Type : Code128 B", font, brush, new PointF(200, 280));
                g.DrawString("Allowed Characters : SPACE (0x20) !  \" # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ / ]^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ DEL (\x7F)  ", font, brush, new RectangleF(200, 300, 300, 200), format);

                g.DrawLine(pen, new PointF(0, 350), new PointF(width, 350));

                PdfCode128CBarcode barcode128C = new PdfCode128CBarcode();

                // Setting height of the barcode
                barcode128C.BarHeight              = 45;
                barcode128C.Text                   = "001122334455";
                barcode128C.EnableCheckDigit       = true;
                barcode128C.EncodeStartStopSymbols = true;
                barcode128C.ShowCheckDigit         = true;

                //Printing barcode on to the Pdf.
                barcode128C.Draw(page, new PointF(25, 370));

                g.DrawString("Type : Code128 C", font, brush, new PointF(200, 370));
                g.DrawString("Allowed Characters : 0 1 2 3 4 5 6 7 8 9 ", font, brush, new PointF(200, 390));

                g.DrawLine(pen, new PointF(0, 440), new PointF(width, 440));

                #endregion

                //Save the PDF document
                document.Save(stream);
            }

            stream.Position = 0;

            if (IsToggled)
            {
                PdfViewerUI pdfViewer = new SampleBrowser.PdfViewerUI();
                pdfViewer.PdfDocumentStream = stream;
                if (Device.Idiom != TargetIdiom.Phone && Device.OS == TargetPlatform.Windows)
                {
                    await PDFViewModel.Navigation.PushModalAsync(new NavigationPage(pdfViewer));
                }
                else
                {
                    await PDFViewModel.Navigation.PushAsync(pdfViewer);
                }
            }
            else
            {
                if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows)
                {
                    Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("Barcode.pdf", "application/pdf", stream);
                }
                else
                {
                    Xamarin.Forms.DependencyService.Get <ISave>().Save("Barcode.pdf", "application/pdf", stream);
                }
            }
        }
示例#3
0
        public async Task <IActionResult> TicketToPdf(int?id)

        // public IActionResult DetailsToPdf(int? id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var ticketsModelx = await _context.TicketsModel
                                .FirstOrDefaultAsync(m => m.id == id);

            ViewBag.details_NIP = ticketsModelx.NIP;
            if (ticketsModelx.getUser() != HttpContext.User.Identity.Name.ToString())
            {
                return(RedirectToAction(nameof(Index)));
            }
            if (ticketsModelx == null)
            {
                return(NotFound());
            }

            /*
             * // return View(ticketsModel);
             * //View(ticketsModel);
             *
             * HtmlToPdfConverter convert = new HtmlToPdfConverter();
             *
             * WebKitConverterSettings settings = new WebKitConverterSettings();
             * settings.WebKitPath = Path.Combine("QtBinariesWindows");
             * convert.ConverterSettings = settings;
             * Syncfusion.Pdf.PdfDocument document= convert.Convert("https://localhost:44366/EventsModels/TicketToPdf/30");
             * PdfPage page = document.Pages.Add();
             * MemoryStream ms = new MemoryStream();
             *
             * document.Save(ms);
             * document.Close(true);
             *
             * ms.Position = 0;
             *
             * FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf");
             * fileStreamResult.FileDownloadName = "test.pdf";
             *
             * return fileStreamResult;
             */


            //Create a new PDF document.
            PdfDocument doc = new PdfDocument();
            //Add a page.
            PdfPage page = doc.Pages.Add();
            //Create a PdfGrid.
            PdfGrid pdfGrid = new PdfGrid();
            //Add values to list
            List <Object> data = new List <Object>();
            Object        row1 = new { x = "email", y = ticketsModelx.getUser() };
            Object        row2 = new { x = "imie", y = ticketsModelx.user_name.ToString() };
            Object        row3 = new { x = "nazwisko", y = ticketsModelx.user_surname };
            Object        row4 = new { x = "Data i godzina", y = ticketsModelx.hour };
            Object        row5 = new { x = "Nazwa wydarzenia", y = ticketsModelx.name };
            Object        row6 = new { x = "Miejsce wydarzenia", y = ticketsModelx.place };

            data.Add(row6);
            data.Add(row5);
            data.Add(row4);
            data.Add(row2);
            data.Add(row3);
            data.Add(row1);
            //Add list to IEnumerable
            IEnumerable <Object> dataTable = data;

            //Assign data source.
            pdfGrid.DataSource = dataTable;
            //Draw grid to the page of PDF document.
            pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(20, 20));


            PdfQRBarcode barcode = new PdfQRBarcode();

            //PdfPage page = doc.Pages.Add();
            //Setting location of the barcode
            barcode.ErrorCorrectionLevel = PdfErrorCorrectionLevel.High;


            barcode.XDimension = 3;


            barcode.Location = new Syncfusion.Drawing.PointF(200, 200);

            //Setting size of the barcode

            barcode.Size = new Syncfusion.Drawing.SizeF(200, 100);

            barcode.Text = "https://localhost:44366/AP/Werify/" + ticketsModelx.event_id + "/" + ticketsModelx.id;

            //Printing barcode on to the Pdf.

            barcode.Draw(page);

            //Save and close the Document

            //doc.Save("CODABAR.pdf");

            //doc.Close(true);



            //Save the PDF document to stream
            MemoryStream stream = new MemoryStream();

            doc.Save(stream);
            //If the position is not set to '0' then the PDF will be empty.
            stream.Position = 0;
            //Close the document.
            doc.Close(true);
            //Defining the ContentType for pdf file.
            string contentType = "application/pdf";
            //Define the file name.
            string fileName = "Output.pdf";

            //Creates a FileContentResult object by using the file contents, content type, and file name.
            return(File(stream, contentType, fileName));
        }
        public ActionResult Barcode(string InsideBrowser)
        {
            //Create a new instance of PdfDocument class.
            PdfDocument document = new PdfDocument();

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

            //Create Pdf graphics for the page
            PdfGraphics g = page.Graphics;

            //Create a solid brush
            PdfBrush brush = PdfBrushes.Black;

            #region 2D Barcode

            //Set the font
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 15f, PdfFontStyle.Bold);

            PdfPen pen   = new PdfPen(brush, 0.5f);
            float  width = page.GetClientSize().Width;

            float xPos = page.GetClientSize().Width / 2;

            PdfStringFormat format = new PdfStringFormat();
            format.Alignment = PdfTextAlignment.Center;

            // Draw String
            g.DrawString("2D Barcodes", font, brush, new PointF(xPos, 10), format);

            #region QR Barcode
            font = new PdfStandardFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Bold);
            g.DrawString("QR Barcode", font, brush, new PointF(10, 70));

            PdfQRBarcode qrBarcode = new PdfQRBarcode();

            // Sets the Input mode to Binary mode
            qrBarcode.InputMode = InputMode.BinaryMode;

            // Automatically select the Version
            qrBarcode.Version = QRCodeVersion.Auto;

            // Set the Error correction level to high
            qrBarcode.ErrorCorrectionLevel = PdfErrorCorrectionLevel.High;

            // Set dimension for each block
            qrBarcode.XDimension = 2;
            qrBarcode.Text       = "Syncfusion Essential Studio Enterprise edition $995";

            // Draw the QR barcode
            qrBarcode.Draw(page, new PointF(25, 100));

            font = new PdfStandardFont(PdfFontFamily.TimesRoman, 9, PdfFontStyle.Regular);

            g.DrawString("Input Type :   Eight Bit Binary", font, brush, new PointF(250, 140));
            g.DrawString("Encoded Data : Syncfusion Essential Studio Enterprise edition $995", font, brush, new PointF(250, 160));

            g.DrawLine(pen, new PointF(0, 230), new PointF(width, 230));

            #endregion

            #region Datamatrix
            font = new PdfStandardFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Bold);
            g.DrawString("DataMatrix Barcode", font, brush, new PointF(10, 270));

            PdfDataMatrixBarcode dataMatrixBarcode = new PdfDataMatrixBarcode("5575235 Win7 4GB 64bit 7Jun2010");

            // Set dimension for each block
            dataMatrixBarcode.XDimension = 4;

            // Draw the barcode
            dataMatrixBarcode.Draw(page, new PointF(25, 310));

            font = new PdfStandardFont(PdfFontFamily.TimesRoman, 9, PdfFontStyle.Regular);

            g.DrawString("Symbol Type : Square", font, brush, new PointF(250, 360));
            g.DrawString("Encoded Data : 5575235 Win7 4GB 64bit 7Jun2010", font, brush, new PointF(250, 380));

            pen = new PdfPen(brush, 0.5f);
            g.DrawLine(pen, new PointF(0, 430), new PointF(width, 430));

            string text = "TYPE 3523 - ETWS/N FE- SDFHW 06/08";

            dataMatrixBarcode = new PdfDataMatrixBarcode(text);

            // rectangular matrix
            dataMatrixBarcode.Size = PdfDataMatrixSize.Size16x48;

            dataMatrixBarcode.XDimension = 4;

            dataMatrixBarcode.Draw(page, new PointF(25, 470));

            g.DrawString("Symbol Type : Rectangle", font, brush, new PointF(250, 490));
            g.DrawString("Encoded Data : " + text, font, brush, new PointF(250, 510));

            pen = new PdfPen(brush, 0.5f);

            g.DrawLine(pen, new PointF(0, 570), new PointF(width, 570));
            font = new PdfStandardFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Bold);
            g.DrawString("PDF417 Barcode", font, brush, new PointF(10, 620));
            Pdf417Barcode pdf417Barcode = new Pdf417Barcode();
            pdf417Barcode.Text = "https://www.syncfusion.com/";
            pdf417Barcode.ErrorCorrectionLevel = Pdf417ErrorCorrectionLevel.Auto;
            pdf417Barcode.XDimension           = 1f;
            pdf417Barcode.Size = new SizeF(200, 50);
            pdf417Barcode.Draw(page, new PointF(25, 670));


            font = new PdfStandardFont(PdfFontFamily.TimesRoman, 9, PdfFontStyle.Regular);
            g.DrawString("Encoded Data : https://www.syncfusion.com/", font, brush, new PointF(250, 680));


            #endregion
            # endregion

            # region 1D Barcode