void Pdf_Clicked(object sender, EventArgs args)
        {
            PdfDocument document = new PdfDocument();
            document.PageSettings.Orientation = PdfPageOrientation.Landscape;
            document.PageSettings.Margins.All = 50;
            PdfPage page = document.Pages.Add();
            PdfGraphics g = page.Graphics;
            PdfTextElement element = new PdfTextElement(@"Syncfusion Software 
2501 Aerial Center Parkway 
Suite 200 Morrisville, NC 27560 USA 
Tel +1 888.936.8638 Fax +1 919.573.0306");
            element.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 12);
            element.Brush = new PdfSolidBrush(new PdfColor(89, 89, 93));
            PdfLayoutResult result = element.Draw(page, new RectangleF(0, 0, page.Graphics.ClientSize.Width / 2, 200));
            Stream imgStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("XamarinIOInvoice.SyncfusionLogo.jpg");
            PdfImage img = PdfImage.FromStream(imgStream);
            page.Graphics.DrawImage(img, new RectangleF(g.ClientSize.Width - 200, result.Bounds.Y, 190, 45));
            PdfFont subHeadingFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 14);
            g.DrawRectangle(new PdfSolidBrush(new PdfColor(126, 151, 173)), new RectangleF(0, result.Bounds.Bottom + 40, g.ClientSize.Width, 20));


            PdfGrid grid = new PdfGrid();
            grid.DataSource = GetDataSource();
            PdfGridCellStyle cellStyle = new PdfGridCellStyle();
            cellStyle.Borders.All = PdfPens.White;
            PdfGridRow header = grid.Headers[0];

            PdfGridCellStyle headerStyle = new PdfGridCellStyle();
            headerStyle.Borders.All = new PdfPen(new PdfColor(126, 151, 173));
            headerStyle.BackgroundBrush = new PdfSolidBrush(new PdfColor(126, 151, 173));
            headerStyle.TextBrush = PdfBrushes.White;
            headerStyle.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f, PdfFontStyle.Regular);

            for (int i = 0; i < header.Cells.Count; i++)
            {
                if (i == 0)
                    header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                else
                    header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
            }

            header.ApplyStyle(headerStyle);
            cellStyle.Borders.Bottom = new PdfPen(new PdfColor(217, 217, 217), 0.70f);
            cellStyle.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 12f);
            cellStyle.TextBrush = new PdfSolidBrush(new PdfColor(131, 130, 136));
            foreach (PdfGridRow row in grid.Rows)
            {
                row.ApplyStyle(cellStyle);
                for (int i = 0; i < row.Cells.Count; i++)
                {
                    PdfGridCell cell = row.Cells[i];
                    if (i == 0)
                        cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                    else
                        cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);

                    if (i > 1)
                    {
                        float val = float.MinValue;
                        float.TryParse(cell.Value.ToString(), out val);
                        cell.Value = "$" + val.ToString();
                    }
                }
            }

            PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat();
            layoutFormat.Layout = PdfLayoutType.Paginate;

            PdfGridLayoutResult gridResult = grid.Draw(page, new RectangleF(new Syncfusion.Drawing.PointF(0, result.Bounds.Bottom + 40), new Syncfusion.Drawing.SizeF(g.ClientSize.Width, g.ClientSize.Height - 100)), layoutFormat);
            float pos = 0.0f;
            for (int i = 0; i < grid.Columns.Count - 1; i++)
                pos += grid.Columns[i].Width;

            PdfFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f);

            gridResult.Page.Graphics.DrawString("Total Due", font, new PdfSolidBrush(new PdfColor(126, 151, 173)), new RectangleF(new Syncfusion.Drawing.PointF(pos, gridResult.Bounds.Bottom + 20), new Syncfusion.Drawing.SizeF(grid.Columns[3].Width - pos, 20)), new PdfStringFormat(PdfTextAlignment.Right));
            gridResult.Page.Graphics.DrawString("Thank you for your business!", new PdfStandardFont(PdfFontFamily.TimesRoman, 12), new PdfSolidBrush(new PdfColor(89, 89, 93)), new Syncfusion.Drawing.PointF(pos - 55, gridResult.Bounds.Bottom + 60));
            pos += grid.Columns[4].Width;
            gridResult.Page.Graphics.DrawString("$13600", font, new PdfSolidBrush(new PdfColor(131, 130, 136)), new RectangleF(new Syncfusion.Drawing.PointF(pos, gridResult.Bounds.Bottom + 20), new Syncfusion.Drawing.SizeF(grid.Columns[4].Width - pos, 20)), new PdfStringFormat(PdfTextAlignment.Right));


            MemoryStream data = new MemoryStream();

            document.Save(data);

            document.Close();

            DependencyService.Get<ISave>().SaveTextAsync("Invoice.pdf", "application/pdf", data);
          

        }
Esempio n. 2
0
        public void ExportToPdf(List <T> entities, string reportTitle, ReportRequest reportRequest, List <string> columns)
        {
            int         paragraphAfterSpacing = 8;
            int         cellMargin            = 8;
            PdfDocument pdfDocument           = new PdfDocument();
            //Add Page to the PDF document.
            PdfPage page = pdfDocument.Pages.Add();

            //Create a new font.
            PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 16);

            //Create a text element to draw a text in PDF page.
            PdfTextElement  title  = new PdfTextElement(reportTitle, font, PdfBrushes.Black);
            PdfLayoutResult result = title.Draw(page, new PointF(0, 0));

            var contentInfo = CreateContentInfo(reportRequest, entities);

            PdfStandardFont contentFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 12);
            PdfTextElement  content     = new PdfTextElement(contentInfo, contentFont, PdfBrushes.Black);
            PdfLayoutFormat format      = new PdfLayoutFormat();

            format.Layout = PdfLayoutType.Paginate;

            //Draw a text to the PDF document.
            result = content.Draw(page, new RectangleF(0, result.Bounds.Bottom + paragraphAfterSpacing, page.GetClientSize().Width, page.GetClientSize().Height), format);

            //Create a PdfGrid.
            PdfGrid pdfGrid = new PdfGrid();

            pdfGrid.Style.CellPadding.Left  = cellMargin;
            pdfGrid.Style.CellPadding.Right = cellMargin;

            //Applying built-in style to the PDF grid
            pdfGrid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable4Accent1);

            //Create data to populate table
            DataTable table = CreateDataSourceTable(entities, columns);

            //Assign data source.
            pdfGrid.DataSource = table;

            pdfGrid.Style.Font = contentFont;

            //Draw PDF grid into the PDF page.
            pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(0, result.Bounds.Bottom + paragraphAfterSpacing));

            MemoryStream memoryStream = new MemoryStream();

            // Save the PDF document.
            pdfDocument.Save(memoryStream);

            // Download the PDF document
            _jsRuntime.SaveAs(reportTitle + ".pdf", memoryStream.ToArray());
        }
Esempio n. 3
0
 private void initTable()
 {
     _initTable = new InitTable
     {
         SharedData         = _commonManagersInfoData,
         CurrentRowInfoData = CurrentRowInfoData
     };
     _initTable.CreateMainTable();
     _mainTable       = _initTable.MainTable;
     _tableCellHelper = _initTable.TableCellHelper;
 }
