예제 #1
0
        public ActionResult CreateDocumentWithoutFilter()
        {
            PdfFont font    = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
            PdfFont bigFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);

            PdfBrush    brush = new PdfSolidBrush(Syncfusion.Drawing.Color.Black);
            PdfDocument doc   = new PdfDocument();
            //Add a page to the document.
            PdfPage page = doc.Pages.Add();
            //Create PDF graphics for the page
            PdfGraphics graphics = page.Graphics;
            PdfGrid     pdfGrid  = new PdfGrid();

            //Load the image as stream.
            FileStream imageStream = new FileStream("logo.png", FileMode.Open, FileAccess.Read);
            PdfBitmap  image       = new PdfBitmap(imageStream);

            graphics.DrawImage(image, 200, 200);

            //Draw the image
            Syncfusion.Drawing.RectangleF bounds    = new Syncfusion.Drawing.RectangleF(0, 0, doc.Pages[0].GetClientSize().Width, 50);
            PdfPageTemplateElement        header    = new PdfPageTemplateElement(bounds);
            PdfCompositeField             compField = new PdfCompositeField(bigFont, brush, "OZO - Izvjestaj o referentnim tipovima");

            compField.Draw(header.Graphics, new Syncfusion.Drawing.PointF(120, 0));

            //Add the header at the top.

            doc.Template.Top = header;
            //Save the PDF document to stream
            //Create a Page template that can be used as footer.


            PdfPageTemplateElement footer = new PdfPageTemplateElement(bounds);



            //Create page number field.

            PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush);

            //Create page count field.

            PdfPageCountField count = new PdfPageCountField(font, brush);

            //Add the fields in composite fields.

            PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Stranica {0} od {1}", pageNumber, count);

            compositeField.Bounds = footer.Bounds;

            //Draw the composite field in footer.

            compositeField.Draw(footer.Graphics, new Syncfusion.Drawing.PointF(450, 40));

            //Add the footer template at the bottom.

            doc.Template.Bottom = footer;

            MemoryStream  stream = new MemoryStream();
            List <object> data   = new List <object>();

            var oprema = _context.ReferentniTip
                         .AsNoTracking()
                         .OrderBy(o => o.Id)
                         .ToList();

            foreach (var komad in oprema)
            {
                var row = new
                {
                    Naziv = komad.Naziv,
                };
                data.Add(row);
            }



            //Add list to IEnumerable
            IEnumerable <object> dataTable = data;

            //Assign data source.
            pdfGrid.DataSource = dataTable;
            pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(50, 50));
            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 = "Referentni tipovi-Reports.pdf";

            return(File(stream, contentType, fileName));
        }
예제 #2
0
        public ActionResult CreateDocument(string id, string vrsta, string znak)
        {
            PdfFont font    = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
            PdfFont bigFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);

            PdfBrush    brush = new PdfSolidBrush(Syncfusion.Drawing.Color.Black);
            PdfDocument doc   = new PdfDocument();
            //Add a page to the document.
            PdfPage page = doc.Pages.Add();
            //Create PDF graphics for the page
            PdfGraphics graphics = page.Graphics;
            PdfGrid     pdfGrid  = new PdfGrid();

            //Load the image as stream.
            FileStream imageStream = new FileStream("logo.png", FileMode.Open, FileAccess.Read);
            PdfBitmap  image       = new PdfBitmap(imageStream);

            graphics.DrawImage(image, 200, 200);

            //Draw the image
            Syncfusion.Drawing.RectangleF bounds    = new Syncfusion.Drawing.RectangleF(0, 0, doc.Pages[0].GetClientSize().Width, 50);
            PdfPageTemplateElement        header    = new PdfPageTemplateElement(bounds);
            PdfCompositeField             compField = new PdfCompositeField(bigFont, brush, "OZO - Izvjestaj o zaposlenicima");

            compField.Draw(header.Graphics, new Syncfusion.Drawing.PointF(120, 0));

            //Add the header at the top.

            doc.Template.Top = header;
            //Save the PDF document to stream
            //Create a Page template that can be used as footer.


            PdfPageTemplateElement footer = new PdfPageTemplateElement(bounds);



            //Create page number field.

            PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush);

            //Create page count field.

            PdfPageCountField count = new PdfPageCountField(font, brush);

            //Add the fields in composite fields.

            PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Stranica {0} od {1}", pageNumber, count);

            compositeField.Bounds = footer.Bounds;

            //Draw the composite field in footer.

            compositeField.Draw(footer.Graphics, new Syncfusion.Drawing.PointF(450, 40));

            //Add the footer template at the bottom.

            doc.Template.Bottom = footer;

            MemoryStream stream = new MemoryStream();
            //Add values to list
            List <object> data = new List <object>();

            switch (vrsta)
            {
            case "Ime":

                var zaposlenici = _context.Zaposlenik
                                  .AsNoTracking()
                                  .Where(n => n.Ime.Equals(id))
                                  .OrderBy(o => o.Id)
                                  .ToList();
                ispisi(zaposlenici, data);

                break;

            case "Plaća":
                int plaća = int.Parse(id);

                if (znak == "manje")
                {
                    zaposlenici = _context.Zaposlenik
                                  .AsNoTracking()
                                  .Where(n => n.Plaća < plaća)
                                  .OrderBy(o => o.Id)
                                  .ToList();
                    ispisi(zaposlenici, data);
                }
                else if (znak == "vise")
                {
                    zaposlenici = _context.Zaposlenik
                                  .AsNoTracking()
                                  .Where(n => n.Plaća > plaća)
                                  .OrderBy(o => o.Id)
                                  .ToList();
                    ispisi(zaposlenici, data);
                }
                else
                {
                    zaposlenici = _context.Zaposlenik
                                  .AsNoTracking()
                                  .Where(n => n.Plaća.Equals(plaća))
                                  .OrderBy(o => o.Id)
                                  .ToList();
                    ispisi(zaposlenici, data);
                }
                break;

            case "Datum":
                zaposlenici = _context.Zaposlenik
                              .AsNoTracking()
                              .Where(n => n.Datum.Equals(id))
                              .OrderBy(o => o.Id)
                              .ToList();
                ispisi(zaposlenici, data);

                break;

            case "NazivSkole":
                zaposlenici = _context.Zaposlenik
                              .AsNoTracking()
                              .Where(n => n.NazivŠkole.Equals(id))
                              .OrderBy(o => o.Id)
                              .ToList();
                ispisi(zaposlenici, data);

                break;

            case "StručnaSprema":
                zaposlenici = _context.Zaposlenik
                              .AsNoTracking()
                              .Where(n => n.StručnaSprema.Equals(id))
                              .OrderBy(o => o.Id)
                              .ToList();
                ispisi(zaposlenici, data);
                break;

            default:
                Console.WriteLine("Niste unijeli string");
                break;
            }



            //Add list to IEnumerable
            IEnumerable <object> dataTable = data;

            //Assign data source.
            pdfGrid.DataSource = dataTable;
            pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(50, 50));

            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 = "Zaposlenici-Reports.pdf";

            return(File(stream, contentType, fileName));
        }