Esempio n. 4
0
        public MemoryStream CreatePdf(Vacunados[] vacuna)
        {
            if (vacuna == null)
            {
                throw new ArgumentException("Data Cannot be null");
            }

            //Create a new PDF document
            using (PdfDocument pdfDocument = new PdfDocument())
            {
                int paragraphAfterSpacing = 8;
                int cellMargin            = 8;

                //Add page to the pdf document
                PdfPage page = pdfDocument.Pages.Add();

                //Create new font
                PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 16);

                //Create a tex elemnt to draw a text in pdf page
                PdfTextElement  title  = new PdfTextElement("Weather Forecast", font, PdfBrushes.Black);
                PdfLayoutResult result = title.Draw(page, new PointF(0, 0));

                PdfStandardFont contentfont = new PdfStandardFont(PdfFontFamily.TimesRoman, 12);
                PdfLayoutFormat format      = new PdfLayoutFormat();
                format.Layout = PdfLayoutType.Paginate;

                //Create a pdf
                PdfGrid pdfGrid = new PdfGrid();
                pdfGrid.Style.CellPadding.Left  = cellMargin;
                pdfGrid.Style.CellPadding.Right = cellMargin;


                //Applying built in style to the PDF
                pdfGrid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable4Accent1);


                //Assing Data Source
                pdfGrid.DataSource = vacuna.ToList();

                pdfGrid.Style.Font = contentfont;


                //Draw pdf grid into the pdf page
                pdfGrid.Draw(page, new PointF(0, result.Bounds.Bottom + paragraphAfterSpacing));

                using (MemoryStream stream = new MemoryStream())
                {
                    pdfDocument.Save(stream);
                    pdfDocument.Close(true);
                    return(stream);
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Adds a new row to the specified table.
        /// The default IColumnItemsTemplate would be TextBlockField.
        /// </summary>
        public static void AddSimpleRow(this PdfGrid table, params Action <CellRowData, CellBasicProperties>[] cellsData)
        {
            if (table.NumberOfColumns != cellsData.Length)
            {
                throw new InvalidOperationException("table.NumberOfColumns(" + table.NumberOfColumns + ") != cellsData.Length(" + cellsData.Length + ")");
            }

            foreach (var item in cellsData)
            {
                addSimpleRowCell(table, item);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Get the Total amount of purcharsed items
        /// </summary>
        /// <param name="grid"></param>
        /// <returns></returns>
        private float GetTotalAmount(PdfGrid grid)
        {
            float Total = 0f;

            for (int i = 0; i < grid.Rows.Count; i++)
            {
                string cellValue = grid.Rows[i].Cells[grid.Columns.Count - 1].Value.ToString();
                float  result    = float.Parse(cellValue, System.Globalization.CultureInfo.InvariantCulture);
                Total += result;
            }
            return(Total);
        }
        /// <summary>
        /// Get the Total amount of purcharsed items
        /// </summary>
        /// <param name="grid"></param>
        /// <returns></returns>
        private float GetTotalAmount(PdfGrid grid)
        {
            float Total = 0f;

            for (int i = 0; i < grid.Rows.Count; i++)
            {
                string cellValue = grid.Rows[i].Cells[grid.Columns.Count - 1].Value.ToString();
                float  result;
                Total += float.TryParse(cellValue, out result) ? result : 0;
            }
            return(Total);
        }
        private void GeneratePDF()
        {
            //Stream fontStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Assets.arial.ttf");
            //PdfTrueTypeFont font = new PdfTrueTypeFont(fontStream, 12);

            //Create a new PDF document
            using (PdfDocument doc = new PdfDocument())
            {
                //Font initialization.
                System.Drawing.Font tempfont = new System.Drawing.Font("/App_Data/ARIALUNI.ttf", 11, FontStyle.Regular);
                //Enable unicode to draw unicode characters.
                PdfTrueTypeFont currentFont = new PdfTrueTypeFont(tempfont, true);


                //Add a page
                PdfPage page = doc.Pages.Add();

                //Create a PdfGrid
                PdfGrid pdfGrid = new PdfGrid();
                //  RSD --PdfFont font = new PdfTrueTypeFont(Server.MapPath("/App_Data/ARIALUNI.ttf"), 24);
                //   Stream fontStream = typeof(SOSubmitChecklist).GetTypeInfo().Assembly.GetManifestResourceStream("Demo.Assets.arial.ttf");

                pdfGrid.Style.Font = new PdfTrueTypeFont(currentFont, 12);

                //Create a DataTable
                DataTable SO1CheckList = new DataTable();

                dsShowAllDocData = dbFamilyDetailsData.getSO1SubmitCheckList(cmbVillage.SelectedValue.ToString(), cmbDocumentNo.SelectedValue.ToString(), "SO1");
                if (dsShowAllDocData.Tables[0].Rows.Count > 0)
                {
                    SO1CheckList = dsShowAllDocData.Tables[0];
                }

                //Assign data source
                pdfGrid.DataSource = SO1CheckList;

                //Draw grid to the page of PDF document
                pdfGrid.Draw(page, new PointF(20, 10));
                //Font
                pdfGrid.Style.Font = new PdfTrueTypeFont(currentFont, 12);
                //PdfFont font = new PdfTrueTypeFont(new Font("Arial Unicode MS Regular", 12, FontStyle.Regular), true);
                PdfTextElement textElement = new PdfTextElement("Unicode characters राजेंद्र ");
                textElement.Font  = new PdfTrueTypeFont(currentFont, 12);
                textElement.Brush = PdfBrushes.Black;
                textElement.Draw(page, new PointF(10, 10));

                //pdfGrid.PDFFonts = new Dictionary<string, Stream>(StringComparer.OrdinalIgnoreCase);
                //pdfGrid.PDFFonts.Add("MS Mincho", assembly.GetManifestResourceStream("WinRTSampleApplication.Assets.msmincho.ttf"));
                //Save the document

                doc.Save(@"F:\\Output.pdf");
            }
        }
Esempio n. 9
0
        private void OnButtonClick(object sender, RoutedEventArgs e)
        {
            //Create a new PDF document
            PdfDocument doc = new PdfDocument();

            //Add a new PDF page
            PdfPage page = doc.Pages.Add();

            // Create PDF graphics for a page
            PdfGraphics graphics = page.Graphics;

            //Set the standard font
            PdfFont font  = new PdfStandardFont(PdfFontFamily.TimesRoman, 20);
            PdfFont font2 = new PdfStandardFont(PdfFontFamily.TimesRoman, 10);
            PdfFont font3 = new PdfStandardFont(PdfFontFamily.Courier, 7);
            PdfPen  pen   = new PdfPen(System.Drawing.Color.Black);


            //Draw the text
            graphics.DrawString("High on Flavours", font, PdfBrushes.Black, new PointF(190, 0));
            graphics.DrawString("experience India ...", font2, PdfBrushes.Black, new PointF(300, 20));
            graphics.DrawString("Bonhoefferstraße 4/1, 69123 Heidelberg", font3, PdfBrushes.Black, new PointF(185, 40));
            graphics.DrawString("Ph no: +49 12345678910        Email: [email protected]", font3, PdfBrushes.Black, new PointF(150, 50));
            graphics.DrawLine(pen, new PointF(0, 60), new PointF(950, 60));
            graphics.DrawLine(pen, new PointF(0, page.Graphics.ClientSize.Height - 100), new PointF(950, page.Graphics.ClientSize.Height - 100));
            graphics.DrawString("Total:", font2, PdfBrushes.Black, new PointF(400, page.Graphics.ClientSize.Height - 80));



            //Create a new PDF grid
            PdfGrid grid = new PdfGrid();

            //Add the data source
            grid.DataSource = finalBillOrder;

            //Apply built-in grid style
            //grid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable6Colorful);

            //Creates the layout format for grid
            PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat();

            //Set the layout type as paginate
            layoutFormat.Layout = PdfLayoutType.OnePage;

            //Draws the grid to the PDF page
            PdfGridLayoutResult gridResult = grid.Draw(page, new RectangleF(new PointF(0, 75), new SizeF(page.Graphics.ClientSize.Width, page.Graphics.ClientSize.Height - 100)), layoutFormat);

            //Save the PDF stream to physical file
            doc.Save("outputGRD.pdf");
            System.Diagnostics.Process.Start("outputGRD.pdf");
            doc.Close(true);
        }
Esempio n. 10
0
        public static void SetGridTextAlignmentByGrid(PdfGrid grid, PdfTextAlignment alignment)
        {
            int RowCount = grid.Rows.Count;

            for (int r = 0; r < RowCount; r++)
            {
                int CellCount = grid.Rows[r].Cells.Count;
                for (int i = 0; i < CellCount; i++)
                {
                    grid.Rows[r].Cells[i].StringFormat.Alignment = alignment;
                }
            }
        }
        private void Grid_BeginCellLayout(object sender, PdfGridBeginCellLayoutEventArgs args)
        {
            PdfGrid grid = sender as PdfGrid;

            if (args.CellIndex == grid.Columns.Count - 1)
            {
                TotalPriceCellBounds = args.Bounds;
            }
            else if (args.CellIndex == grid.Columns.Count - 2)
            {
                QuantityCellBounds = args.Bounds;
            }
        }
Esempio n. 12
0
        public static void SetGridPaddingByGrid(PdfGrid grid, float all)
        {
            int RowCount = grid.Rows.Count;

            for (int r = 0; r < RowCount; r++)
            {
                int CellCount = grid.Rows[r].Cells.Count;
                for (int i = 0; i < CellCount; i++)
                {
                    grid.Rows[r].Cells[i].Style.CellPadding = new PdfPaddings(all, all, all, all);
                }
            }
        }
Esempio n. 13
0
        public static void SetGridPaddingByGrid(PdfGrid grid, float left, float top, float right, float bottom)
        {
            int RowCount = grid.Rows.Count;

            for (int r = 0; r < RowCount; r++)
            {
                int CellCount = grid.Rows[r].Cells.Count;
                for (int i = 0; i < CellCount; i++)
                {
                    grid.Rows[r].Cells[i].Style.CellPadding = new PdfPaddings(left, right, top, bottom);
                }
            }
        }
Esempio n. 14
0
        /// <summary>Creates the PDF summary.</summary>
        /// <param name="path">The path.</param>
        /// <param name="Tourlist">The tourlist.</param>
        /// <returns>
        ///   <para>No Returnvalue, but may throw a Directory not found Exception</para>
        /// </returns>
        public static int CreatePdfSummary(string path, ObservableCollection <Tour> Tourlist)
        {
            try
            {
                FileStream fs = File.Open(Path.Combine(path, "Report.pdf"), FileMode.Create);
                if (!fs.CanWrite)
                {
                    return(-1);
                }
                PdfDocument document = new PdfDocument();

                PdfPage page = document.Pages.Add();

                PdfGraphics graphics = page.Graphics;

                PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);

                graphics.DrawString("Tour Summary", font, PdfBrushes.Black, new PointF(10, 10));

                PdfGrid pdfGrid = new PdfGrid();
                //Create a DataTable
                DataTable dataTable = new DataTable();
                //Add columns to the DataTable
                dataTable.Columns.Add("Name");
                dataTable.Columns.Add("Description");
                dataTable.Columns.Add("Source");
                dataTable.Columns.Add("Destination");
                dataTable.Columns.Add("Distance");
                dataTable.Columns.Add("Number of Logs");
                //Add rows to the DataTable
                foreach (Tour tl in Tourlist)
                {
                    dataTable.Rows.Add(tl.PrintToPDF());
                }
                //Assign data source
                pdfGrid.DataSource = dataTable;
                //Draw grid to the page of PDF document
                pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(10, 40));

                document.Save(fs);

                document.Close(true);
                fs.Close();
            }
            catch (Exception e)
            {
                throw e;
            }

            return(0);
        }
Esempio n. 15
0
        /// <summary>
        /// Creates a new PdfGrid with one column and row.
        /// </summary>
        /// <param name="phrase">An optional phrase to display</param>
        /// <param name="widthPercentage">Width of the table</param>
        /// <param name="fixedHeight">Height of the table</param>
        /// <param name="border">Border width</param>
        /// <returns>A PdfGrid</returns>
        public static PdfGrid CreateEmptyRowTable(string phrase = " ", float widthPercentage = 100, float fixedHeight = 35, int border = 0)
        {
            var table = new PdfGrid(1)
            {
                WidthPercentage = widthPercentage
            };
            var emptyHeaderCell = new PdfPCell(new Phrase(phrase))
            {
                Border = border, FixedHeight = fixedHeight
            };

            table.AddCell(emptyHeaderCell);
            return(table);
        }
        public Stream CreateZugFerdXML()
        {
            //Create ZugFerd Invoice
            ZugFerdInvoice invoice = new ZugFerdInvoice("2058557939", new DateTime(2013, 6, 5), CurrencyCodes.USD);

            //Set ZugFerdProfile to ZugFerdInvoice
            invoice.Profile = ZugFerdProfile.Basic;

            //Add buyer details
            invoice.Buyer = new UserDetails
            {
                ID          = "Abraham_12",
                Name        = "Abraham Swearegin",
                ContactName = "Swearegin",
                City        = "United States, California",
                Postcode    = "9920",
                Country     = CountryCodes.US,
                Street      = "9920 BridgePointe Parkway"
            };

            //Add seller details
            invoice.Seller = new UserDetails
            {
                ID          = "Adventure_123",
                Name        = "AdventureWorks",
                ContactName = "Adventure support",
                City        = "Austin,TX",
                Postcode    = "",
                Country     = CountryCodes.US,
                Street      = "800 Interchange Blvd"
            };


            IEnumerable <Product> products = GetProductReport();

            foreach (var product in products)
            {
                invoice.AddProduct(product);
            }

            PdfGrid grid = new PdfGrid();

            grid.DataSource     = GetProductReport();
            invoice.TotalAmount = GetTotalAmount(grid);

            MemoryStream ms = new MemoryStream();

            //Save ZugFerd Xml
            return(invoice.Save(ms));
        }
        private async void button2_Click(object sender, RoutedEventArgs e)
        {
            //Create a new PDF document.
            PdfDocument pdfDocument = new PdfDocument();

            //Create the page
            PdfPage pdfPage = pdfDocument.Pages.Add();

            //Create the parent grid
            PdfGrid parentPdfGrid = new PdfGrid();

            parentPdfGrid.Columns.Add(CellGrid.ColumnCount);
            //Add the rows
            for (int i = 0; i < CellGrid.RowCount; i++)
            {
                PdfGridRow row1 = parentPdfGrid.Rows.Add();
                row1.Height = 50;
                for (int j = 0; j < CellGrid.ColumnCount; j++)
                {
                    var         style       = CellGrid.Model[i, j];
                    PdfGridCell pdfGridCell = parentPdfGrid.Rows[i].Cells[j];
                    pdfGridCell.Value = style.CellValue;
                    var brush = (style.Background as SolidColorBrush);
                    //Export with style
                    if (brush != null)
                    {
                        pdfGridCell.Style.BackgroundBrush = new PdfSolidBrush(new PdfColor(System.Drawing.Color.FromArgb(brush.Color.A, brush.Color.R, brush.Color.G, brush.Color.B)));
                    }
                }
            }

            //Draw the PdfGrid.
            parentPdfGrid.Draw(pdfPage, PointF.Empty);
            StorageFile   storageFile;
            StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;

            storageFile = await local.CreateFileAsync("Sample.pdf", CreationCollisionOption.ReplaceExisting);

            //Save the document.
            await pdfDocument.SaveAsync(storageFile);

            FileStream stream = File.OpenRead(storageFile.Path);

            this.pdfViewer.Unload();
            this.pdfViewer.LoadDocument(stream);
            //Print the pdf file.
            this.pdfViewer.Print();
            this.pdfViewer.Visibility = Visibility.Collapsed;
        }
Esempio n. 18
0
        private void Grid_BeginCellLayout(object sender, PdfGridBeginCellLayoutEventArgs args)
        {
            PdfGrid grid = sender as PdfGrid;

            if (args.CellIndex == grid.Columns.Count - 1)
            {
                //Get the bounds of price cell in grid row.
                TotalPriceCellBounds = args.Bounds;
            }
            else if (args.CellIndex == grid.Columns.Count - 2)
            {
                //Get the bounds of quantity cell in grid row.
                QuantityCellBounds = args.Bounds;
            }
        }
Esempio n. 19
0
        // Public Methods (6) 

        /// <summary>
        /// Adds a border to an existing PdfGrid
        /// </summary>
        /// <param name="table">Table</param>
        /// <param name="borderColor">Border's color</param>
        /// <param name="spacingBefore">Spacing before the table</param>
        /// <returns>A new PdfGrid</returns>
        public static PdfGrid AddBorderToTable(this PdfGrid table, BaseColor borderColor, float spacingBefore)
        {
            var outerTable = new PdfGrid(numColumns: 1)
            {
                WidthPercentage = table.WidthPercentage,
                SpacingBefore   = spacingBefore
            };
            var pdfCell = new PdfPCell(table)
            {
                BorderColor = borderColor
            };

            outerTable.AddCell(pdfCell);
            return(outerTable);
        }
        public IActionResult Post([FromBody] Prescription prescription)
        {
            PdfDocument doc = new PdfDocument();

            PdfPage page = doc.Pages.Add();

            PdfGrid pdfGrid = new PdfGrid();

            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);

            PdfGraphics graphics = page.Graphics;

            graphics.DrawString("Prescription from Dr. Sangeetha generated at " + DateTime.Now, font, PdfBrushes.Black, new PointF(0, 0));

            List <object> data = new List <object>();
            Object        row1 = new { ID = "\n  PatientName", Name = "\n  " + prescription.Name + "\n" };
            Object        row2 = new { ID = "\n  Age & gender", Name = "\n " + prescription.Age + "\n" };
            Object        row3 = new { ID = "\n  Symptoms", Name = "\n  " + prescription.Symptoms + "\n" };
            Object        row4 = new { ID = "\n  Diagnosis", Name = "\n  " + prescription.Diagnosis + "\n" };
            Object        row5 = new { ID = "\n  Remarks", Name = "\n  " + prescription.Remarks + "\n" };

            data.Add(row1);
            data.Add(row2);
            data.Add(row3);
            data.Add(row4);
            data.Add(row5);
            //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(10, 20));
            //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 = "Prescription.pdf";

            return(File(stream, contentType, fileName));
        }
Esempio n. 21
0
        public static void SetGridBorderBrushByGrid(PdfGrid grid, PdfBrush all)
        {
            int RowCount = grid.Rows.Count;

            for (int r = 0; r < RowCount; r++)
            {
                int CellCount = grid.Rows[r].Cells.Count;
                for (int i = 0; i < CellCount; i++)
                {
                    grid.Rows[r].Cells[i].Style.Borders.Left.Brush   = all;
                    grid.Rows[r].Cells[i].Style.Borders.Top.Brush    = all;
                    grid.Rows[r].Cells[i].Style.Borders.Right.Brush  = all;
                    grid.Rows[r].Cells[i].Style.Borders.Bottom.Brush = all;
                }
            }
        }
Esempio n. 22
0
        public static void SetGridBorderBrushByGrid(PdfGrid grid, PdfBrush left, PdfBrush top, PdfBrush right, PdfBrush bottom)
        {
            int RowCount = grid.Rows.Count;

            for (int r = 0; r < RowCount; r++)
            {
                int CellCount = grid.Rows[r].Cells.Count;
                for (int i = 0; i < CellCount; i++)
                {
                    grid.Rows[r].Cells[i].Style.Borders.Left.Brush   = left;
                    grid.Rows[r].Cells[i].Style.Borders.Top.Brush    = top;
                    grid.Rows[r].Cells[i].Style.Borders.Right.Brush  = right;
                    grid.Rows[r].Cells[i].Style.Borders.Bottom.Brush = bottom;
                }
            }
        }
Esempio n. 23
0
        private void initWrapping()
        {
            if (!_shouldWrapTablesInColumns)
            {
                return;
            }
            if (_pageSetup.PagePreferences.RunDirection == null)
            {
                _pageSetup.PagePreferences.RunDirection = PdfRunDirection.LeftToRight;
            }

            _mainGroupTable = new PdfGrid(1)
            {
                SplitLate = false, WidthPercentage = 100, RunDirection = (int)_pageSetup.PagePreferences.RunDirection
            };
        }
Esempio n. 24
0
        public static void SetGridBorderWidthByGrid(PdfGrid grid, float left, float top, float right, float bottom)
        {
            int RowCount = grid.Rows.Count;

            for (int r = 0; r < RowCount; r++)
            {
                int CellCount = grid.Rows[r].Cells.Count;
                for (int i = 0; i < CellCount; i++)
                {
                    grid.Rows[r].Cells[i].Style.Borders.Left.Width   = left;
                    grid.Rows[r].Cells[i].Style.Borders.Top.Width    = top;
                    grid.Rows[r].Cells[i].Style.Borders.Right.Width  = right;
                    grid.Rows[r].Cells[i].Style.Borders.Bottom.Width = bottom;
                }
            }
        }
Esempio n. 25
0
        private PdfLayoutResult DrawVendor(PdfPageBase page, DataTable vendors, int index, String title, float y)
        {
            //draw title
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold));
            DataRow         row   = vendors.Rows[index];

            page.Canvas.DrawString(title, font1, PdfBrushes.Black, 0, y);
            y = y + font1.MeasureString(title).Height + 1;

            //draw table
            Object[][] data = new Object[vendors.Columns.Count][];
            for (int i = 0; i < vendors.Columns.Count; i++)
            {
                data[i]    = new Object[2];
                data[i][0] = vendors.Columns[i].ColumnName;
                data[i][1] = vendors.Rows[index].ItemArray[i];
            }

            PdfGrid grid = new PdfGrid();

            grid.Style.CellPadding = new PdfPaddings(2, 2, 1, 1);
            grid.DataSource        = data;

            float width
                = page.Canvas.ClientSize.Width
                  - (grid.Columns.Count + 1) * 0.75f;

            grid.Columns[0].Width = width * 0.20f;
            grid.Columns[1].Width = width * 0.80f;

            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold));
            PdfTrueTypeFont font3 = new PdfTrueTypeFont(new Font("Arial", 10f));

            for (int i = 0; i < grid.Rows.Count; i++)
            {
                grid.Rows[i].Style.Font = font2;
                grid.Rows[i].Cells[0].Style.BackgroundBrush = PdfBrushes.CadetBlue;
                grid.Rows[i].Cells[1].Style.BackgroundBrush = PdfBrushes.SkyBlue;
            }

            PdfGridLayoutFormat layout = new PdfGridLayoutFormat();

            layout.Break  = PdfLayoutBreakType.FitPage;
            layout.Layout = PdfLayoutType.Paginate;

            return(grid.Draw(page, new PointF(0, y), layout));
        }
Esempio n. 26
0
        // Public Methods (2) 


        /// <summary>
        /// Creates and initializes the MainTable's settings
        /// </summary>
        public void CreateMainTable()
        {
            setHeaderAndFooterRows();

            var len = SharedData.ColumnsWidths.Length;

            if (SharedData.IsMainTableHorizontalStackPanel)
            {
                len = SharedData.HorizontalStackPanelColumnsPerRow;
            }
            if (len == 0)
            {
                throw new InvalidOperationException("At least one column should be defined or visible.");
            }

            if (SharedData.PageSetup.PagePreferences.RunDirection == null)
            {
                SharedData.PageSetup.PagePreferences.RunDirection = PdfRunDirection.LeftToRight;
            }

            setDefaultSpacingAfterForGroups();

            MainTable = new PdfGrid(len)
            {
                RunDirection    = (int)SharedData.PageSetup.PagePreferences.RunDirection,
                WidthPercentage = SharedData.PageSetup.MainTablePreferences.WidthPercentage,
                HeadersInEvent  = true,
                HeaderRows      = _headerRows,
                FooterRows      = _footerRows,
                SkipFirstHeader = true,
                SplitLate       = SharedData.PageSetup.MainTablePreferences.SplitLate,
                SpacingAfter    = SharedData.PageSetup.MainTablePreferences.SpacingAfter,
                SpacingBefore   = SharedData.PageSetup.MainTablePreferences.SpacingBefore,
                KeepTogether    = SharedData.PageSetup.MainTablePreferences.KeepTogether,
                SplitRows       = SharedData.PageSetup.MainTablePreferences.SplitRows
            };

            setWidths();

            TableCellHelper = new TableCellHelper
            {
                SharedData              = SharedData,
                MainTable               = MainTable,
                CurrentRowInfoData      = CurrentRowInfoData,
                ShowAllGroupsSummaryRow = showAllGroupsSummaryRow
            };
        }
Esempio n. 27
0
        public PdfGrid RenderingReportHeader(Document pdfDoc, PdfWriter pdfWriter, IList <SummaryCellData> summaryData)
        {
            if (_image == null) //cache is empty
            {
                var templatePath = System.IO.Path.Combine(AppPath.ApplicationPath, "data\\PdfHeaderTemplate.pdf");
                _image = PdfImageHelper.GetITextSharpImageFromPdfTemplate(pdfWriter, templatePath);
            }

            var table = new PdfGrid(1);
            var cell  = new PdfPCell(_image, true)
            {
                Border = 0
            };

            table.AddCell(cell);
            return(table);
        }
Esempio n. 28
0
            public PdfGrid RenderingReportHeader(Document pdfDoc, PdfWriter pdfWriter, IList <SummaryCellData> summaryData)
            {
                var table = new PdfGrid(numColumns: 1)
                {
                    WidthPercentage = 100
                };

                table.AddSimpleRow(
                    (cellData, cellProperties) =>
                {
                    cellData.Value                     = naslov;
                    cellProperties.PdfFont             = PdfRptFont;
                    cellProperties.PdfFontStyle        = DocumentFontStyle.Bold;
                    cellProperties.HorizontalAlignment = HorizontalAlignment.Center;
                });
                return(table.AddBorderToTable());
            }
        private async void button2_Click(object sender, RoutedEventArgs e)
        {
            //Create a new PDF document.

            PdfDocument pdfDocument = new PdfDocument();

            //Create the page

            PdfPage pdfPage = pdfDocument.Pages.Add();

            //Create the parent grid

            PdfGrid parentPdfGrid = new PdfGrid();

            //Add the rows
            for (int i = 0; i < CellGrid.RowCount; i++)
            {
                PdfGridRow row1 = parentPdfGrid.Rows.Add();
                row1.Height = 50;
                parentPdfGrid.Columns.Add(CellGrid.ColumnCount);
                for (int j = 0; j < CellGrid.ColumnCount; j++)
                {
                    var         style       = CellGrid.Model[i, j];
                    PdfGridCell pdfGridCell = parentPdfGrid.Rows[i].Cells[j];
                    pdfGridCell.Value = style.CellValue;
                    var brush = (style.Background as SolidColorBrush);
                    //Export with style
                    //if (brush != null)
                    //    pdfGridCell.Style.BackgroundBrush
                }
            }



            //Draw the PdfGrid.

            parentPdfGrid.Draw(pdfPage, PointF.Empty);
            StorageFile   storageFile;
            StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;

            storageFile = await local.CreateFileAsync("Sample.pdf", CreationCollisionOption.ReplaceExisting);

            //Save the document.

            await pdfDocument.SaveAsync(storageFile);
        }
Esempio n. 30
0
        public PdfGrid RenderingReportHeader(Document pdfDoc, PdfWriter pdfWriter, IList <SummaryCellData> summaryData)
        {
            var table = new PdfGrid(numColumns: 1)
            {
                WidthPercentage = 100
            };

            table.AddSimpleRow(
                (cellData, cellProperties) =>
            {
                //electroweb/Images/wwwroot/01.png does not exists & defaultImageFilePath was not found.'

                /*  string url ="http://54.86.105.4/";
                 * cellData.CellTemplate = new ImageFilePathField();
                 *
                 * cellData.Value = TestUtils.GetHtmlPage(url+"Fotos/fb9c27b1-98f7-4388-b13c-664d22cac022.jpg");
                 * cellProperties.HorizontalAlignment = HorizontalAlignment.Center;*/
                cellData.CellTemplate = new ImageFilePathField();
                cellData.Value        = TestUtils.GetImagePath("logo.png");
                cellProperties.HorizontalAlignment = HorizontalAlignment.Center;
            });
            table.AddSimpleRow(
                (cellData, cellProperties) =>
            {
                cellData.Value                     = "Reporte inventario";
                cellProperties.PdfFont             = PdfRptFont;
                cellProperties.PdfFontStyle        = DocumentFontStyle.Bold;
                cellProperties.HorizontalAlignment = HorizontalAlignment.Center;
            });
            table.AddSimpleRow(
                (cellData, cellProperties) =>
            {
                //electroweb/Images/wwwroot/01.png does not exists & defaultImageFilePath was not found.'

                /*  string url ="http://54.86.105.4/";
                 * cellData.CellTemplate = new ImageFilePathField();
                 *
                 * cellData.Value = TestUtils.GetHtmlPage(url+"Fotos/fb9c27b1-98f7-4388-b13c-664d22cac022.jpg");
                 * cellProperties.HorizontalAlignment = HorizontalAlignment.Center;*/
                cellData.CellTemplate = new ImageFilePathField();
                cellData.Value        = TestUtils.GetImagePath("01.png");
                cellProperties.HorizontalAlignment = HorizontalAlignment.Justified;
            });
            return(table.AddBorderToTable());
        }
Esempio n. 31
0
        public IActionResult ShowAllAdmins()
        {
            //Create a new PDF document.
            PdfDocument doc = new PdfDocument();

            //doc.PageSettings.Orientation = PdfPageOrientation.Landscape;
            //doc.PageSettings.Margins.All = 50;
            //PdfBrush solidBrush = new PdfSolidBrush(new PdfColor(126, 151, 173));
            //RectangleF bounds = new RectangleF(176, 0, 390, 130);
            //bounds = new Syncfusion.Drawing.RectangleF(0, bounds.Bottom + 90, graphics.ClientSize.Width, 30);

            //Add a page.
            PdfPage page = doc.Pages.Add();
            //Create a PdfGrid.
            PdfGrid pdfGrid = new PdfGrid();
            //Add values to list
            var AdminList = _context.Admins.ToListAsync();
            //List<Admin> data = AdminList.ToList();

            //Add list to IEnumerable
            IEnumerable <Admin> dataTable = _context.Admins.ToList();

            //Assign data source.
            pdfGrid.DataSource = dataTable;
            //Draw grid to the page of PDF document.
            pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(10, 10));
            //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 = "AdminList.pdf";

            //Creates a FileContentResult object by using the file contents, content type, and file name.
            return(File(stream, contentType, fileName));

            //return View();
        }
Esempio n. 32
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            // Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin, PdfPageRotateAngle.RotateAngle0, PdfPageOrientation.Landscape);

            float y = 10;
            float x1 = page.Canvas.ClientSize.Width;

            //title
            PdfBrush brush1 = PdfBrushes.Black;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold), true);
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString("Vendor List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Vendor List", format1).Height;
            y = y + 5;

            String[] data
                = {
                    "VendorName;Address1;City;State;Country",
                    "Cacor Corporation;161 Southfield Rd;Southfield;OH;U.S.A.",
                    "Underwater;50 N 3rd Street;Indianapolis;IN;U.S.A.",
                    "J.W.  Luscher Mfg.;65 Addams Street;Berkely;MA;U.S.A.",
                    "Scuba Professionals;3105 East Brace;Rancho Dominguez;CA;U.S.A.",
                    "Divers'  Supply Shop;5208 University Dr;Macon;GA;U.S.A.",
                    "Techniques;52 Dolphin Drive;Redwood City;CA;U.S.A.",
                    "Perry Scuba;3443 James Ave;Hapeville;GA;U.S.A.",
                    "Beauchat, Inc.;45900 SW 2nd Ave;Ft Lauderdale;FL;U.S.A.",
                    "Amor Aqua;42 West 29th Street;New York;NY;U.S.A.",
                    "Aqua Research Corp.;P.O. Box 998;Cornish;NH;U.S.A.",
                    "B&K Undersea Photo;116 W 7th Street;New York;NY;U.S.A.",
                    "Diving International Unlimited;1148 David Drive;San Diego;DA;U.S.A.",
                    "Nautical Compressors;65 NW 167 Street;Miami;FL;U.S.A.",
                    "Glen Specialties, Inc.;17663 Campbell Lane;Huntington Beach;CA;U.S.A.",
                    "Dive Time;20 Miramar Ave;Long Beach;CA;U.S.A.",
                    "Undersea Systems, Inc.;18112 Gotham Street;Huntington Beach;CA;U.S.A.",
                    "Felix Diving;310 S Michigan Ave;Chicago;IL;U.S.A.",
                    "Central Valley Skin Divers;160 Jameston Ave;Jamaica;NY;U.S.A.",
                    "Parkway Dive Shop;241 Kelly Street;South Amboy;NJ;U.S.A.",
                    "Marine Camera & Dive;117 South Valley Rd;San Diego;CA;U.S.A.",
                    "Dive Canada;275 W Ninth Ave;Vancouver;British Columbia;Canada",
                    "Dive & Surf;P.O. Box 20210;Indianapolis;IN;U.S.A.",
                    "Fish Research Labs;29 Wilkins Rd Dept. SD;Los Banos;CA;U.S.A."
                };
            PdfGrid grid = new PdfGrid();
            grid.Style.CellPadding = new PdfPaddings(1, 1, 1, 1);

            String[] header = data[0].Split(';');
            grid.Columns.Add(header.Length);
            float width
                = page.Canvas.ClientSize.Width - (grid.Columns.Count + 1);
            grid.Columns[0].Width = width * 0.25f;
            grid.Columns[1].Width = width * 0.25f;
            grid.Columns[2].Width = width * 0.25f;
            grid.Columns[3].Width = width * 0.15f;
            grid.Columns[4].Width = width * 0.10f;
            PdfGridRow headerRow = grid.Headers.Add(1)[0];
            headerRow.Style.Font = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold), true);
            headerRow.Style.BackgroundBrush
                = new PdfLinearGradientBrush(new PointF(0, 0), new PointF(x1, 0), Color.Red, Color.Blue);
            for (int i = 0; i < header.Length; i++)
            {
                headerRow.Cells[i].Value = header[i];
                headerRow.Cells[i].StringFormat
                    = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                if (i == 0)
                {
                    headerRow.Cells[i].Style.BackgroundBrush = PdfBrushes.Gray;
                }
            }

            Random random = new Random();
            Dictionary<String, int> groupByCountry = new Dictionary<String, int>();
            for (int r = 1; r < data.Length; r++)
            {
                PdfGridRow row = grid.Rows.Add();
                row.Style.Font = new PdfTrueTypeFont(new Font("Arial", 10f), true);
                byte[] buffer = new byte[6];
                random.NextBytes(buffer);
                PdfRGBColor color1 = new PdfRGBColor(buffer[0], buffer[1], buffer[2]);
                PdfRGBColor color2 = new PdfRGBColor(buffer[3], buffer[4], buffer[5]);
                row.Style.BackgroundBrush
                    = new PdfLinearGradientBrush(new PointF(0, 0), new PointF(x1, 0), color1, color2);
                String[] rowData = data[r].Split(';');
                for (int c = 0; c < rowData.Length; c++)
                {
                    row.Cells[c].Value = rowData[c];
                    if (c == 0)
                    {
                        row.Cells[c].Style.BackgroundBrush = PdfBrushes.Gray;
                    }
                    if(c < 3)
                    {
                        row.Cells[c].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                    }
                    else
                    {
                        row.Cells[c].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                    }
                    if (c == 4)
                    {
                        if (groupByCountry.ContainsKey(rowData[c]))
                        {
                            groupByCountry[rowData[c]] = groupByCountry[rowData[c]] + 1;
                        }
                        else
                        {
                            groupByCountry[rowData[c]] = 1;
                        }
                    }
                }
            }
            StringBuilder totalAmount = new StringBuilder();
            foreach (KeyValuePair<String, int> country in groupByCountry)
            {
                totalAmount.AppendFormat("{0}:\t{1}", country.Key, country.Value);
                totalAmount.AppendLine();
            }

            PdfGridRow totalAmountRow = grid.Rows.Add();
            totalAmountRow.Style.BackgroundBrush = PdfBrushes.Plum;
            totalAmountRow.Cells[0].Value = "Total Amount";
            totalAmountRow.Cells[0].Style.Font = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold), true);
            totalAmountRow.Cells[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            totalAmountRow.Cells[1].ColumnSpan = 4;
            totalAmountRow.Cells[1].Value = totalAmount.ToString();
            totalAmountRow.Cells[1].Style.Font = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold | FontStyle.Italic), true);
            totalAmountRow.Cells[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);

            //append product list
            PdfGrid productList = new PdfGrid();
            productList.Style.Font = new PdfTrueTypeFont(new Font("Arial", 8f), true);
            using (OleDbConnection conn = new OleDbConnection())
            {
                conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\..\..\..\Data\demo.mdb";
                OleDbCommand command = new OleDbCommand();
                command.CommandText
                    = " select p.Description "
                    + " from vendors v "
                    + "     inner join parts p "
                    + "     on v.VendorNo = p.VendorNo "
                    + " where v.VendorName = 'Cacor Corporation'";
                command.Connection = conn;
                using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(command))
                {
                    DataTable dataTable = new DataTable();
                    dataAdapter.Fill(dataTable);
                    productList.DataSource = dataTable;
                }
            }
            productList.Headers[0].Cells[0].Value = "Cacor Corporation";
            productList.Headers[0].Cells[0].Style.Font = new PdfTrueTypeFont(new Font("Arial", 8f, FontStyle.Bold), true);
            productList.Headers[0].Cells[0].Style.Borders.All = new PdfPen(new PdfTilingBrush(new SizeF(1, 1)), 0);
            grid.Rows[0].Cells[0].Value = productList;
            grid.Rows[0].Cells[0].StringFormat.Alignment = PdfTextAlignment.Left;

            PdfLayoutResult result = grid.Draw(page, new PointF(0, y));
            y = y + result.Bounds.Height + 5;

            PdfBrush brush2 = PdfBrushes.Gray;
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 9f));
            result.Page.Canvas.DrawString(String.Format("* All {0} vendors in the list", grid.Rows.Count - 1),
                font2, brush2, 5, y);

            //Save pdf file.
            doc.SaveToFile("Grid.pdf");
            doc.Close();

            //Launching the Pdf file.
            PDFDocumentViewer("Grid.pdf");
        }
        void PDFButton_Clicked(object sender, EventArgs e)
        {
            PdfDocument document = new PdfDocument();
            document.PageSettings.Orientation = PdfPageOrientation.Portrait;
            document.PageSettings.Margins.All = 50;
            PdfPage page = document.Pages.Add();
            PdfGraphics g = page.Graphics;
            PdfTextElement element = new PdfTextElement(@"Syncfusion Software 
2501 Aerial Center Parkway 
Suite 200 Morrisville, NC 27560 USA 
Tel +1 888.936.8638 Fax +1 919.573.0306");
            element.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14);
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            PdfLayoutResult result = element.Draw(page, new RectangleF(0, 0, page.Graphics.ClientSize.Width / 2, 200));
            Stream imgStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("XamarinIOInvoice.SyncfusionLogo.jpg");
            PdfImage img = PdfImage.FromStream(imgStream);
            page.Graphics.DrawImage(img, new RectangleF(g.ClientSize.Width - 200, result.Bounds.Y, 190, 45));
            PdfFont subHeadingFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 15);
            g.DrawRectangle(new PdfSolidBrush(new PdfColor(34, 83, 142)), new RectangleF(0, result.Bounds.Bottom + 40, g.ClientSize.Width, 30));
            element = new PdfTextElement("INVOICE: " + billInfo.InvoiceNumber.ToString(), subHeadingFont);
            element.Brush = PdfBrushes.White;
            result = element.Draw(page, new PointF(10, result.Bounds.Bottom + 48));
            string currentDate = "DATE: " + billInfo.Date.ToString();
            SizeF textSize = subHeadingFont.MeasureString(currentDate);
            g.DrawString(currentDate, subHeadingFont, element.Brush, new PointF(g.ClientSize.Width - textSize.Width - 10, result.Bounds.Y));

            element = new PdfTextElement("BILL TO ", new PdfStandardFont(PdfFontFamily.TimesRoman, 14));
            element.Brush = new PdfSolidBrush(new PdfColor(34, 83, 142));
            result = element.Draw(page, new PointF(10, result.Bounds.Bottom + 25));

            g.DrawLine(new PdfPen(new PdfColor(34, 83, 142), 0.70f), new PointF(0, result.Bounds.Bottom + 3), new PointF(g.ClientSize.Width, result.Bounds.Bottom + 3));

            element = new PdfTextElement(billInfo.Name, new PdfStandardFont(PdfFontFamily.TimesRoman, 14));
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            result = element.Draw(page, new RectangleF(10, result.Bounds.Bottom + 5, g.ClientSize.Width / 2, 100));

            element = new PdfTextElement(billInfo.Address, new PdfStandardFont(PdfFontFamily.TimesRoman, 14));
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            result = element.Draw(page, new RectangleF(10, result.Bounds.Bottom + 3, g.ClientSize.Width / 2, 100));

            PdfGrid grid = new PdfGrid();
            grid.DataSource = this.ListSource;
            PdfGridCellStyle cellStyle = new PdfGridCellStyle();
            cellStyle.Borders.All = PdfPens.White;
            PdfGridRow header = grid.Headers[0];

            PdfGridCellStyle headerStyle = new PdfGridCellStyle();
            headerStyle.Borders.All = new PdfPen(new PdfColor(34, 83, 142));
            headerStyle.BackgroundBrush = new PdfSolidBrush(new PdfColor(34, 83, 142));
            headerStyle.TextBrush = PdfBrushes.White;
            headerStyle.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 15f, PdfFontStyle.Regular);

            for (int i = 0; i < header.Cells.Count; i++)
            {
                if (i == 0)
                    header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                else
                    header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
            }
            header.Cells[0].Value = "ITEM";
            header.Cells[1].Value = "QUANTITY";
            header.Cells[2].Value = "RATE";
            header.Cells[3].Value = "TAXES (%)";
            header.Cells[4].Value = "AMOUNT";
            header.ApplyStyle(headerStyle);
            cellStyle.Borders.Bottom = new PdfPen(new PdfColor(217, 217, 217), 0.70f);
            cellStyle.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f);
            cellStyle.TextBrush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            foreach (PdfGridRow row in grid.Rows)
            {
                row.ApplyStyle(cellStyle);
                for (int i = 0; i < row.Cells.Count; i++)
                {
                    PdfGridCell cell = row.Cells[i];
                    if (i == 0)
                        cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                    else
                        cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);

                    if (i > 1 && i != 3)
                    {
                        //float val = float.MinValue;
                        //float.TryParse(cell.Value.ToString(), out val);
                        if (cell.Value.ToString().Contains("$"))
                        {
                            cell.Value = cell.Value.ToString();
                        }
                        else
                        {
                            cell.Value = "$" + cell.Value.ToString();
                        }
                    }
                }
            }

            PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat();
            layoutFormat.Layout = PdfLayoutType.Paginate;

            PdfGridLayoutResult gridResult = grid.Draw(page, new RectangleF(new PointF(0, result.Bounds.Bottom + 40), new SizeF(g.ClientSize.Width, g.ClientSize.Height - 100)), layoutFormat);
            float pos = 0.0f;
            for (int i = 0; i < grid.Columns.Count - 1; i++)
                pos += grid.Columns[i].Width;

            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14f,PdfFontStyle.Bold);

            gridResult.Page.Graphics.DrawString("TOTAL DUE", font, new PdfSolidBrush(new PdfColor(34, 83, 142)), new RectangleF(new PointF(pos, gridResult.Bounds.Bottom + 10), new SizeF(grid.Columns[3].Width - pos, 20)), new PdfStringFormat(PdfTextAlignment.Right));
            gridResult.Page.Graphics.DrawString("Thank you for your business!", new PdfStandardFont(PdfFontFamily.TimesRoman, 14), new PdfSolidBrush(new PdfColor(0, 0, 0)), new PointF(pos -210, gridResult.Bounds.Bottom + 60));
            pos += grid.Columns[4].Width;
            gridResult.Page.Graphics.DrawString("$" + GetNetAmount().ToString(), font, new PdfSolidBrush(new PdfColor(0, 0, 0)), new RectangleF(new Syncfusion.Drawing.PointF(pos, gridResult.Bounds.Bottom + 10), new Syncfusion.Drawing.SizeF(grid.Columns[4].Width - pos, 20)), new PdfStringFormat(PdfTextAlignment.Right));

            MemoryStream data = new MemoryStream();

            document.Save(data);

            document.Close();

            DependencyService.Get<ISave>().SaveTextAsync("Invoice.pdf", "application/pdf", data);

        }
        private void buttonRun_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog saveFiledialog = new SaveFileDialog();
            saveFiledialog.Filter = "PDF Document (*.pdf)|*.pdf";
            bool? result = saveFiledialog.ShowDialog();
            if (!result.HasValue || !result.Value)
            {
                return;
            }

            //create a pdf document
            PdfDocument document = new PdfDocument();

            //margin
            PdfMargins margin = new PdfMargins();
            margin.Top = ConvertUnits(1.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            //create one page
            PdfPageBase page
                = document.Pages.Add(PdfPageSize.A4, margin, PdfPageRotateAngle.RotateAngle0,
                PdfPageOrientation.Landscape);
            float y = 0;

            //title
            PdfBrush brush1 = PdfBrushes.Black;
            PdfTrueTypeFont font1
                = new PdfInternalFont(new Font("Arial", 16f, System.Drawing.FontStyle.Bold), true);
            PdfStringFormat format1
                = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString("Vendor List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Vendor List", format1).Height;
            y = y + 5;

            PdfGrid grid = new PdfGrid();
            grid.Style.CellPadding = new PdfPaddings(1, 1, 1, 1);
            grid.Columns.Add(this.dataGridVendorList.Columns.Count);

            float width
                = page.Canvas.ClientSize.Width - (grid.Columns.Count + 1);
            grid.Columns[0].Width = width * 0.25f;
            grid.Columns[1].Width = width * 0.25f;
            grid.Columns[2].Width = width * 0.25f;
            grid.Columns[3].Width = width * 0.15f;
            grid.Columns[4].Width = width * 0.10f;

            //header of grid
            PdfGridRow headerRow = grid.Headers.Add(1)[0];
            headerRow.Style.Font
                = new PdfInternalFont(new Font("Arial", 11f, System.Drawing.FontStyle.Bold), true);
            String[] header = { "Vendor Name", "Address", "City", "State", "Country" };
            for (int i = 0; i < header.Length; i++)
            {
                headerRow.Cells[i].Value = header[i];
                headerRow.Cells[i].StringFormat
                    = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);

            }
            headerRow.Style.BackgroundBrush = PdfBrushes.SeaGreen;

            //datarow of grid
            int rowIndex = 1;
            foreach (Vendor vendor in this.dataSource)
            {
                PdfGridRow row = grid.Rows.Add();
                row.Style.Font = new PdfInternalFont(new Font("Arial", 10f), true);
                row.Cells[0].Value = vendor.VendorName;
                row.Cells[1].Value = vendor.Address;
                row.Cells[2].Value = vendor.City;
                row.Cells[3].Value = vendor.State;
                row.Cells[4].Value = vendor.Country;

                row.Cells[0].Style.BackgroundBrush = PdfBrushes.LightGray;
                row.Cells[0].StringFormat = row.Cells[1].StringFormat = row.Cells[2].StringFormat
                    = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                row.Cells[3].StringFormat = row.Cells[4].StringFormat
                    = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                if (rowIndex % 2 == 0)
                {
                    row.Style.BackgroundBrush = PdfBrushes.YellowGreen;
                }
                else
                {
                    row.Style.BackgroundBrush = PdfBrushes.Bisque;
                }
                rowIndex++;
            }

            StringBuilder totalAmount = new StringBuilder();

            var groupByCountry
                = this.dataSource.GroupBy(v => v.Country)
                    .Select(g => new { Name = g.Key, Count = g.Count() });

            foreach (var item in groupByCountry)
            {
                totalAmount.AppendFormat("{0}:\t{1}", item.Name, item.Count);
                totalAmount.AppendLine();
            }

            PdfGridRow totalAmountRow = grid.Rows.Add();
            totalAmountRow.Style.BackgroundBrush = PdfBrushes.Plum;
            totalAmountRow.Cells[0].Value = "Total Amount";
            totalAmountRow.Cells[0].Style.Font
                = new PdfInternalFont(new Font("Arial", 10f, System.Drawing.FontStyle.Bold), true);
            totalAmountRow.Cells[0].StringFormat
                = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            totalAmountRow.Cells[1].ColumnSpan = 4;
            totalAmountRow.Cells[1].Value = totalAmount.ToString();
            totalAmountRow.Cells[1].Style.Font
                = new PdfInternalFont(new Font("Arial", 10f, System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic), true);
            totalAmountRow.Cells[1].StringFormat
                = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);

            PdfLayoutResult resultl = grid.Draw(page, new PointF(0, y));
            y = y + resultl.Bounds.Height + 5;

            PdfBrush brush2 = PdfBrushes.Gray;
            PdfTrueTypeFont font2 = new PdfInternalFont(new Font("Arial", 9f));
            resultl.Page.Canvas.DrawString(String.Format("* All {0} vendors in the list", grid.Rows.Count - 1),
                font2, brush2, 5, y);

            //Save pdf file.
            using (Stream stream = saveFiledialog.OpenFile())
            {
                document.SaveToStream(stream);
            }
            document.Close();
        }
Esempio n. 35
0
        private PdfLayoutResult DrawVendor(PdfPageBase page, DataTable vendors, int index, String title, float y)
        {
            //draw title
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold));
            DataRow row = vendors.Rows[index];
            page.Canvas.DrawString(title, font1, PdfBrushes.Black, 0, y);
            y = y + font1.MeasureString(title).Height + 1;

            //draw table
            Object[][] data = new Object[vendors.Columns.Count][];
            for (int i = 0; i < vendors.Columns.Count; i++)
            {
                data[i] = new Object[2];
                data[i][0] = vendors.Columns[i].ColumnName;
                data[i][1] = vendors.Rows[index].ItemArray[i];
            }

            PdfGrid grid = new PdfGrid();
            grid.Style.CellPadding = new PdfPaddings(2, 2, 1, 1);
            grid.DataSource = data;

            float width
                = page.Canvas.ClientSize.Width
                    - (grid.Columns.Count + 1) * 0.75f;
            grid.Columns[0].Width = width * 0.20f;
            grid.Columns[1].Width = width * 0.80f;

            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold));
            PdfTrueTypeFont font3 = new PdfTrueTypeFont(new Font("Arial", 10f));
            for (int i = 0; i < grid.Rows.Count; i++)
            {
                grid.Rows[i].Style.Font = font2;
                grid.Rows[i].Cells[0].Style.BackgroundBrush = PdfBrushes.CadetBlue;
                grid.Rows[i].Cells[1].Style.BackgroundBrush = PdfBrushes.SkyBlue;
            }

            PdfGridLayoutFormat layout = new PdfGridLayoutFormat();
            layout.Break = PdfLayoutBreakType.FitPage;
            layout.Layout = PdfLayoutType.Paginate;

            return grid.Draw(page, new PointF(0, y), layout);
        }