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);
          

        }
Exemple #2
0
        public PrintBill(ObservableCollection <printBillData> finalBillOrderPrint, string name, string total)
        {
            PdfDocument doc      = new PdfDocument();
            PdfPage     page     = doc.Pages.Add();
            PdfGraphics graphics = page.Graphics;
            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);

            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:   " + total + " EURO", font2, PdfBrushes.Black, new PointF(400, page.Graphics.ClientSize.Height - 80));
            PdfGrid grid = new PdfGrid();

            grid.DataSource = finalBillOrderPrint;
            PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat();

            layoutFormat.Layout = PdfLayoutType.OnePage;
            PdfGridLayoutResult gridResult = grid.Draw(page, new RectangleF(new PointF(0, 75), new SizeF(page.Graphics.ClientSize.Width, page.Graphics.ClientSize.Height - 100)), layoutFormat);

            doc.Save(name + ".pdf");
            System.Diagnostics.Process.Start(name + ".pdf");
            doc.Close(true);
        }
Exemple #3
0
        private void button_ExportPdf_Click(object sender, EventArgs e)
        {
            (string title, string _) = GenerateTitle($"Bel Report", "x");
            saveFileDialog1.Filter   = "Pdf files|*.pdf|All files|*.*";

            string filePath = ShowSaveDialog("Export Pdf");

            if (string.IsNullOrEmpty(filePath))
            {
                return;
            }

            PdfExportingOptions options = new PdfExportingOptions();

            //options.AutoColumnWidth = true;
            options.AutoRowHeight  = true;
            options.ExcludeColumns = new List <string> {
                nameof(ReportModel.Emphasis),
                nameof(ReportModel.VolumeId)
            };
            foreach (var col in sfDataGrid1.Columns.Where(x => !x.Visible))
            {
                options.ExcludeColumns.Add(col.HeaderText);
            }
            options.RepeatHeaders          = true;
            options.FitAllColumnsInOnePage = true;
            options.AutoColumnWidth        = true;
            options.ExportGroups           = true;
            options.ExportDetailsView      = true;

            var document = new PdfDocument();

            document.PageSettings.Orientation = PdfPageOrientation.Landscape;
            var page    = document.Pages.Add();
            var PDFGrid = sfDataGrid1.ExportToPdfGrid(sfDataGrid1.View, options);
            var format  = new PdfGridLayoutFormat()
            {
                Layout = PdfLayoutType.Paginate,
                Break  = PdfLayoutBreakType.FitPage
            };

            PDFGrid.Draw(page, new PointF(), format);

            //Syncfusion.Pdf.PdfDocument document = sfDataGrid1.ExportToPdf(options);
            //document.PageSettings.Orientation = Syncfusion.Pdf.PdfPageOrientation.Landscape;
            document.Save(filePath);

            //GenerateDataForExport();
            //var exporter = m_ExporterProvider.Provide("Pdf");
            //string exportData = exporter.Export(title, ExportColNames, ExportData);
            //File.WriteAllText(filePath, exportData);
        }
Exemple #4
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);
        }
Exemple #5
0
        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            PdfExportingOptions options = new PdfExportingOptions();
            var document = new PdfDocument();

            document.PageSettings.Orientation = PdfPageOrientation.Landscape;
            var page = document.Pages.Add();

            options.AutoColumnWidth        = true;
            options.AutoRowHeight          = true;
            options.RepeatHeaders          = true;
            options.ExportGroups           = true;
            options.ExportStackedHeaders   = true;
            options.FitAllColumnsInOnePage = true;

            foreach (var c in SelectedGrid.Columns)
            {
                if (c.Width == 0)
                {
                    options.ExcludeColumns.Add(c.MappingName);
                }
            }

            var PDFGrid = SelectedGrid.ExportToPdfGrid(SelectedGrid.View, options);

            var format = new PdfGridLayoutFormat()
            {
                Layout = PdfLayoutType.Paginate,
                Break  = PdfLayoutBreakType.FitPage
            };

            PDFGrid.Draw(page, new PointF(), format);

            SaveFileDialog sfd = new SaveFileDialog
            {
                Filter = "Pdf Image|*.pdf|Ficheiro pdf|*.pdf",
                Title  = "Guardar ficheiro pdf"
            };

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                document.Save(sfd.FileName);
                Process.Start(sfd.FileName);
            }
            Cursor.Current = Cursors.Default;
        }
        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));
        }
Exemple #7
0
        private async void GeneratePDF_Click(object sender, RoutedEventArgs e)
        {
            #region Field Definitions
            IEnumerable <Adventure> products = Provider.GetProducts();
            Stream          fontStream       = typeof(MainPage).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Pdf.Assets.verdana.ttf");
            PdfStandardFont font             = new PdfStandardFont(PdfFontFamily.TimesRoman, 8f);
            #endregion

            styleName = this.gridBuiltinstyleComboBox.SelectedItem.ToString();

            PdfDocument document = new PdfDocument();

            PdfPage page = document.Pages.Add();

            #region PdfGrid
            grid            = new PdfGrid();
            grid.DataSource = products;

            PdfGridBuiltinStyle style = ConvertToPdfGridBuiltinStyle(styleName);

            PdfGridBuiltinStyleSettings setting = new PdfGridBuiltinStyleSettings();
            setting.ApplyStyleForHeaderRow  = true;
            setting.ApplyStyleForBandedRows = true;

            grid.Style.CellPadding.All = 2;

            grid.ApplyBuiltinStyle(style, setting);

            PdfGridLayoutFormat gridLayoutFormat = new PdfGridLayoutFormat();
            gridLayoutFormat.Layout = PdfLayoutType.Paginate;
            gridLayoutFormat.Break  = PdfLayoutBreakType.FitElement;

            grid.Draw(page, PointF.Empty, gridLayoutFormat);

            #endregion

            MemoryStream stream = new MemoryStream();
            await document.SaveAsync(stream);

            document.Close(true);
            SaveFile(stream, "GridBuiltinStyle.pdf");
        }
Exemple #8
0
        /// <summary>
        /// Creates PDF
        /// </summary>
        public async void CreatePDF(IList <InvoiceItem> dataSource, BillingInformation billInfo, double totalDue)
        {
            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, 12);
            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(MainPage).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.DocIO.DocIO.Invoice.Assets.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(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("d");
            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, 12));
            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, 11));
            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, 11));
            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));
            string[] headers = new string[] { "Item", "Quantity", "Rate", "Taxes", "Amount" };
            PdfGrid  grid    = new PdfGrid();

            grid.Columns.Add(headers.Length);
            //Adding headers in to the grid
            grid.Headers.Add(1);
            PdfGridRow headerRow = grid.Headers[0];
            int        count     = 0;

            foreach (string columnName in headers)
            {
                headerRow.Cells[count].Value = columnName;
                count++;
            }
            //Adding rows into the grid
            foreach (var item in dataSource)
            {
                PdfGridRow row = grid.Rows.Add();
                row.Cells[0].Value = item.ItemName;
                row.Cells[1].Value = item.Quantity.ToString();
                row.Cells[2].Value = "$" + item.Rate.ToString("#,###.00", CultureInfo.InvariantCulture);
                row.Cells[3].Value = "$" + item.Taxes.ToString("#,###.00", CultureInfo.InvariantCulture);
                row.Cells[4].Value = "$" + item.TotalAmount.ToString("#,###.00", CultureInfo.InvariantCulture);
            }

            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, 12f, 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);
            grid.Columns[0].Width    = 180;
            cellStyle.Borders.Bottom = new PdfPen(new PdfColor(34, 83, 142), 0.70f);
            cellStyle.Font           = new PdfStandardFont(PdfFontFamily.TimesRoman, 11f);
            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)
                    {
                        if (cell.Value.ToString().Contains("$"))
                        {
                            cell.Value = cell.Value.ToString();
                        }
                        else
                        {
                            if (cell.Value is double)
                            {
                                cell.Value = "$" + ((double)cell.Value).ToString("#,###.00", CultureInfo.InvariantCulture);
                            }
                            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.TimesRoman, 12f, 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, 12), new PdfSolidBrush(new PdfColor(0, 0, 0)), new PointF(pos - 210, gridResult.Bounds.Bottom + 60));
            pos += grid.Columns[4].Width;
            gridResult.Page.Graphics.DrawString("$" + totalDue.ToString("#,###.00", CultureInfo.InvariantCulture), font, new PdfSolidBrush(new PdfColor(0, 0, 0)), new RectangleF(pos, gridResult.Bounds.Bottom + 10, grid.Columns[4].Width - pos, 20), new PdfStringFormat(PdfTextAlignment.Right));
            StorageFile stFile = null;

            if (!(Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons")))
            {
                FileSavePicker savePicker = new FileSavePicker();
                savePicker.DefaultFileExtension = ".pdf";
                savePicker.SuggestedFileName    = "Invoice";
                savePicker.FileTypeChoices.Add("Adobe PDF Document", new List <string>()
                {
                    ".pdf"
                });
                stFile = await savePicker.PickSaveFileAsync();
            }
            else
            {
                StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
                stFile = await local.CreateFileAsync("Invoice.pdf", CreationCollisionOption.ReplaceExisting);
            }

            if (stFile != null)
            {
                Stream stream = await stFile.OpenStreamForWriteAsync();

                await document.SaveAsync(stream);

                stream.Flush();
                stream.Dispose();
                document.Close(true);

                MessageDialog msgDialog = new MessageDialog("Do you want to view the Document?", "File has been created successfully.");

                UICommand yesCmd = new UICommand("Yes");
                msgDialog.Commands.Add(yesCmd);
                UICommand noCmd = new UICommand("No");
                msgDialog.Commands.Add(noCmd);
                IUICommand cmd = await msgDialog.ShowAsync();

                if (cmd == yesCmd)
                {
                    // Launch the saved file
                    bool success = await Windows.System.Launcher.LaunchFileAsync(stFile);
                }
            }
        }
Exemple #9
0
        /// <summary>
        /// Creates PDF
        /// </summary>
        public void CreatePDF(IList <InvoiceItem> dataSource, BillingInformation billInfo, double totalDue)
        {
            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, 12);
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            PdfLayoutResult result    = element.Draw(page, new RectangleF(0, 0, page.Graphics.ClientSize.Width / 2, 200));
            Assembly        assembly  = typeof(MainPage).Assembly;
            Stream          imgStream = assembly.GetManifestResourceStream("Invoice.Assets.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(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("d");
            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, 12));
            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, 11));
            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, 11));
            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 = ConvertToDataTable(dataSource);
            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, 12f, 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);
            grid.Columns[0].Width    = 180;
            cellStyle.Borders.Bottom = new PdfPen(new PdfColor(34, 83, 142), 0.70f);
            cellStyle.Font           = new PdfStandardFont(PdfFontFamily.TimesRoman, 11f);
            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)
                    {
                        if (cell.Value.ToString().Contains("$"))
                        {
                            cell.Value = cell.Value.ToString();
                        }
                        else
                        {
                            if (cell.Value is double)
                            {
                                cell.Value = "$" + ((double)cell.Value).ToString("#,###.00", CultureInfo.InvariantCulture);
                            }
                            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.TimesRoman, 12f, 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, 12), new PdfSolidBrush(new PdfColor(0, 0, 0)), new PointF(pos - 210, gridResult.Bounds.Bottom + 60));
            pos += grid.Columns[4].Width;
            gridResult.Page.Graphics.DrawString("$" + totalDue.ToString("#,###.00", CultureInfo.InvariantCulture), font, new PdfSolidBrush(new PdfColor(0, 0, 0)), new RectangleF(pos, gridResult.Bounds.Bottom + 10, grid.Columns[4].Width - pos, 20), new PdfStringFormat(PdfTextAlignment.Right));

            document.Save("Invoice.pdf");
            //Message box confirmation to view the created PDF document.
            if (MessageBox.Show("Do you want to view the PDF file?", "PDF File Created",
                                MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
            {
                //Launching the PDF file using the default Application.[Acrobat Reader]
                System.Diagnostics.Process.Start("Invoice.pdf");
                //this.Close();
            }
            //else
            // Exit
            //this.Close();

            document.Close(true);
        }
        private ActionResult ExportPdfLINEPayRemittance(List <LINEPayRemittance> LINEPayRemittance, DateTime RemittanceDate)
        {
            // Load the PDF Template
            Stream pdfStream = System.IO.File.OpenRead(_hostingEnvironment.WebRootPath + @"\assets\templates\LINEPayRemittance.pdf");

            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, (float)6.5);
            PdfFont fontRemittanceDate = new PdfStandardFont(PdfFontFamily.Helvetica, (float)8);

            // Load a PDF document.
            PdfLoadedDocument loadedDocument = new PdfLoadedDocument(pdfStream);

            //Create a new PDF document.
            PdfDocument pdfDocument = new PdfDocument();

            pdfDocument.ImportPage(loadedDocument, 0);

            PdfPage pdfPage = pdfDocument.Pages[0];

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

            //Add three columns.
            pdfGrid.Columns.Add(9);

            //Add header.
            pdfGrid.Headers.Add(1);

            PdfGridRow pdfGridHeader = pdfGrid.Headers[0];

            string[] headerStr = { "ERP ID", "Branch ID", "Report Date", "Branch Name", "TUC DCSP", "TUC", "TUP", "TUD", "Captured" };

            int[] columnsWidth = { 40, 40, 50, 0, 50, 50, 50, 50, 30 };
            pdfGridHeader.Style.Font            = font;
            pdfGridHeader.Style.BackgroundBrush = PdfBrushes.LightGray;
            pdfGridHeader.Height = (float)11;

            for (int i = 0; i < headerStr.Count(); i++)
            {
                if (!i.Equals(3))
                {
                    pdfGrid.Columns[i].Width = columnsWidth[i];
                }

                pdfGridHeader.Cells[i].StringFormat.Alignment = PdfTextAlignment.Center;

                pdfGridHeader.Cells[i].Value                      = headerStr[i];
                pdfGridHeader.Cells[i].Style.CellPadding          = new PdfPaddings((float)1.5, (float)1.5, (float)1.5, (float)1.5);
                pdfGridHeader.Cells[i].Style.Borders.Left.Width   = (float)0.5;
                pdfGridHeader.Cells[i].Style.Borders.Right.Width  = (float)0.5;
                pdfGridHeader.Cells[i].Style.Borders.Top.Width    = (float)0.5;
                pdfGridHeader.Cells[i].Style.Borders.Bottom.Width = (float)0.5;
            }

            pdfGridHeader.Cells[4].StringFormat.Alignment = PdfTextAlignment.Right;
            pdfGridHeader.Cells[5].StringFormat.Alignment = PdfTextAlignment.Right;
            pdfGridHeader.Cells[6].StringFormat.Alignment = PdfTextAlignment.Right;

            PdfGridRow pdfGridRow;

            LINEPayRemittance.ForEach(line => {
                //Add rows.
                pdfGridRow            = pdfGrid.Rows.Add();
                pdfGridRow.Style.Font = font;

                pdfGridRow.Height = (float)11;

                pdfGridRow.Cells[0].Value = line.ERP_ID;
                pdfGridRow.Cells[1].Value = line.BranchID;
                pdfGridRow.Cells[2].Value = line.ReportDate.ToString("dd/MM/yyyy", enUS);
                pdfGridRow.Cells[3].Value = line.BranchName;
                pdfGridRow.Cells[4].Value = line.branch_type.Equals("DCSP-SHOP") ? line.TUC.ToString("#,0.00"):"-";
                pdfGridRow.Cells[5].Value = !line.branch_type.Equals("DCSP-SHOP") ? line.TUC.ToString("#,0.00") : "-";
                pdfGridRow.Cells[6].Value = line.TUP.ToString("#,0.00");
                pdfGridRow.Cells[7].Value = line.TUD.ToString("#,0.00");
                pdfGridRow.Cells[8].Value = line.TUDVerifyDate == null ? line.Captured : "Yes";

                pdfGridRow.Cells[0].StringFormat.Alignment = PdfTextAlignment.Center;
                pdfGridRow.Cells[2].StringFormat.Alignment = PdfTextAlignment.Center;
                pdfGridRow.Cells[4].StringFormat.Alignment = PdfTextAlignment.Right;
                pdfGridRow.Cells[5].StringFormat.Alignment = PdfTextAlignment.Right;
                pdfGridRow.Cells[6].StringFormat.Alignment = PdfTextAlignment.Right;
                pdfGridRow.Cells[7].StringFormat.Alignment = PdfTextAlignment.Right;
                pdfGridRow.Cells[8].StringFormat.Alignment = PdfTextAlignment.Center;

                for (int i = 0; i < pdfGridRow.Cells.Count; i++)
                {
                    pdfGridRow.Cells[i].Style.Borders.Left.Width   = (float)0.5;
                    pdfGridRow.Cells[i].Style.Borders.Right.Width  = (float)0.5;
                    pdfGridRow.Cells[i].Style.Borders.Top.Width    = (float)0.5;
                    pdfGridRow.Cells[i].Style.Borders.Bottom.Width = (float)0.5;

                    pdfGridRow.Cells[i].Style.CellPadding = new PdfPaddings((float)1.5, (float)1.5, (float)1.5, (float)1.5);
                }
            });

            //Add rows Sum
            pdfGridRow = pdfGrid.Rows.Add();
            pdfGridRow.Cells[4].Value             = LINEPayRemittance.Where(line => line.branch_type.Equals("DCSP-SHOP")).Sum(line => line.TUC).ToString("#,0.00");
            pdfGridRow.Cells[5].Value             = LINEPayRemittance.Where(line => !line.branch_type.Equals("DCSP-SHOP")).Sum(line => line.TUC).ToString("#,0.00");
            pdfGridRow.Cells[6].Value             = LINEPayRemittance.Sum(line => line.TUP).ToString("#,0.00");
            pdfGridRow.Cells[7].Value             = LINEPayRemittance.Sum(line => line.TUD).ToString("#,0.00");
            pdfGridRow.Cells[4].Style.CellPadding = new PdfPaddings((float)1.5, (float)1.5, (float)1.5, (float)1.5);
            pdfGridRow.Cells[5].Style.CellPadding = new PdfPaddings((float)1.5, (float)1.5, (float)1.5, (float)1.5);
            pdfGridRow.Cells[6].Style.CellPadding = new PdfPaddings((float)1.5, (float)1.5, (float)1.5, (float)1.5);
            pdfGridRow.Cells[7].Style.CellPadding = new PdfPaddings((float)1.5, (float)1.5, (float)1.5, (float)1.5);

            for (int i = 0; i < pdfGridRow.Cells.Count; i++)
            {
                pdfGridRow.Cells[i].Style.Borders.Left.Color   = PdfColor.Empty;
                pdfGridRow.Cells[i].Style.Borders.Right.Color  = PdfColor.Empty;
                pdfGridRow.Cells[i].Style.Borders.Bottom.Color = PdfColor.Empty;
                pdfGridRow.Cells[i].Style.Borders.Left.Width   = (float)0.5;
                pdfGridRow.Cells[i].Style.Borders.Right.Width  = (float)0.5;
                pdfGridRow.Cells[i].Style.Borders.Top.Width    = (float)0.5;
                pdfGridRow.Cells[i].Style.Borders.Bottom.Width = (float)0.5;
            }

            pdfGridRow.Cells[4].StringFormat.Alignment = PdfTextAlignment.Right;
            pdfGridRow.Cells[5].StringFormat.Alignment = PdfTextAlignment.Right;
            pdfGridRow.Cells[6].StringFormat.Alignment = PdfTextAlignment.Right;
            pdfGridRow.Cells[7].StringFormat.Alignment = PdfTextAlignment.Right;

            pdfGridRow.Height     = (float)11;
            pdfGridRow.Style.Font = font;

            for (int i = 4; i <= 7; i++)
            {
                pdfGridRow.Cells[i].Style.Borders.Top.Color    = new PdfColor(Color.Black);
                pdfGridRow.Cells[i].Style.Borders.Left.Color   = new PdfColor(Color.Black);
                pdfGridRow.Cells[i].Style.Borders.Right.Color  = new PdfColor(Color.Black);
                pdfGridRow.Cells[i].Style.Borders.Bottom.Color = new PdfColor(Color.Black);
            }

            //Add rows Total
            pdfGridRow = pdfGrid.Rows.Add();
            pdfGridRow.Cells[3].Value = "Total";
            pdfGridRow.Cells[4].Value = (
                LINEPayRemittance.Sum(line => line.TUC)
                +
                LINEPayRemittance.Sum(line => line.TUP)
                +
                LINEPayRemittance.Sum(line => line.TUD)).ToString("#,0.00");
            pdfGridRow.Cells[4].ColumnSpan        = 4;
            pdfGridRow.Cells[3].Style.CellPadding = new PdfPaddings((float)1.5, (float)1.5, (float)1.5, (float)1.5);
            pdfGridRow.Cells[4].Style.CellPadding = new PdfPaddings((float)1.5, (float)1.5, (float)1.5, (float)1.5);

            pdfGridRow.Cells[3].StringFormat.Alignment = PdfTextAlignment.Right;
            pdfGridRow.Cells[4].StringFormat.Alignment = PdfTextAlignment.Center;

            pdfGridRow.Height     = (float)11;
            pdfGridRow.Style.Font = font;

            for (int i = 0; i < pdfGridRow.Cells.Count; i++)
            {
                pdfGridRow.Cells[i].Style.Borders.Top.Color    = PdfColor.Empty;
                pdfGridRow.Cells[i].Style.Borders.Left.Color   = PdfColor.Empty;
                pdfGridRow.Cells[i].Style.Borders.Right.Color  = PdfColor.Empty;
                pdfGridRow.Cells[i].Style.Borders.Bottom.Color = PdfColor.Empty;
            }

            pdfGridRow.Cells[4].Style.Borders.Top.Color    = new PdfColor(Color.Black);
            pdfGridRow.Cells[4].Style.Borders.Left.Color   = new PdfColor(Color.Black);
            pdfGridRow.Cells[4].Style.Borders.Right.Color  = new PdfColor(Color.Black);
            pdfGridRow.Cells[4].Style.Borders.Bottom.Color = new PdfColor(Color.Black);
            pdfGridRow.Cells[4].Style.Borders.Left.Width   = (float)0.5;
            pdfGridRow.Cells[4].Style.Borders.Right.Width  = (float)0.5;
            pdfGridRow.Cells[4].Style.Borders.Top.Width    = (float)0.5;
            pdfGridRow.Cells[4].Style.Borders.Bottom.Width = (float)0.5;


            //Create PDF graphics for the page.
            PdfGraphics graphics = pdfPage.Graphics;

            //Draw the text.
            graphics.DrawString(RemittanceDate.ToString("dd MMM yyyy", enUS), fontRemittanceDate, PdfBrushes.Black, new PointF((float)458, (float)57.5));

            //Draw the PdfGrid.
            //pdfGrid.Draw(pdfPage, (float)20, (float)90, (float)555.28,);
            //pdfGrid.Draw(pdfPage, new RectangleF(20, 90, pdfDocument.Pages[0].GetClientSize().Width - 40, pdfDocument.Pages[0].GetClientSize().Height - 140));

            //Set properties to paginate the table.
            PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat();

            layoutFormat.Break          = PdfLayoutBreakType.FitElement;
            layoutFormat.Layout         = PdfLayoutType.Paginate;
            layoutFormat.PaginateBounds = new RectangleF(20, 20, pdfDocument.Pages[0].GetClientSize().Width - 40, pdfDocument.Pages[0].GetClientSize().Height - 50);

            //Draw PdfLightTable.
            pdfGrid.Draw(pdfPage, 20f, 90f, (pdfDocument.Pages[0].GetClientSize().Width - 40), layoutFormat);

            //Create a Page template that can be used as footer.
            RectangleF             bounds = new RectangleF(0, 0, pdfDocument.Pages[0].GetClientSize().Width, 50);
            PdfPageTemplateElement footer = new PdfPageTemplateElement(bounds);
            PdfBrush brush = new PdfSolidBrush(Color.Black);

            //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, "Page {0} of {1}", pageNumber, count);

            string            printDate          = DateTime.Now.ToString("dd MMM yyyy HH:mm:ss", enUS);
            PdfCompositeField compositePrintDate = new PdfCompositeField(font, brush, string.Format("Printed Date : {0}", printDate));

            compositeField.Bounds = footer.Bounds;

            //Draw the composite field in footer.
            compositeField.Draw(footer.Graphics, new PointF(pdfDocument.Pages[0].GetClientSize().Width - 50, 30));
            compositePrintDate.Draw(footer.Graphics, new PointF(20, 30));

            //Add the footer template at the bottom.
            pdfDocument.Template.Bottom = footer;



            MemoryStream ms = new MemoryStream();

            pdfDocument.Save(ms);
            ms.Position = 0;

            //Close the document
            pdfDocument.Close(true);

            //Save the document.
            return(File(ms, "Application/pdf"));
        }
Exemple #11
0
        public async Task <FileStreamResult> CompleteAsync(int?id)
        {
            var paper = await _context.papers
                        .FirstOrDefaultAsync(m => m.id == id);


            List <StudentData> students = new List <StudentData>();
            List <StudentData> print    = new List <StudentData>();

            students = await _context.studentDatas.ToListAsync();

            StudentData student = null;

            for (int i = 0; i < students.Count(); i++)
            {
                if ((students[i].Studentid).Equals(paper.StudentID))

                {
                    student         = new StudentData();
                    student.Faculty = students[i].Faculty;
                    student.Course  = students[i].Course;
                    student.Note    = students[i].Note;
                    print.Add(student);
                }
            }



            PdfDocument document = new PdfDocument();

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

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

            //Set the standard font
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);



            FileStream imageStream = new FileStream("ua.jpg", FileMode.Open, FileAccess.Read);
            PdfBitmap  image       = new PdfBitmap(imageStream);

            //Draw the image
            graphics.DrawImage(image, 30, 0);



            if (paper.type == "Notes")
            {
                DataTable table = new DataTable("INFO");

                // Declare DataColumn and DataRow variables.
                DataColumn column;
                DataColumn column2;


                // Create column.
                column            = new DataColumn();
                column.DataType   = Type.GetType("System.String");
                column.ColumnName = "Course";
                table.Columns.Add(column);

                column2            = new DataColumn();
                column2.DataType   = Type.GetType("System.Int32");
                column2.ColumnName = "Note";
                table.Columns.Add(column2);

                foreach (StudentData item in print)
                {
                    table.Rows.Add(item.Course, item.Note);
                }



                PdfBrush  solidBrush = new PdfSolidBrush(new PdfColor(126, 151, 173));
                Rectangle bounds     = new RectangleF(0, 200, graphics.ClientSize.Width, 30);
                //Draws a rectangle to place the heading in that region.
                graphics.DrawRectangle(solidBrush, bounds);
                //Creates a font for adding the heading in the page
                PdfFont subHeadingFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 14);
                //Creates a text element to add the invoice number
                PdfTextElement element = new PdfTextElement("Student " + paper.Firstname + " " + paper.lastname, subHeadingFont);
                element.Brush = PdfBrushes.White;

                //Draws the heading on the page
                PdfLayoutResult result      = element.Draw(page, new PointF(10, bounds.Top + 8));
                string          currentDate = "DATE " + DateTime.Now.ToString("MM/dd/yyyy");
                //Measures the width of the text to place it in the correct location
                SizeF  textSize     = subHeadingFont.MeasureString(currentDate);
                PointF textPosition = new PointF(graphics.ClientSize.Width - textSize.Width - 10, result.Bounds.Y);
                //Draws the date by using DrawString method
                graphics.DrawString(currentDate, subHeadingFont, element.Brush, textPosition);
                PdfFont timesRoman = new PdfStandardFont(PdfFontFamily.TimesRoman, 10);
                //Creates text elements to add the address and draw it to the page.
                element       = new PdfTextElement("Student ID: " + paper.StudentID, timesRoman);
                element.Brush = new PdfSolidBrush(new PdfColor(126, 155, 203));
                result        = element.Draw(page, new PointF(10, result.Bounds.Bottom + 25));
                PdfPen linePen    = new PdfPen(new PdfColor(126, 151, 173), 0.70f);
                PointF startPoint = new PointF(0, result.Bounds.Bottom + 3);
                PointF endPoint   = new PointF(graphics.ClientSize.Width, result.Bounds.Bottom + 3);
                //Draws a line at the bottom of the address
                graphics.DrawLine(linePen, startPoint, endPoint);


                //Creates the datasource for the table

                //Creates a PDF grid
                PdfGrid grid = new PdfGrid();
                //Adds the data source
                grid.DataSource = table;
                //Creates the grid cell styles
                PdfGridCellStyle cellStyle = new PdfGridCellStyle();
                cellStyle.Borders.All = PdfPens.White;
                PdfGridRow header = grid.Headers[0];
                //Creates the header style
                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);

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

                //Applies the header style
                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));
                //Creates the layout format for grid
                PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat();
                // Creates layout format settings to allow the table pagination
                layoutFormat.Layout = PdfLayoutType.Paginate;
                //Draws the grid to the PDF page.
                PdfGridLayoutResult gridResult = grid.Draw(page, new RectangleF(new PointF(0, result.Bounds.Bottom + 40), new SizeF(graphics.ClientSize.Width, graphics.ClientSize.Height - 100)), layoutFormat);
            }

            if (paper.type == "Continue Education")
            {
                int    now   = DateTime.Now.Year;
                int    y     = now - 1;
                String text  = "The student " + paper.Firstname + " " + paper.lastname + " continu his/her education for the year: ";
                String text2 = y + "-" + now;
                graphics.DrawString(text, font, PdfBrushes.Black, new PointF(0, 180));
                graphics.DrawString(text2, font, PdfBrushes.Red, new PointF(0, 210));
            }


            //Saving the PDF to the MemoryStream
            MemoryStream stream = new MemoryStream();

            document.Save(stream);

            //Set the position as '0'.
            stream.Position = 0;

            //Download the PDF document in the browser
            FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf");

            fileStreamResult.FileDownloadName = paper.StudentID + "_" + paper.type + ".pdf";

            paper.Status = "Complete";

            _context.Update(paper);
            await _context.SaveChangesAsync();

            RedirectToAction("Admin");

            return(fileStreamResult);
        }
Exemple #12
0
        public void CreatePDF(List <object[]> items)
        {
            //Create a new PDF document.
            PdfDocument doc = new PdfDocument();
            //Add a page.
            PdfPage page = doc.Pages.Add();
            //Create a PdfGrid.
            PdfGrid pdfGrid = new PdfGrid();
            //Loads the image from disk
            string     CSPath    = Directory.GetParent(Directory.GetParent(Directory.GetParent(Directory.GetCurrentDirectory()).FullName).FullName).FullName;
            string     ImagePath = Path.Combine(CSPath, @"DAL\Images\LongLogo.jpeg");
            PdfImage   image     = PdfImage.FromFile(ImagePath);
            RectangleF bounds    = new RectangleF(50, 0, 400, 150);

            //Draws the image to the PDF page
            page.Graphics.DrawImage(image, bounds);
            Font            font    = new Font("Ariel", 14);
            PdfFont         pdfFont = new PdfTrueTypeFont(font, true);
            PdfStringFormat format  = new PdfStringFormat();

            //Set right-to-left text direction for RTL text
            format.TextDirection = PdfTextDirection.RightToLeft;
            format.Alignment     = PdfTextAlignment.Right;

            //Draw grid to the page of PDF document.
            PdfBrush solidBrush = new PdfSolidBrush(new PdfColor(126, 151, 173));

            bounds = new RectangleF(0, bounds.Bottom + 90, page.Graphics.ClientSize.Width, 30);
            //Draws a rectangle to place the heading in that region.
            page.Graphics.DrawRectangle(solidBrush, bounds);
            //Creates a text element to add the invoice number
            PdfTextElement element = new PdfTextElement("", pdfFont);

            element.Brush = PdfBrushes.White;
            //Draws the heading on the page
            PdfLayoutResult result      = element.Draw(page, new PointF(10, bounds.Top + 8));
            string          currentDate = DateTime.Now.ToString("MM/dd/yyyy");
            //Measures the width of the text to place it in the correct location
            SizeF  textSize     = pdfFont.MeasureString(currentDate);
            PointF textPosition = new PointF(page.Graphics.ClientSize.Width - textSize.Width + 70, result.Bounds.Y);

            //Draws the date by using DrawString method
            page.Graphics.DrawString(currentDate, pdfFont, element.Brush, textPosition, format);
            //Creates text elements to add the address and draw it to the page.
            element              = new PdfTextElement("רשימת הקניות שלך:", pdfFont);
            element.Brush        = new PdfSolidBrush(new PdfColor(126, 155, 203));
            element.StringFormat = format;
            result = element.Draw(page, new PointF(page.Graphics.ClientSize.Width - textSize.Width + 70, result.Bounds.Bottom + 25));
            PdfPen linePen    = new PdfPen(new PdfColor(126, 151, 173), 0.70f);
            PointF startPoint = new PointF(0, result.Bounds.Bottom + 3);
            PointF endPoint   = new PointF(page.Graphics.ClientSize.Width, result.Bounds.Bottom + 3);

            //Draws a line at the bottom of the address
            page.Graphics.DrawLine(linePen, startPoint, endPoint);



            //Create a DataTable.
            DataTable dataTable = new DataTable();

            //Add columns to the DataTable
            dataTable.Columns.Add("הכי זול אצל:");
            dataTable.Columns.Add("כמות");
            dataTable.Columns.Add("תיאור");
            dataTable.Columns.Add("שם");
            //Add rows to the DataTable.
            foreach (var item in items)
            {
                dataTable.Rows.Add(item);
            }

            //Creates the datasource for the table
            DataTable Details = dataTable;
            //Creates a PDF grid
            PdfGrid grid = new PdfGrid();

            grid.Style.Font = pdfFont;

            //Adds the data source
            grid.DataSource = Details;
            //Creates the grid cell styles
            PdfGridCellStyle cellStyle = new PdfGridCellStyle();

            cellStyle.Borders.All = PdfPens.White;
            //PdfGridRow header = grid.Headers[0];
            //Creates the header style
            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            = pdfFont;
            headerStyle.StringFormat    = format;
            //Applies the header style
            grid.Headers[0].ApplyStyle(headerStyle);
            foreach (PdfGridColumn Column in grid.Columns)
            {
                Column.Format = format;
            }
            cellStyle.Borders.Bottom = new PdfPen(new PdfColor(217, 217, 217), 0.70f);
            cellStyle.Font           = pdfFont;
            cellStyle.TextBrush      = new PdfSolidBrush(new PdfColor(131, 130, 136));
            cellStyle.StringFormat   = format;


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

            // Creates layout format settings to allow the table pagination
            layoutFormat.Layout = PdfLayoutType.Paginate;
            //Draws the grid to the PDF page.
            PdfGridLayoutResult gridResult = grid.Draw(page, new RectangleF(new PointF(0, result.Bounds.Bottom + 40), new SizeF(page.Graphics.ClientSize.Width, page.Graphics.ClientSize.Height - 100)), layoutFormat);

            pdfGrid.Draw(page, new PointF(10, 10));


            //Save the document.
            try
            {
                doc.Save("Output.pdf");
                System.Diagnostics.Process.Start("Output.pdf");
            }
            catch
            {
            }
            //close the document
            doc.Close(true);
        }
Exemple #13
0
        public bool CreatePDF(Movimientos movimientos, DataTable tablacarrito, Model.Usuario User)
        {
            try
            {
                PdfDocument document = new PdfDocument();
                //Adds page settings
                document.PageSettings.Orientation = PdfPageOrientation.Portrait;
                document.PageSettings.Margins.All = 50;
                //Adds a page to the document
                PdfPage page = document.Pages.Add();

                PdfGraphics graphics = page.Graphics;

                //Loads the image from disk
                //PdfImage image = PdfImage.FromFile("Logo.png");

                Stream imageStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("Inventario2.Assets.NewLogo.jpeg");
                //Load the image from the disk.
                PdfBitmap image = new PdfBitmap(imageStream);
                //Draw the image
                RectangleF bounds = new RectangleF(0, 0, 110, 110);
                //Draws the image to the PDF page
                page.Graphics.DrawImage(image, bounds);


                //DRAW THE MAIN TITLE
                PdfFont Headfont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
                //Creates a text element to add the invoice number
                PdfTextElement headelement = new PdfTextElement("AUDIO VIDEO STUDIOS ", Headfont);
                headelement.Brush = PdfBrushes.Red;
                PdfLayoutResult result = headelement.Draw(page, new PointF(graphics.ClientSize.Width - 350, graphics.ClientSize.Height - 740));


                PdfFont Subtitle = new PdfStandardFont(PdfFontFamily.Helvetica, 14);
                //Creates a text element to add the invoice number
                PdfTextElement subtitelement = new PdfTextElement("ORDEN DE SALIDA ", Subtitle);
                subtitelement.Brush = PdfBrushes.Red;
                PdfLayoutResult Subresult = subtitelement.Draw(page, new PointF(graphics.ClientSize.Width - 300, graphics.ClientSize.Height - 710));


                PdfBrush solidBrush = new PdfSolidBrush(new PdfColor(222, 237, 242));
                bounds = new RectangleF(bounds.Right, Subresult.Bounds.Bottom, graphics.ClientSize.Width - 300, 50);
                //Draws a rectangle to place the heading in that region.
                graphics.DrawRectangle(solidBrush, bounds);

                //creating fields, folio, fecha, lugar
                PdfFont        campofont = new PdfStandardFont(PdfFontFamily.TimesRoman, 12);
                PdfTextElement lblugar   = new PdfTextElement("EVENTO: ", campofont);
                lblugar.Brush = PdfBrushes.Black;
                PdfLayoutResult reslblugar = lblugar.Draw(page, new PointF(bounds.Left + 40, bounds.Top));

                PdfTextElement lbfecha = new PdfTextElement("FECHA: ", campofont);
                lbfecha.Brush = PdfBrushes.Black;
                PdfLayoutResult reslbfecha = lbfecha.Draw(page, new PointF(bounds.Left + 40, bounds.Top + 16));

                PdfTextElement lbfolio = new PdfTextElement("FOLIO: ", campofont);
                lbfolio.Brush = PdfBrushes.Black;
                PdfLayoutResult reslbfolio = lbfolio.Draw(page, new PointF(bounds.Left + 40, bounds.Top + 32));


                PdfBrush solidBrush2 = new PdfSolidBrush(new PdfColor(190, 220, 228));
                bounds = new RectangleF(bounds.Right, Subresult.Bounds.Bottom, graphics.ClientSize.Width - 300, 50);
                //Draws a rectangle to place the heading in that region.
                graphics.DrawRectangle(solidBrush2, bounds);


                //variables de campos
                PdfTextElement lugar = new PdfTextElement(movimientos.lugar, campofont);
                lugar.Brush = PdfBrushes.Black;
                PdfLayoutResult reslugar = lugar.Draw(page, new PointF(bounds.Left + 40, bounds.Top));

                PdfTextElement fecha = new PdfTextElement(DateTime.Now.ToString(), campofont);
                fecha.Brush = PdfBrushes.Black;
                PdfLayoutResult resfecha = fecha.Draw(page, new PointF(bounds.Left + 40, bounds.Top + 16));

                PdfTextElement folio = new PdfTextElement(movimientos.ID, campofont);
                folio.Brush = PdfBrushes.Black;
                PdfLayoutResult resfolio = folio.Draw(page, new PointF(bounds.Left + 40, bounds.Top + 32));

                //create table

                //Creates the datasource for the table
                DataTable invoiceDetails = tablacarrito;
                //Creates a PDF grid
                PdfGrid grid = new PdfGrid();
                //Adds the data source
                grid.DataSource = invoiceDetails;
                //Creates the grid cell styles
                PdfGridCellStyle cellStyle = new PdfGridCellStyle();
                cellStyle.Borders.All = PdfPens.White;
                PdfGridRow header = grid.Headers[0];
                //Creates the header style
                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, 16f, PdfFontStyle.Regular);

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

                //Applies the header style
                header.ApplyStyle(headerStyle);
                cellStyle.Borders.Bottom = new PdfPen(new PdfColor(217, 217, 217), 0.70f);
                cellStyle.Font           = new PdfStandardFont(PdfFontFamily.TimesRoman, 10f);
                cellStyle.TextBrush      = new PdfSolidBrush(new PdfColor(131, 130, 136));
                //Creates the layout format for grid
                PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat();
                // Creates layout format settings to allow the table pagination
                layoutFormat.Layout = PdfLayoutType.Paginate;

                //Draws the grid to the PDF page.
                PdfGridLayoutResult gridResult = grid.Draw(page, new RectangleF(new PointF(0, result.Bounds.Bottom + 150), new SizeF(graphics.ClientSize.Width, graphics.ClientSize.Height - 100)), layoutFormat);

                PdfGraphics graphicsSecond = gridResult.Page.Graphics;

                PdfPen linePen    = new PdfPen(new PdfColor(126, 151, 173), 1.0f);
                PointF startPoint = new PointF(0, gridResult.Bounds.Bottom + 60);
                PointF endPoint   = new PointF(150, gridResult.Bounds.Bottom + 60);
                //Draws a line at the bottom of the address
                graphicsSecond.DrawLine(linePen, startPoint, endPoint);


                PdfFont        entregafont = new PdfStandardFont(PdfFontFamily.TimesRoman, 12);
                PdfTextElement lbentrega   = new PdfTextElement("ENTREGA: ", entregafont);
                lbentrega.Brush = PdfBrushes.Black;
                PdfLayoutResult reslbentrega = lbentrega.Draw(gridResult.Page, new PointF(linePen.Width / 2.0f, startPoint.Y + 5));

                //texto de quien entrega
                PdfFont        usuarioentregafont = new PdfStandardFont(PdfFontFamily.TimesRoman, 12);
                PdfTextElement lbusuarioentrega   = new PdfTextElement(Model.User.nombre + " " + Model.User.apellido_paterno, usuarioentregafont);
                lbusuarioentrega.Brush = PdfBrushes.Black;
                PdfLayoutResult reslbusuarioentrega = lbusuarioentrega.Draw(gridResult.Page, new PointF(linePen.Width / 2.0f, startPoint.Y - 20));


                PdfPen linePenfinal    = new PdfPen(new PdfColor(126, 151, 173), 1.0f);
                PointF startPointfinal = new PointF(350, gridResult.Bounds.Bottom + 60);
                PointF endPointfinal   = new PointF(graphics.ClientSize.Width, gridResult.Bounds.Bottom + 60);
                //Draws a line at the bottom of the address
                graphicsSecond.DrawLine(linePenfinal, startPointfinal, endPointfinal);

                PdfFont        recibefont = new PdfStandardFont(PdfFontFamily.TimesRoman, 12);
                PdfTextElement lbrecibe   = new PdfTextElement("RECIBE: ", recibefont);
                lbrecibe.Brush = PdfBrushes.Black;
                PdfLayoutResult reslbrecibe = lbrecibe.Draw(gridResult.Page, new PointF(350.0f + (linePenfinal.Width / 2.0f), startPoint.Y + 5));

                //texto de quien recibe
                PdfFont        usuariofont = new PdfStandardFont(PdfFontFamily.TimesRoman, 12);
                PdfTextElement lbusuario   = new PdfTextElement(User.nombre + " " + User.apellido_paterno, usuariofont);
                lbusuario.Brush = PdfBrushes.Black;
                PdfLayoutResult reslbusuario = lbusuario.Draw(gridResult.Page, new PointF(350.0f + (linePenfinal.Width / 2.0f), startPoint.Y - 20));


                MemoryStream stream = new MemoryStream();

                //Save the document.
                document.Save(stream);
                streamPDF = stream;
                //Close the document.
                document.Close(true);

                byte[] bytes = stream.ToArray();


                bool   res  = SendSTMPT(bytes, correo);
                string save = "OrdenDeSalida-" + movimientos.ID;
                //Save the stream as a file in the device and invoke it for viewing
                // Xamarin.Forms.DependencyService.Get<ISave>().SaveAndView(save + ".pdf", "application/pdf", stream);
                //The operation in Save under Xamarin varies between Windows Phone, Android and iOS platforms. Please refer PDF/Xamarin section for respective code samples.

                if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows)
                {
                    // Xamarin.Forms.DependencyService.Get<ISaveWindowsPhone>().Save("Output.pdf", "application/pdf", stream);
                    Xamarin.Forms.DependencyService.Get <ISave>().SaveAndView(save + ".pdf", "application/pdf", stream);
                }
                else
                {
                    Xamarin.Forms.DependencyService.Get <ISave>().SaveAndView(save + ".pdf", "application/pdf", stream);
                }


                return(true);
            }
            catch
            {
                return(false);
            }
        }
        private float GenerateItemizedBodyWithGrid(GenerateInvoiceContext request, PdfGenerator pdf, float y)
        {
            y = pdf.IncrementY(y, 10, FOOTER_HEIGHT);
            //Create a new PdfGrid.

            PdfGrid pdfGrid = new PdfGrid();

            //Add four columns.

            pdfGrid.Columns.Add(4);
            var columnFormat = new PdfStringFormat
            {
                Alignment     = PdfTextAlignment.Center,
                LineAlignment = PdfVerticalAlignment.Middle
            };

            pdfGrid.Columns[1].Format = columnFormat;
            pdfGrid.Columns[2].Format = columnFormat;
            pdfGrid.Columns[3].Format = columnFormat;

            //Add header.

            pdfGrid.Headers.Add(1);

            PdfGridRow pdfGridHeader = pdfGrid.Headers[0];

            pdfGridHeader.Cells[0].Value = "Item";
            pdfGridHeader.Cells[1].Value = "Cost";
            pdfGridHeader.Cells[2].Value = "Qty";
            pdfGridHeader.Cells[3].Value = "Total";

            //Add rows.
            foreach (var item in request.Invoice.Items)
            {
                PdfGridRow pdfGridRow = pdfGrid.Rows.Add();

                //NOTE: It seems that values MUST be string values

                pdfGridRow.Cells[0].Value = item.Name;
                pdfGridRow.Cells[1].Value = item.ItemAmount.ToString("n2");
                pdfGridRow.Cells[2].Value = item.Quantity.ToString("n0");
                pdfGridRow.Cells[3].Value = item.Amount.ToString("n2");
            }

            var data = request.Invoice.Items.Select(x => x.ItemAmount.ToString("n2"));

            pdfGrid.Columns[1].SizeColumnToContent(data, pdf.PageWidth, pdf.NormalFont);
            data = request.Invoice.Items.Select(x => x.Quantity.ToString("n2"));
            pdfGrid.Columns[2].SizeColumnToContent(data, pdf.PageWidth, pdf.NormalFont);
            data = request.Invoice.Items.Select(x => x.Amount.ToString("n2"));
            pdfGrid.Columns[3].SizeColumnToContent(data, pdf.PageWidth, pdf.NormalFont);

            //Apply built-in table style
            //NOTE: that the accent2 color of #FFED7D31 is used in generating the total rectangle as well
            pdfGrid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable4Accent2);

            //Apply Custom Style
            //pdfGrid.Style = new PdfGridStyle
            //{
            //    //BackgroundBrush = pdf.AccentBrush,
            //    TextBrush = pdf.AccentBrush,
            //    //TextPen = new PdfPen(pdf.AccentBrush)
            //};

            PdfGridLayoutFormat format = new PdfGridLayoutFormat();

            format.Layout         = PdfLayoutType.Paginate;
            format.PaginateBounds = new RectangleF(0, 0, pdf.CurrentPage.Graphics.ClientSize.Width, pdf.CurrentPage.Graphics.ClientSize.Height - FOOTER_HEIGHT);

            //Draw the PdfGrid.
            var result = pdfGrid.Draw(pdf.CurrentPage, new PointF(10, y), format);

            return(result.Bounds.Bottom);
        }
Exemple #15
0
        private FileStreamResult ExportPDF(List <EOD> edo)
        {
            // Load the PDF Template
            Stream pdfStream = System.IO.File.OpenRead(_hostingEnvironment.WebRootPath + @"\assets\templates\CloseShop2.pdf");

            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, (float)8);
            //PdfFont fontText = new PdfStandardFont(PdfFontFamily.Helvetica, (float)12);
            PdfFont fontTextTHSarabunNew = new PdfTrueTypeFont(System.IO.File.OpenRead(_hostingEnvironment.WebRootPath + $@"\assets\fonts\THSarabunNew\THSarabunNew Bold.ttf"), 15);
            PdfFont fontTextCalibri      = new PdfTrueTypeFont(System.IO.File.OpenRead(_hostingEnvironment.WebRootPath + $@"\assets\fonts\calibri\Calibri.ttf"), 13);
            PdfFont fontTextCalibriBold  = new PdfTrueTypeFont(System.IO.File.OpenRead(_hostingEnvironment.WebRootPath + $@"\assets\fonts\calibri\Calibri.ttf"), 13, PdfFontStyle.Bold);

            // Load a PDF document.
            PdfLoadedDocument loadedDocument = new PdfLoadedDocument(pdfStream);

            //Create a new PDF document.
            PdfDocument pdfDocument = new PdfDocument();

            int     numPage = 1;
            PdfPage pdfPage;

            //Set the format for string.
            PdfStringFormat formatAlignRight  = new PdfStringFormat(PdfTextAlignment.Right);
            PdfStringFormat formatAlignCenter = new PdfStringFormat(PdfTextAlignment.Center);

            edo.ForEach(e => {
                pdfDocument.ImportPage(loadedDocument, 0);

                pdfPage = pdfDocument.Pages[numPage - 1];

                // Create PDF graphics for the page
                PdfGraphics graphics = pdfPage.Graphics;

                float xPosition = 105;
                float yPosition = (float)85.5;//106.5;
                float gap       = (float)20.5;

                #region Header Left
                // Branch Name
                graphics.DrawString(e.BranchName.Replace("KERRY EXPRESS", "Kerry Express"), fontTextTHSarabunNew, PdfBrushes.Black, new PointF(xPosition, yPosition));


                // Date
                yPosition += gap;
                graphics.DrawString(e.Report_Date.ToString("dd-MMMM-yyyy", _cultureTHInfo), fontTextTHSarabunNew, PdfBrushes.Black, new PointF(xPosition, yPosition));


                // Branch ID
                yPosition += gap + (float)1;
                graphics.DrawString(e.BranchID, fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition));


                // Cost Center
                yPosition += gap + (float)1;
                graphics.DrawString(e.ERPID, fontTextTHSarabunNew, PdfBrushes.Black, new PointF(xPosition, yPosition));
                #endregion


                #region Header Right
                // Branch Type
                xPosition = (float)464;
                yPosition = (float)107;
                graphics.DrawString(e.BranchType.Split('-')[0], fontTextCalibri, PdfBrushes.Black, new PointF(xPosition - (float)14.5, yPosition), formatAlignCenter);

                // Total Transfer
                xPosition = (float)555.31;
                yPosition = (float)107;
                graphics.DrawString(e.TotalTransfer.ToString("N"), fontTextCalibriBold, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Shipment
                yPosition += gap;
                graphics.DrawString(e.TotalShipments.ToString("N0"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Boxes
                yPosition += gap;
                graphics.DrawString(e.TotalBoxes.ToString("N0"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);
                #endregion

                #region Detail Service
                xPosition = (float)281.585;
                yPosition = (float)219;
                gap       = (float)19;

                // Transport Service
                graphics.DrawString(e.TransportService.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // AM Service
                yPosition += gap - 1;
                graphics.DrawString(e.AMService.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // PUP Service
                yPosition += gap - 2;
                graphics.DrawString(e.PUPService.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // SAT Service
                yPosition += gap - 1;
                graphics.DrawString(e.SATService.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // RAS Service
                yPosition += gap - 1;
                graphics.DrawString(e.RASService.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // COD Service
                yPosition += gap - 1;
                graphics.DrawString(e.CODService.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // INSUR Service
                yPosition += gap - 1;
                graphics.DrawString(e.INSURService.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Package Service
                yPosition += gap - 2;
                graphics.DrawString(e.PACKAGEService.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Sale Package Service
                yPosition += gap - 1;
                graphics.DrawString(e.SALEService.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);


                // Discount
                yPosition += gap + 1;
                graphics.DrawString(e.Discount.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Line Top-up Service
                yPosition += gap - 1;
                graphics.DrawString(e.LNTUPService.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                //rabbitTopUp
                yPosition += gap + 2;
                graphics.DrawString(e.rabbitTopUp.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                //mPayService
                yPosition += gap - 1;
                graphics.DrawString(e.mPayService.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Total Shipments
                yPosition += gap;
                graphics.DrawString(e.Shipment.ToString("N0"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Total Boxes
                yPosition += gap + 2;
                graphics.DrawString(e.Boxes.ToString("N0"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Drop-off Boxes
                yPosition += gap + 2;
                graphics.DrawString(e.DropOffBoxes.ToString("N0"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Total Detail Service
                yPosition += (float)34.5;
                graphics.DrawString(e.TotalDetailService.ToString("N"), fontTextCalibriBold, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);
                #endregion

                // Total Freight Revenue
                yPosition += (float)26;
                graphics.DrawString(e.TotalFreightRevenue.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                #region Detail Pay
                xPosition = (float)555.31;
                yPosition = (float)219.5;
                gap       = (float)19;

                // Cash
                graphics.DrawString(e.Cash.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Rabbit
                yPosition += gap + 2;
                graphics.DrawString(e.Rabbit.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Credit Card BBL
                yPosition += gap + 2;
                graphics.DrawString(e.CreditBBL.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Credit Card SCB
                yPosition += gap + 2;
                graphics.DrawString(e.CreditSCB.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Credit QR Payment
                yPosition += gap + 2;
                graphics.DrawString(e.QRPay.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // LinePay
                yPosition += gap + 2;
                graphics.DrawString(e.LinePay.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Total Detail Pay
                yPosition += (float)32;
                graphics.DrawString(e.TotalDetailPay.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);
                #endregion

                #region Detail Surcharge
                yPosition = (float)439.5;
                gap       = (float)19;

                // Transportation
                graphics.DrawString(e.Transportation.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // VAS Surcharge
                yPosition += gap + 2;
                graphics.DrawString(e.VASSurcharge.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Discount
                yPosition += gap + 2;
                graphics.DrawString(e.Discount.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Vat
                yPosition += gap + 2;
                graphics.DrawString(e.VAT.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Total Detail Surcharge
                yPosition += (float)29;
                graphics.DrawString(e.TotalDetailSurcharge.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);
                #endregion

                #region BSD Surcharge
                xPosition = (float)281.585;
                yPosition = (float)632.5;
                gap       = (float)19;

                // CITY
                graphics.DrawString(e.BSDCity.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // CITYN
                yPosition += gap + 2;
                graphics.DrawString(e.BSDCityn.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // CITYS
                yPosition += gap + 2;
                graphics.DrawString(e.BSDCitys.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Grab
                yPosition += gap + 2;
                graphics.DrawString(e.BSDGrab.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Discount
                yPosition += gap + 2;
                graphics.DrawString(e.BSDDiscount.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Total
                yPosition += gap + (float)12.5;
                graphics.DrawString(e.BSDTotalDetailService.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Total Consignment
                yPosition += gap + 12;
                graphics.DrawString(e.BSDConsignment.ToString("N0"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);
                #endregion

                #region BSD Surcharge
                xPosition = (float)555.31;
                yPosition = (float)632.5;
                gap       = (float)19;

                // Cash
                graphics.DrawString(e.BSDCash.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Line Pay
                yPosition += gap + 2;
                graphics.DrawString(e.BSDLinePay.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Total Payment
                yPosition += gap + 2;
                graphics.DrawString(e.BSDTotalPayment.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Line Topup
                yPosition += gap + 2;
                graphics.DrawString(e.BSDLineTopUp.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Dummy
                yPosition += gap + 2;
                graphics.DrawString("", fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Total Payment Cash
                yPosition += gap + (float)12.5;
                graphics.DrawString(e.BSDTotalPaymentCash.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Total Payment Boxes
                yPosition += gap + 12;
                graphics.DrawString(e.BSDBoxes.ToString("N0"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight);

                // Lasted Update
                string closedDate = e.LastedUpdate.HasValue
                ? e.LastedUpdate.Value.ToString("dd MMM yyyy HH:mm:ss", _cultureENInfo)
                : "N/A";

                yPosition += gap + (float)7.8;
                xPosition  = pdfDocument.Pages[0].GetClientSize().Width - 24;
                graphics.DrawString($"Closed Date/Time : {closedDate}", font, PdfBrushes.Red, new PointF(xPosition, yPosition), formatAlignRight);
                #endregion


                if (!(e.TotalDetailService.Equals(e.TotalDetailPay) && e.TotalDetailSurcharge.Equals(e.TotalDetailPay)))
                {
                    //watermark text.
                    PdfFont fontTextTHSarabunNewBold = new PdfTrueTypeFont(System.IO.File.OpenRead(_hostingEnvironment.WebRootPath + $@"\assets\fonts\THSarabunNew\THSarabunNew Bold.ttf"), 48);
                    PdfGraphicsState state           = graphics.Save();
                    graphics.SetTransparency(0.50f);
                    graphics.RotateTransform(-40);
                    graphics.DrawString("ข้อมูลไม่ถูกต้อง โปรดติดต่อผู้ดูแลระบบ", fontTextTHSarabunNewBold, PdfPens.Red, PdfBrushes.Red, new PointF(-300, 460));
                }

                numPage++;
            });

            //Set properties to paginate the table.
            PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat();
            layoutFormat.Break          = PdfLayoutBreakType.FitElement;
            layoutFormat.Layout         = PdfLayoutType.Paginate;
            layoutFormat.PaginateBounds = new RectangleF(20, 20, pdfDocument.Pages[0].GetClientSize().Width - 40, pdfDocument.Pages[0].GetClientSize().Height - 50);

            //Create a Page template that can be used as footer.
            RectangleF             bounds = new RectangleF(0, 0, pdfDocument.Pages[0].GetClientSize().Width, 50);
            PdfPageTemplateElement footer = new PdfPageTemplateElement(bounds);
            PdfBrush brush = new PdfSolidBrush(Color.Black);

            //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, "Page {0} of {1}", pageNumber, count);

            string            printDate          = DateTime.Now.ToString("dd MMM yyyy HH:mm:ss", _cultureENInfo);
            PdfCompositeField compositePrintDate = new PdfCompositeField(font, brush, string.Format("Printed from PDC/CloseShop      Printed Date/Time : {0}", printDate));

            compositeField.Bounds = footer.Bounds;

            //Draw the composite field in footer.
            compositeField.Draw(footer.Graphics, new PointF(pdfDocument.Pages[0].GetClientSize().Width - (float)63.5, 30));
            compositePrintDate.Draw(footer.Graphics, new PointF((float)24, 30));

            //Add the footer template at the bottom.
            pdfDocument.Template.Bottom = footer;

            MemoryStream ms = new MemoryStream();
            pdfDocument.Save(ms);
            ms.Position = 0;

            //Close the document
            pdfDocument.Close(true);

            // Close file
            pdfStream.Dispose();

            //Save the document.
            return(File(ms, "Application/pdf"));
        }
Exemple #16
0
        public ActionResult CreateDocument()
        {
            //Creates a new PDF document
            PdfDocument document = new PdfDocument();

            //Adds page settings
            document.PageSettings.Orientation = PdfPageOrientation.Portrait;
            document.PageSettings.Margins.All = 50;
            //Adds a page to the document
            PdfPage     page     = document.Pages.Add();
            PdfGraphics graphics = page.Graphics;
            RectangleF  bounds   = new RectangleF();

            if (person.photo != null)
            {
                //Loads the image as stream
                System.Drawing.Image img = System.Drawing.Image.FromFile(@person.photo.ImagePath);
                double perc;
                perc = 200.0 / img.Width;
                float      newHeight   = (float)(img.Height * perc);
                FileStream imageStream = new FileStream(person.photo.ImagePath, FileMode.Open, FileAccess.Read);
                bounds = new RectangleF(250, 0, 200, newHeight);
                PdfImage image = PdfImage.FromStream(imageStream);
                //Draws the image to the PDF page
                page.Graphics.DrawImage(image, bounds);
            }
            PdfBrush solidBrush = new PdfSolidBrush(new PdfColor(126, 151, 173));

            bounds = new RectangleF(0, bounds.Bottom + 90, graphics.ClientSize.Width, 30);
            //Draws a rectangle to place the heading in that region.
            graphics.DrawRectangle(solidBrush, bounds);
            //Creates a font for adding the heading in the page
            PdfFont subHeadingFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 14);
            //Creates a text element to add the invoice number
            PdfTextElement element = new PdfTextElement("Personal Information", subHeadingFont);

            element.Brush = PdfBrushes.White;

            //Draws the heading on the page
            PdfLayoutResult result       = element.Draw(page, new PointF(10, bounds.Top + 8));
            string          name         = person.personalInfo.FirstName + " " + person.personalInfo.LastName;
            SizeF           textSize     = subHeadingFont.MeasureString(name);
            PointF          textPosition = new PointF(graphics.ClientSize.Width - textSize.Width - 10, result.Bounds.Y);

            graphics.DrawString(name, subHeadingFont, element.Brush, textPosition);
            PdfFont timesRoman = new PdfStandardFont(PdfFontFamily.TimesRoman, 12);

            //Creates text elements to add the address and draw it to the page.
            element = new PdfTextElement(System.Environment.NewLine
                                         + "Phonenumber: " + person.personalInfo.Phonenumber + System.Environment.NewLine, timesRoman);
            element.Brush = new PdfSolidBrush(new PdfColor(1, 0, 0));
            result        = element.Draw(page, new PointF(10, result.Bounds.Bottom + 25));
            PdfPen linePen    = new PdfPen(new PdfColor(126, 151, 173), 0.70f);
            PointF startPoint = new PointF(0, result.Bounds.Bottom + 3);
            PointF endPoint   = new PointF(graphics.ClientSize.Width, result.Bounds.Bottom + 3);

            //Draws a line at the bottom of the address
            graphics.DrawLine(linePen, startPoint, endPoint);

            element = new PdfTextElement(System.Environment.NewLine
                                         + "Email: " + person.personalInfo.Email + System.Environment.NewLine, timesRoman);
            element.Brush = new PdfSolidBrush(new PdfColor(1, 0, 0));
            result        = element.Draw(page, new PointF(10, result.Bounds.Bottom + 25));
            linePen       = new PdfPen(new PdfColor(126, 151, 173), 0.70f);
            startPoint    = new PointF(0, result.Bounds.Bottom + 3);
            endPoint      = new PointF(graphics.ClientSize.Width, result.Bounds.Bottom + 3);
            //Draws a line at the bottom of the address
            graphics.DrawLine(linePen, startPoint, endPoint);

            DateTime strDate = new DateTime(person.personalInfo.BirthDay.Year, person.personalInfo.BirthDay.Month, person.personalInfo.BirthDay.Day);

            element = new PdfTextElement(System.Environment.NewLine
                                         + "BirthDay: " + person.personalInfo.BirthDay.ToString("d") + System.Environment.NewLine, timesRoman);
            element.Brush = new PdfSolidBrush(new PdfColor(1, 0, 0));
            result        = element.Draw(page, new PointF(10, result.Bounds.Bottom + 25));
            linePen       = new PdfPen(new PdfColor(126, 151, 173), 0.70f);
            startPoint    = new PointF(0, result.Bounds.Bottom + 3);
            endPoint      = new PointF(graphics.ClientSize.Width, result.Bounds.Bottom + 3);
            //Draws a line at the bottom of the address
            graphics.DrawLine(linePen, startPoint, endPoint);

            element = new PdfTextElement(System.Environment.NewLine
                                         + "Location: " + person.personalInfo.City + System.Environment.NewLine, timesRoman);
            element.Brush = new PdfSolidBrush(new PdfColor(1, 0, 0));
            result        = element.Draw(page, new PointF(10, result.Bounds.Bottom + 25));
            linePen       = new PdfPen(new PdfColor(126, 151, 173), 0.70f);
            startPoint    = new PointF(0, result.Bounds.Bottom + 3);
            endPoint      = new PointF(graphics.ClientSize.Width, result.Bounds.Bottom + 3);
            //Draws a line at the bottom of the address
            graphics.DrawLine(linePen, startPoint, endPoint);

            if (!person.personalInfo.Skills.Contains("Enter text here..."))
            {
                element = new PdfTextElement(System.Environment.NewLine
                                             + "Skills: " + person.personalInfo.Skills + System.Environment.NewLine, timesRoman);
                element.Brush = new PdfSolidBrush(new PdfColor(1, 0, 0));
                result        = element.Draw(page, new PointF(10, result.Bounds.Bottom + 25));
                linePen       = new PdfPen(new PdfColor(126, 151, 173), 0.70f);
                startPoint    = new PointF(0, result.Bounds.Bottom + 3);
                endPoint      = new PointF(graphics.ClientSize.Width, result.Bounds.Bottom + 3);
                //Draws a line at the bottom of the address
                graphics.DrawLine(linePen, startPoint, endPoint);
            }

            DataTable           Details;
            PdfGrid             grid;
            PdfGridCellStyle    cellStyle;
            PdfGridRow          header;
            PdfGridCellStyle    headerStyle  = new PdfGridCellStyle();
            PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat();
            PdfGridLayoutResult gridResult;

            if (person.gainedEducation != null && person.gainedEducation.Count > 0)
            {
                //Creates the datasource for the table
                Details = new DataTable();
                Details = CreateDataTable(person.gainedEducation);
                //Creates a PDF grid
                grid = new PdfGrid();
                //Adds the data source
                grid.DataSource = Details;
                //Creates the grid cell styles
                cellStyle             = new PdfGridCellStyle();
                cellStyle.Borders.All = PdfPens.White;
                header = grid.Headers[0];
                //Creates the header style
                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);

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

                //Applies the header style
                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));
                //Creates the layout format for grid
                layoutFormat = new PdfGridLayoutFormat();
                // Creates layout format settings to allow the table pagination
                layoutFormat.Layout = PdfLayoutType.Paginate;
                //Draws the grid to the PDF page.
                gridResult = grid.Draw(page, new RectangleF
                                           (new PointF(0, result.Bounds.Bottom + 40), new SizeF(graphics.ClientSize.Width, graphics.ClientSize.Height - 50)),
                                       layoutFormat);
                page          = document.Pages.Add();
                element       = new PdfTextElement(" ", subHeadingFont);
                element.Brush = PdfBrushes.White;
                graphics      = page.Graphics;
                result        = element.Draw(page, new PointF(10, 10));
            }
            if (person.Languages != null && person.Languages.Count > 0)
            {
                Details = new DataTable();

                //Creates the datasource for the table
                Details = CreateDataTable(person.Languages);
                //Creates a PDF grid
                grid = new PdfGrid();
                //Adds the data source
                grid.DataSource = Details;
                //Creates the grid cell styles
                cellStyle             = new PdfGridCellStyle();
                cellStyle.Borders.All = PdfPens.White;
                header = grid.Headers[0];
                //Creates the header style
                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);

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

                //Applies the header style
                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));
                //Creates the layout format for grid
                layoutFormat = new PdfGridLayoutFormat();
                // Creates layout format settings to allow the table pagination
                layoutFormat.Layout = PdfLayoutType.Paginate;
                //Draws the grid to the PDF page.
                gridResult = grid.Draw(page, new RectangleF
                                           (new PointF(0, result.Bounds.Bottom + 40), new SizeF(graphics.ClientSize.Width, graphics.ClientSize.Height - 50)),
                                       layoutFormat);
                page          = document.Pages.Add();
                element       = new PdfTextElement(" ", subHeadingFont);
                element.Brush = PdfBrushes.White;
                graphics      = page.Graphics;
                result        = element.Draw(page, new PointF(10, 10));
            }

            if (person.gainedExperience != null && person.gainedExperience.Count > 0)
            {
                Details = new DataTable();

                //Creates the datasource for the table
                Details = CreateDataTable(person.gainedExperience);
                //Creates a PDF grid
                grid = new PdfGrid();
                //Adds the data source
                grid.DataSource = Details;
                //Creates the grid cell styles
                cellStyle             = new PdfGridCellStyle();
                cellStyle.Borders.All = PdfPens.White;
                header = grid.Headers[0];
                //Creates the header style
                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);

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

                //Applies the header style
                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));
                //Creates the layout format for grid
                layoutFormat = new PdfGridLayoutFormat();
                // Creates layout format settings to allow the table pagination
                layoutFormat.Layout = PdfLayoutType.Paginate;
                //Draws the grid to the PDF page.
                gridResult = grid.Draw(page, new RectangleF
                                           (new PointF(0, result.Bounds.Bottom + 40), new SizeF(graphics.ClientSize.Width, graphics.ClientSize.Height - 50)),
                                       layoutFormat);
            }



            //FileStream fileStream = new FileStream("Sample.pdf", FileMode.CreateNew, FileAccess.ReadWrite);
            ////Save and close the PDF document
            //document.Save(fileStream);
            ////document.Close(true);
            MemoryStream stream = new MemoryStream();

            document.Save(stream);

            //If the position is not set to '0' then the PDF will be empty.
            stream.Position = 0;

            //Download the PDF document in the browser.
            FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf");

            fileStreamResult.FileDownloadName = "YourCV.pdf";
            return(fileStreamResult);



            ////Create a new PDF document
            //PdfDocument document = new PdfDocument();

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

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

            ////Set the standard font
            //PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);

            ////Draw the text
            //graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0));

            ////Saving the PDF to the MemoryStream
            //MemoryStream stream = new MemoryStream();

            //document.Save(stream);

            ////If the position is not set to '0' then the PDF will be empty.
            //stream.Position = 0;

            ////Download the PDF document in the browser.
            //FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf");
            //fileStreamResult.FileDownloadName = "YourCV.pdf";
            //return fileStreamResult;
        }
Exemple #17
0
        private async void GeneratePDF_Click(object sender, RoutedEventArgs e)
        {
            total = 0;
            string id = this.OrderIdList.SelectedValue.ToString();
            IEnumerable <CustOrders> products = Orders.GetProducts(id);

            List <CustOrders> list = new List <CustOrders>();

            foreach (CustOrders cust in products)
            {
                list.Add(cust);
            }
            var reducedList = list.Select(f => new { f.ProductID, f.ProductName, f.Quantity, f.UnitPrice, f.Discount, f.Price }).ToList();

            IEnumerable <ShipDetails> shipDetails = Orders.GetShipDetails();
            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("Northwind Traders\n67, rue des Cinquante Otages,\nElgin,\nUnites States.");

            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(Invoice).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.logo.jpg");

            PdfImage img = new PdfBitmap(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, 30));


            element       = new PdfTextElement("INVOICE " + id.ToString(), subHeadingFont);
            element.Brush = PdfBrushes.White;
            result        = element.Draw(page, new PointF(10, result.Bounds.Bottom + 48));
            string currentDate = "DATE " + DateTime.Now.ToString("MM/dd/yyyy");
            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, 10));
            element.Brush = new PdfSolidBrush(new PdfColor(126, 155, 203));
            result        = element.Draw(page, new PointF(10, result.Bounds.Bottom + 25));

            g.DrawLine(new PdfPen(new PdfColor(126, 151, 173), 0.70f), new PointF(0, result.Bounds.Bottom + 3), new PointF(g.ClientSize.Width, result.Bounds.Bottom + 3));

            GetShipDetails(shipDetails);

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

            element       = new PdfTextElement(string.Format("{0}, {1}, {2}", address, shipCity, shipCountry), new PdfStandardFont(PdfFontFamily.TimesRoman, 10));
            element.Brush = new PdfSolidBrush(new PdfColor(89, 89, 93));
            result        = element.Draw(page, new RectangleF(10, result.Bounds.Bottom + 3, g.ClientSize.Width / 2, 100));

            PdfGrid grid = new PdfGrid();

            grid.DataSource = reducedList;


            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 || i == 1)
                {
                    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 == 1)
                    {
                        cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                    }
                    else if (i == 0)
                    {
                        cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                    }
                    else
                    {
                        cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
                    }

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

            grid.Columns[0].Width = 100;
            grid.Columns[1].Width = 200;

            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.TimesRoman, 14f);

            GetTotalPrice(products);

            gridResult.Page.Graphics.DrawString("Total Due", font, new PdfSolidBrush(new PdfColor(126, 151, 173)), new RectangleF(new PointF(pos, gridResult.Bounds.Bottom + 20), 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, 12), new PdfSolidBrush(new PdfColor(89, 89, 93)), new PointF(pos - 55, gridResult.Bounds.Bottom + 60));
            pos += grid.Columns[4].Width;
            gridResult.Page.Graphics.DrawString('$' + string.Format("{0:N2}", total), font, new PdfSolidBrush(new PdfColor(131, 130, 136)), new RectangleF(new PointF(pos, gridResult.Bounds.Bottom + 20), new SizeF(grid.Columns[4].Width - pos, 20)), new PdfStringFormat(PdfTextAlignment.Right));


            MemoryStream stream = new MemoryStream();
            await document.SaveAsync(stream);

            document.Close(true);
            Save(stream, "Invoice.pdf");
        }
Exemple #18
0
        public IActionResult Index()
        {
            //Creates a new PDF document
            PdfDocument document = new PdfDocument();

            //Adds page settings
            document.PageSettings.Orientation = PdfPageOrientation.Landscape;
            document.PageSettings.Margins.All = 50;
            //Adds a page to the document
            PdfPage     page     = document.Pages.Add();
            PdfGraphics graphics = page.Graphics;

            //Loads the image as stream
            FileStream imageStream = new FileStream("logo.png", FileMode.Open, FileAccess.Read);
            RectangleF bounds      = new RectangleF(176, 0, 390, 130);
            PdfImage   image       = PdfImage.FromStream(imageStream);

            //Draws the image to the PDF page
            page.Graphics.DrawImage(image, bounds);
            PdfBrush solidBrush = new PdfSolidBrush(new PdfColor(126, 151, 173));

            bounds = new RectangleF(0, bounds.Bottom + 90, graphics.ClientSize.Width, 30);
            //Draws a rectangle to place the heading in that region.
            graphics.DrawRectangle(solidBrush, bounds);
            //Creates a font for adding the heading in the page
            PdfFont subHeadingFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 14);
            //Creates a text element to add the invoice number
            PdfTextElement element = new PdfTextElement("Purchase Order", subHeadingFont);

            element.Brush = PdfBrushes.White;

            //Draws the heading on the page
            PdfLayoutResult result      = element.Draw(page, new PointF(10, bounds.Top + 8));
            string          currentDate = "DATE " + DateTime.Now.ToString("MM/dd/yyyy");
            //Measures the width of the text to place it in the correct location
            SizeF  textSize     = subHeadingFont.MeasureString(currentDate);
            PointF textPosition = new PointF(graphics.ClientSize.Width - textSize.Width - 10, result.Bounds.Y);

            //Draws the date by using DrawString method
            graphics.DrawString(currentDate, subHeadingFont, element.Brush, textPosition);
            PdfFont timesRoman = new PdfStandardFont(PdfFontFamily.TimesRoman, 10);

            //Creates text elements to add the address and draw it to the page.
            element       = new PdfTextElement("BILL TO ", timesRoman);
            element.Brush = new PdfSolidBrush(new PdfColor(126, 155, 203));
            result        = element.Draw(page, new PointF(10, result.Bounds.Bottom + 25));
            PdfPen linePen    = new PdfPen(new PdfColor(126, 151, 173), 0.70f);
            PointF startPoint = new PointF(0, result.Bounds.Bottom + 3);
            PointF endPoint   = new PointF(graphics.ClientSize.Width, result.Bounds.Bottom + 3);

            //Draws a line at the bottom of the address
            graphics.DrawLine(linePen, startPoint, endPoint);
            //Creates the datasource for the table
            var invoiceDetails = GetProductDetailsAsDataTable();
            //Creates a PDF grid
            PdfGrid grid = new PdfGrid();

            //Adds the data source
            grid.DataSource = invoiceDetails;
            //Creates the grid cell styles
            PdfGridCellStyle cellStyle = new PdfGridCellStyle();

            cellStyle.Borders.All = PdfPens.White;
            PdfGridRow header = grid.Headers[0];
            //Creates the header style
            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);

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

            //Applies the header style
            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));
            //Creates the layout format for grid
            PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat();

            // Creates layout format settings to allow the table pagination
            layoutFormat.Layout = PdfLayoutType.Paginate;
            //Draws the grid to the PDF page.
            PdfGridLayoutResult gridResult = grid.Draw(page, new RectangleF(new PointF(0, result.Bounds.Bottom + 40), new SizeF(graphics.ClientSize.Width, graphics.ClientSize.Height - 100)), layoutFormat);
            //Save the PDF document to stream
            MemoryStream ms = new MemoryStream();

            document.Save(ms);
            document.Close(true);


            ms.Position = 0;

            FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf");

            fileStreamResult.FileDownloadName = "Sample.pdf";
            return(fileStreamResult);
        }
Exemple #19
0
        private async void TableFeaturesSample()
        {
            #region Field Definitions
            //Load product data.
            IEnumerable <Products> products = DataProvider.GetProducts();

            //Create a new PDF standard font
            PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 8f);

            PdfStandardFont smallFont = new PdfStandardFont(font, 5f);

            PdfFont bigFont = new PdfStandardFont(font, 16f);

            //Create a new PDF solid brush
            PdfBrush orangeBrush = new PdfSolidBrush(new PdfColor(247, 148, 29));

            PdfBrush grayBrush = new PdfSolidBrush(new PdfColor(170, 171, 171));

            //Create a new PDF pen
            PdfPen borderPen = new PdfPen(PdfBrushes.DarkGray, .3f);

            borderPen.LineCap = PdfLineCap.Square;

            PdfPen transparentPen = new PdfPen(PdfBrushes.Transparent, .3f);

            transparentPen.LineCap = PdfLineCap.Square;

            float margin = 40f;
            #endregion

            MemoryStream stream = new MemoryStream();

            //Create a new PDF document
            using (PdfDocument document = new PdfDocument())
            {
                //Set the margins
                document.PageSettings.Margins.All = 0;

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

                //Add the document header
                AddHeader(document, "Syncfusion Essential PDF");

                //Add the document footer
                AddFooter(document, font, grayBrush);

                //Draw the text to the PDF page
                page.Graphics.DrawString("What You Get with Syncfusion", bigFont, orangeBrush, new PointF(10, 10));

                #region PdfGrid
                //Create a new PDF grid
                PdfGrid pdfGrid = new PdfGrid();

                IEnumerable <Report> report = DataProvider.GetReport();
                pdfGrid.DataSource = report;
                pdfGrid.Headers.Clear();
                pdfGrid.Columns[0].Width  = 80;
                pdfGrid.Style.Font        = font;
                pdfGrid.Style.CellSpacing = 15f;

                for (int i = 0; i < pdfGrid.Rows.Count; i++)
                {
                    if (i % 2 == 0)
                    {
                        PdfGridCell cell = pdfGrid.Rows[i].Cells[0];

                        cell.RowSpan = 2;

                        Stream imgStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Assets." + cell.Value.ToString().ToLower() + ".jpg");

                        //Set cell background image
                        cell.Style.BackgroundImage = new PdfBitmap(imgStream);

                        cell.Value = "";

                        cell = pdfGrid.Rows[i].Cells[1];

                        cell.Style.Font = bigFont;
                    }
                    for (int j = 0; j < pdfGrid.Columns.Count; j++)
                    {
                        pdfGrid.Rows[i].Cells[j].Style.Borders.All = transparentPen;
                    }
                }

                //Create a PDF grid layout format
                PdfGridLayoutFormat gridLayoutFormat = new PdfGridLayoutFormat();

                //Set pagination
                gridLayoutFormat.Layout = PdfLayoutType.Paginate;

                //Draw the grid to the PDF document
                pdfGrid.Draw(page, new RectangleF(new PointF(margin, 75), new SizeF(page.Graphics.ClientSize.Width - (2 * margin), page.Graphics.ClientSize.Height - margin)), gridLayoutFormat);
                #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("TableFeatures.pdf", "application/pdf", stream);
                }
                else
                {
                    Xamarin.Forms.DependencyService.Get <ISave>().Save("TableFeatures.pdf", "application/pdf", stream);
                }
            }
        }
Exemple #20
0
        private void DrawDataTable(PdfPage page, PdfGraphics graphics)
        {
            //Create a new PdfGrid.
            PdfGrid pdfGrid = new PdfGrid();


            //Pagination
            PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat();

            layoutFormat.Break  = PdfLayoutBreakType.FitColumnsToPage;
            layoutFormat.Layout = PdfLayoutType.Paginate;


            //Cell Padding
            pdfGrid.Style.CellPadding.All = 4;
            //Cell align text
            PdfStringFormat centredText = new PdfStringFormat()
            {
                LineAlignment = PdfVerticalAlignment.Middle,
                Alignment     = PdfTextAlignment.Center
            };
            PdfStringFormat leftText = new PdfStringFormat()
            {
                LineAlignment = PdfVerticalAlignment.Middle,
                Alignment     = PdfTextAlignment.Left
            };
            PdfStringFormat rightText = new PdfStringFormat()
            {
                LineAlignment = PdfVerticalAlignment.Middle,
                Alignment     = PdfTextAlignment.Right
            };

            //Add 7 column
            pdfGrid.Columns.Add(5);

            pdfGrid.Columns[0].Width = 270;
            pdfGrid.Columns[1].Width = 50;
            pdfGrid.Columns[2].Width = 70;
            pdfGrid.Columns[3].Width = 80;
            pdfGrid.Columns[4].Width = 100;


            //Add header.
            pdfGrid.Headers.Add(1);
            PdfGridRow pdfGridHeader = pdfGrid.Headers[0];

            pdfGridHeader.Style.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 14);


            pdfGridHeader.Cells[0].Value = AppResources.Description;
            pdfGridHeader.Cells[1].Value = AppResources.Taxes;
            pdfGridHeader.Cells[2].Value = AppResources.Quantity;
            pdfGridHeader.Cells[3].Value = AppResources.UnitPrice;
            pdfGridHeader.Cells[4].Value = AppResources.Price;


            //centre text dans cellule
            for (var i = 0; i < 5; i++)
            {
                pdfGridHeader.Cells[i].StringFormat = centredText;
            }

            //Add Rows
            string logo = model.CurrencyLogo;



            Stream fontstream = typeof(ContactsPage).GetTypeInfo().Assembly.GetManifestResourceStream("voltaire.Resources.Raleway-Regular.ttf");

            for (int i = 0; i < OrderItems.Count; i++)
            {
                PdfGridRow pdfGridRow = pdfGrid.Rows.Add();

                pdfGridRow.Style.Font = new PdfTrueTypeFont(fontstream, 12);

                pdfGridRow.Cells[0].Value        = string.IsNullOrEmpty(OrderItems[i].Description) ? "" : OrderItems[i].Description;
                pdfGridRow.Cells[0].StringFormat = leftText;

                pdfGridRow.Cells[1].Value        = OrderItems[i].TaxPercent.ToString() + "%";
                pdfGridRow.Cells[1].StringFormat = centredText;

                pdfGridRow.Cells[2].Value        = OrderItems[i].Quantity.ToString();
                pdfGridRow.Cells[2].StringFormat = centredText;

                pdfGridRow.Cells[3].Value        = OrderItems[i].Product.PriceUnit + logo;
                pdfGridRow.Cells[3].StringFormat = centredText;

                pdfGridRow.Cells[4].Value        = (OrderItems[i].Product.PriceUnit * OrderItems[i].Product.ProductQty) + logo;
                pdfGridRow.Cells[4].StringFormat = rightText;
            }

            //ajout sub total
            PdfGridRow pdfGridRowTotal = pdfGrid.Rows.Add();

            pdfGridRowTotal.Style.Font            = new PdfTrueTypeFont(fontstream, 12);
            pdfGridRowTotal.Cells[0].ColumnSpan   = 4;
            pdfGridRowTotal.Cells[0].Value        = AppResources.TotalHT;
            pdfGridRowTotal.Cells[0].StringFormat = rightText;

            pdfGridRowTotal.Cells[4].Value        = SaleOrder.AmountUntaxed + logo;
            pdfGridRowTotal.Cells[4].StringFormat = rightText;

            //ajout taxes
            if (true)
            {
                PdfGridRow pdfGridRowDeposit = pdfGrid.Rows.Add();
                pdfGridRowDeposit.Style.Font = new PdfTrueTypeFont(fontstream, 12);

                pdfGridRowDeposit.Cells[0].ColumnSpan   = 4;
                pdfGridRowDeposit.Cells[0].Value        = AppResources.Taxes;
                pdfGridRowDeposit.Cells[0].StringFormat = rightText;

                pdfGridRowDeposit.Cells[4].Value        = SaleOrder.AmountTax + logo;
                pdfGridRowDeposit.Cells[4].StringFormat = rightText;
            }

            //Total
            PdfGridRow pdfGridRowtotal = pdfGrid.Rows.Add();

            pdfGridRowtotal.Style.Font = new PdfTrueTypeFont(fontstream, 12);

            pdfGridRowtotal.Cells[0].ColumnSpan   = 4;
            pdfGridRowtotal.Cells[0].Value        = AppResources.Total;
            pdfGridRowtotal.Cells[0].StringFormat = rightText;

            pdfGridRowtotal.Cells[4].Value        = $"{SaleOrder.AmountTotal}{logo}";
            pdfGridRowtotal.Cells[4].StringFormat = rightText;


            //signature
            if (Signature != null)
            {
                PdfGridRow pdfGridRowsign = pdfGrid.Rows.Add();

                pdfGridRowsign.Height = 70;

                PdfBitmap pBmp = new PdfBitmap(new MemoryStream(Signature));

                pdfGridRowsign.Cells[0].Style.BackgroundImage = pBmp;
                pdfGridRowsign.Cells[0].Value = "";
            }

            //Style du PdfGrid
            PdfGridBuiltinStyleSettings tableStyleOption = new PdfGridBuiltinStyleSettings();

            tableStyleOption.ApplyStyleForBandedRows = true;
            tableStyleOption.ApplyStyleForHeaderRow  = true;

            pdfGrid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable4Accent1);

            //ecriture du pdfGrid
            resultDataTable = pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(0, 300), layoutFormat);
        }
Exemple #21
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);
        }
        public ActionResult DownloadPDF(int orderId)
        {
            var         order         = orderRepository.GetOrderDetailsById(orderId);
            int         ShipingCharge = Convert.ToInt32(configuration["shippingCharge"]);
            PdfDocument document      = new PdfDocument();

            //Adds page settings
            document.PageSettings.Orientation = PdfPageOrientation.Landscape;
            document.PageSettings.Margins.All = 50;
            //Adds a page to the document
            PdfPage     page     = document.Pages.Add();
            PdfGraphics graphics = page.Graphics;
            //Set the standard font
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 35, PdfFontStyle.Bold);


            //Draw the text
            graphics.DrawString("Prince Fashion!", font, PdfBrushes.Gray, new PointF(120, 5));

            FileStream imageStream = new FileStream("wwwroot/images/logo.png", FileMode.Open, FileAccess.Read);


            RectangleF bounds = new RectangleF(10, 0, 80, 40);
            PdfImage   image  = PdfImage.FromStream(imageStream);

            //Draws the image to the PDF page
            page.Graphics.DrawImage(image, bounds);

            PdfBrush solidBrush = new PdfSolidBrush(new PdfColor(116, 152, 190));

            bounds = new RectangleF(0, bounds.Bottom + 50, graphics.ClientSize.Width, 40);
            //Draws a rectangle to place the heading in that region.
            graphics.DrawRectangle(solidBrush, bounds);
            //Creates a font for adding the heading in the page
            PdfFont subHeadingFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 14);
            //Creates a text element to add the invoice number

            PdfTextElement element1;

            if (order.OrderType.Equals("DoneOnlinepayment"))
            {
                element1 = new PdfTextElement("Type :: " + order.OrderType, subHeadingFont);
            }
            else
            {
                element1 = new PdfTextElement("Type :: COD ");
            }

            element1.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 16, PdfFontStyle.Bold);

            element1.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            element1.Draw(page, new PointF(graphics.ClientSize.Width - 250, bounds.Top - 40));


            PdfTextElement element = new PdfTextElement("INVOICE " + orderId, subHeadingFont);

            element.Brush = PdfBrushes.White;

            //Draws the heading on the page
            PdfLayoutResult result      = element.Draw(page, new PointF(10, bounds.Top + 8));
            string          currentDate = "DATE " + DateTime.Now.ToString("dd/MM/yyyy");
            //Measures the width of the text to place it in the correct location
            SizeF  textSize     = subHeadingFont.MeasureString(currentDate);
            PointF textPosition = new PointF(graphics.ClientSize.Width - textSize.Width - 10, result.Bounds.Y);


            //Draws the date by using DrawString method
            graphics.DrawString(currentDate, subHeadingFont, element.Brush, textPosition);
            PdfFont timesRoman = new PdfStandardFont(PdfFontFamily.TimesRoman, 10);

            //Creates text elements to add the address and draw it to the page.
            element       = new PdfTextElement("BILL TO ", timesRoman);
            element.Brush = new PdfSolidBrush(new PdfColor(126, 155, 203));
            result        = element.Draw(page, new PointF(10, result.Bounds.Bottom + 25));


            element       = new PdfTextElement("Name :: ", timesRoman);
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            result        = element.Draw(page, new PointF(10, result.Bounds.Bottom + 5));

            element       = new PdfTextElement(order.FirstName.ToUpper() + " " + order.LastName.ToUpper(), timesRoman);
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            result        = element.Draw(page, new PointF(result.Bounds.Left + 40, result.Bounds.Bottom - 10));


            element       = new PdfTextElement("Mob No :: ", timesRoman);
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            result        = element.Draw(page, new PointF(result.Bounds.Left + 200, result.Bounds.Bottom - 10));

            element       = new PdfTextElement(order.PhoneNumber, timesRoman);
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            result        = element.Draw(page, new PointF(result.Bounds.Left + 45, result.Bounds.Bottom - 10));


            element       = new PdfTextElement("Address :: ", timesRoman);
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            result        = element.Draw(page, new PointF(10, result.Bounds.Bottom + 5));

            element       = new PdfTextElement(order.AddressLine1 + " , " + order.AddressLine2, timesRoman);
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            result        = element.Draw(page, new PointF(result.Bounds.Left + 45, result.Bounds.Bottom - 10));


            element       = new PdfTextElement("Email Id:: ", timesRoman);
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            result        = element.Draw(page, new PointF(result.Bounds.Left + 195, result.Bounds.Bottom - 10));

            element       = new PdfTextElement(order.Email, timesRoman);
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            result        = element.Draw(page, new PointF(result.Bounds.Left + 45, result.Bounds.Bottom - 10));


            element       = new PdfTextElement(order.City + " , " + order.State + " -" + order.ZipCode, timesRoman);
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            result        = element.Draw(page, new PointF(55, result.Bounds.Bottom + 5));


            element       = new PdfTextElement(order.Country, timesRoman);
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            result        = element.Draw(page, new PointF(55, result.Bounds.Bottom + 5));



            PdfPen linePen    = new PdfPen(new PdfColor(126, 151, 173), 0.70f);
            PointF startPoint = new PointF(0, result.Bounds.Bottom + 3);
            PointF endPoint   = new PointF(graphics.ClientSize.Width, result.Bounds.Bottom + 3);

            //Draws a line at the bottom of the address
            graphics.DrawLine(linePen, startPoint, endPoint);


            DataTable dt = new DataTable();

            dt.Columns.Add("Product Code");
            dt.Columns.Add("Product Disc");
            dt.Columns.Add("Price");
            dt.Columns.Add("Discount");
            dt.Columns.Add("Discount Price");

            foreach (var p in order.OrderLines)
            {
                float discountPrice = (float)Math.Round(p.Product.Price - p.Product.Price * p.Product.Discount / 100, 2);
                dt.Rows.Add(p.Product.ProductName, p.Product.ShortDescription, "Rs. " + p.Product.Price, p.Product.Discount + " %", "Rs. " + discountPrice);
            }
            if (order.OrderType.Equals("codpayment"))
            {
                dt.Rows.Add("Shipping Charge", "", "Rs. " + ShipingCharge, "", "Rs. " + ShipingCharge);
            }

            DataTable invoiceDetails = dt;
            //Creates a PDF grid
            PdfGrid grid = new PdfGrid();

            //Adds the data source
            grid.DataSource = invoiceDetails;
            //Creates the grid cell styles
            PdfGridCellStyle cellStyle = new PdfGridCellStyle();

            cellStyle.Borders.All = PdfPens.White;
            PdfGridRow header = grid.Headers[0];
            //Creates the header style
            PdfGridCellStyle headerStyle = new PdfGridCellStyle();

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

            //Adds cell customizations
            for (int i = 0; i < header.Cells.Count; i++)
            {
                header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            }

            //Applies the header style
            header.ApplyStyle(headerStyle);

            PdfGridStyle gridStyle = new PdfGridStyle();

            gridStyle.CellPadding = new PdfPaddings(2, 2, 2, 2);

            gridStyle.CellSpacing = 1;

            grid.Style = gridStyle;

            PdfStringFormat stringFormat = new PdfStringFormat();

            stringFormat.Alignment     = PdfTextAlignment.Left + 5;
            stringFormat.LineAlignment = PdfVerticalAlignment.Middle;


            //Apply string formatting for whole table
            for (int i = 0; i < grid.Columns.Count; i++)
            {
                grid.Columns[i].Format = stringFormat;
            }


            grid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable4Accent1);
            cellStyle.Font      = new PdfStandardFont(PdfFontFamily.TimesRoman, 12f);
            cellStyle.TextBrush = new PdfSolidBrush(new PdfColor(131, 130, 136));
            //Creates the layout format for grid
            PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat();

            // Creates layout format settings to allow the table pagination
            layoutFormat.Layout = PdfLayoutType.Paginate;
            //Draws the grid to the PDF page.
            PdfGridLayoutResult gridResult = grid.Draw(page, new RectangleF(new PointF(0, result.Bounds.Bottom + 40), new SizeF(graphics.ClientSize.Width, graphics.ClientSize.Height - 100)), layoutFormat);


            element       = new PdfTextElement("Total Price:: ", timesRoman);
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            result        = element.Draw(page, new PointF(graphics.ClientSize.Width - 200, gridResult.Bounds.Bottom + 10));

            element       = new PdfTextElement("Rs. " + order.OrderTotal.ToString("0.00"), timesRoman);
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            result        = element.Draw(page, new PointF(graphics.ClientSize.Width - 140, result.Bounds.Bottom - 10));



            element       = new PdfTextElement("Total Product:: ", timesRoman);
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            result        = element.Draw(page, new PointF(graphics.ClientSize.Width - 500, gridResult.Bounds.Bottom + 10));

            element       = new PdfTextElement(order.TotalItem.ToString("0"), timesRoman);
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            result        = element.Draw(page, new PointF(graphics.ClientSize.Width - 420, result.Bounds.Bottom - 10));


            element       = new PdfTextElement("OrderDate:: ", timesRoman);
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            result        = element.Draw(page, new PointF(10, gridResult.Bounds.Bottom + 10));

            element       = new PdfTextElement(order.OrderPlacedDate.ToString("dd/MM/yyyy"), timesRoman);
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            result        = element.Draw(page, new PointF(60, result.Bounds.Bottom - 10));

            element1.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 20, PdfFontStyle.Bold);

            element1       = new PdfTextElement("Thanks,", subHeadingFont);
            element1.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            result         = element1.Draw(page, new PointF(graphics.ClientSize.Width - 130, result.Bounds.Bottom + 20));
            element1       = new PdfTextElement("Prince Digital,Surat", subHeadingFont);
            element1.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            result         = element1.Draw(page, new PointF(graphics.ClientSize.Width - 130, result.Bounds.Bottom + 1));

            MemoryStream stream = new MemoryStream();

            document.Save(stream);

            //Set the position as '0'.
            stream.Position = 0;

            //Download the PDF document in the browser
            FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf");
            string           FileName         = "order_" + order.OrderId + ".pdf";

            fileStreamResult.FileDownloadName = FileName;

            return(fileStreamResult);
        }
Exemple #23
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (_data == null || _data.Count == 0)
            {
                MessageBox.Show("Aucune donnée à exporter.", "Attention", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            string filename = string.Concat("Output_", DateTime.Now.ToString("yyyyMMddHHmmss"));

            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.FileName   = filename;           // Default file name
            dlg.DefaultExt = ".pdf";             // Default file extension
            dlg.Filter     = "PDF (.pdf)|*.pdf"; // Filter files by extension

            if (dlg.ShowDialog() != true)
            {
                return;
            }

            filename = dlg.FileName;
            try
            {
                PdfDocument doc     = new PdfDocument();
                PdfPage     page    = doc.Pages.Add();
                PdfGrid     pdfGrid = new PdfGrid();

                DataTable dataTable = new DataTable();
                dataTable.Columns.Add("Purchdoc");
                dataTable.Columns.Add("Ln Meso");
                dataTable.Columns.Add("Ln PWC");
                dataTable.Columns.Add("Material");
                dataTable.Columns.Add("Description Meso");
                dataTable.Columns.Add("SO");
                dataTable.Columns.Add("Job");
                dataTable.Columns.Add("Liv PWC");
                dataTable.Columns.Add("Shipped");
                dataTable.Columns.Add("Promised_Date");

                foreach (var line in _data)
                {
                    dataTable.Rows.Add(new object[] {
                        line.PurchaseDoc,        //Purchdoc
                        line.LnMeso,             //Ln Meso
                        line.Item,               //Ln PWC
                        line.Material,           // Material
                        line.Description,        //Description Meso
                        line.SO,                 //SO
                        line.Job,                //Job
                        line.DeliveryDateString, //LivPWC
                        line.Shipped,            //Shipped
                        line.PromisedDate        //Promised_Date
                    });
                }

                pdfGrid.DataSource = dataTable;

                pdfGrid.Columns[0].Width = 50;
                pdfGrid.Columns[1].Width = 35;
                pdfGrid.Columns[2].Width = 35;
                pdfGrid.Columns[3].Width = 50;
                pdfGrid.Columns[4].Width = 75;
                pdfGrid.Columns[5].Width = 40;
                pdfGrid.Columns[6].Width = 55;
                pdfGrid.Columns[7].Width = 50;
                pdfGrid.Columns[8].Width = 50;
                pdfGrid.Columns[9].Width = 60;

                PdfGridLayoutFormat format = new PdfGridLayoutFormat();
                format.Break          = PdfLayoutBreakType.FitPage;
                format.PaginateBounds = new RectangleF(0, 0, 400, 800);
                pdfGrid.Draw(page, new PointF(10, 30), format);

                PdfGraphics graphics = page.Graphics;
                PdfFont     font     = new PdfStandardFont(PdfFontFamily.Helvetica, 14, PdfFontStyle.Bold);
                graphics.DrawString(_data.First().CompanyName, font, PdfBrushes.Red, new PointF(10, 0));

                doc.Save(filename);
                doc.Close(true);

                System.Diagnostics.Process.Start(filename);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Concat("Erreur lors de la génération du PDF. ", ex.ToString()), "Attention", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
        }
        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);

        }
Exemple #25
0
        private async void Reprtbtn_Clicked(object sender, EventArgs e)

        {
            //Create a new PDF document.
            PdfDocument doc = new PdfDocument();
            //Add a page.
            PdfPage page = doc.Pages.Add();

            Stream      fontStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("IttezanPos.Assets.arial.ttf");
            PdfTemplate header     = PdfHelper.AddHeader(doc, "تقرير العملاء", "Ittezan Pos" + " " + DateTime.Now.ToString());

            PdfCellStyle headerStyle = new PdfCellStyle();

            headerStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);
            page.Graphics.DrawPdfTemplate(header, new PointF());

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

            //String format

            //  PdfFont pdfFont = new PdfTrueTypeFont(fontStream1, 12);

            //Create a DataTable.
            DataTable       dataTable       = new DataTable("EmpDetails");
            List <Customer> customerDetails = new List <Customer>();

            //Add columns to the DataTable
            dataTable.Columns.Add("ID");
            dataTable.Columns.Add("Name");
            dataTable.Columns.Add("Address");

            //Add rows to the DataTable.
            foreach (var item in Clients)
            {
                Customer customer = new Customer();
                customer.ID      = item.id;
                customer.Name    = item.name;
                customer.Address = item.address;
                customerDetails.Add(customer);
                dataTable.Rows.Add(new string[] { customer.ID.ToString(), customer.Name, customer.Address });
            }

            //Assign data source.
            pdfGrid.DataSource = dataTable;
            pdfGrid.Headers.Add(1);
            PdfGridRow pdfGridRowHeader = pdfGrid.Headers[0];

            pdfGridRowHeader.Cells[0].Value = "رقم العميل";
            pdfGridRowHeader.Cells[1].Value = "إسم العميل";
            pdfGridRowHeader.Cells[2].Value = "عنوان العميل";
            PdfGridStyle pdfGridStyle = new PdfGridStyle();

            pdfGridStyle.Font = new PdfTrueTypeFont(fontStream, 12);

            PdfGridLayoutFormat format1 = new PdfGridLayoutFormat();

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

            PdfStringFormat format = new PdfStringFormat();

            format.TextDirection      = PdfTextDirection.RightToLeft;
            format.Alignment          = PdfTextAlignment.Center;
            format.LineAlignment      = PdfVerticalAlignment.Middle;
            pdfGrid.Columns[0].Format = format;
            pdfGrid.Columns[1].Format = format;
            pdfGrid.Columns[2].Format = format;
            pdfGrid.Style             = pdfGridStyle;
            //Draw grid to the page of PDF document.
            pdfGrid.Draw(page, new Syncfusion.Drawing.Point(0, (int)header.Height + 10), format1);
            MemoryStream stream = new MemoryStream();

            //Save the document.
            doc.Save(stream);
            //close the document
            doc.Close(true);
            await Xamarin.Forms.DependencyService.Get <ISave>().SaveAndView("تقرير العملاء.pdf", "application/pdf", stream);
        }
Exemple #26
0
        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);
        }
        private async void Button_Clicked(object sender, EventArgs e)
        {
            //Create a new PDF document.
            PdfDocument doc = new PdfDocument();
            //Add a page.
            PdfPage page = doc.Pages.Add();

            Stream      fontStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("IttezanPos.Assets.arial.ttf");
            PdfTemplate header     = PdfHelper.AddHeader(doc, "الأرصدة الإفتتاحية", "Ittezan Pos" + " " + DateTime.Now.ToString());

            PdfCellStyle headerStyle = new PdfCellStyle();

            headerStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);
            page.Graphics.DrawPdfTemplate(header, new PointF());

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

            //String format

            //  PdfFont pdfFont = new PdfTrueTypeFont(fontStream1, 12);

            //Create a DataTable.
            DataTable dataTable = new DataTable("EmpDetails");
            List <SuplierTotalAmount> customerDetails = new List <SuplierTotalAmount>();

            //Add columns to the DataTable
            dataTable.Columns.Add("ID");
            dataTable.Columns.Add("Name");
            dataTable.Columns.Add("Address");
            dataTable.Columns.Add("Total");

            //Add rows to the DataTable.
            foreach (var item in suppliers)
            {
                SuplierTotalAmount customer = new SuplierTotalAmount();
                customer.name         = item.name;
                customer.remaining    = item.remaining;
                customer.creditorit   = item.creditorit;
                customer.total_amount = item.total_amount;
                customerDetails.Add(customer);
                dataTable.Rows.Add(new string[] { customer.total_amount.ToString(), customer.remaining.ToString(), customer.creditorit.ToString(), customer.name });
            }

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

            pdfGrid.Headers.Add(1);
            PdfGridRow pdfGridRowHeader = pdfGrid.Headers[0];

            pdfGridRowHeader.Cells[3].Value = "الإسم";
            pdfGridRowHeader.Cells[2].Value = "المبلغ دائن/ له";
            pdfGridRowHeader.Cells[1].Value = "المبلغ المدين / عليه";
            pdfGridRowHeader.Cells[0].Value = "الرصيد";
            PdfGridStyle pdfGridStyle = new PdfGridStyle();

            pdfGridStyle.Font = new PdfTrueTypeFont(fontStream, 12);

            PdfGridLayoutFormat format1 = new PdfGridLayoutFormat();

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

            PdfStringFormat format = new PdfStringFormat();

            format.TextDirection = PdfTextDirection.RightToLeft;
            format.Alignment     = PdfTextAlignment.Center;
            format.LineAlignment = PdfVerticalAlignment.Middle;

            pdfGrid.Columns[0].Format = format;
            pdfGrid.Columns[1].Format = format;
            pdfGrid.Columns[2].Format = format;
            pdfGrid.Columns[3].Format = format;
            pdfGrid.Style             = pdfGridStyle;
            //Draw grid to the page of PDF document.
            pdfGrid.Draw(page, new Syncfusion.Drawing.Point(0, (int)header.Height + 10), format1);
            MemoryStream stream = new MemoryStream();

            //Save the document.
            doc.Save(stream);
            //close the document
            doc.Close(true);
            await Xamarin.Forms.DependencyService.Get <ISave>().SaveAndView("الأرصدة الإفتتاحية .pdf", "application/pdf", stream);
        }
Exemple #28
0
        protected void btnDownload_Click(object sender, EventArgs e)
        {
            using (PdfDocument document = new PdfDocument())
            {
                PdfPage     page     = document.Pages.Add();
                PdfGraphics graphics = page.Graphics;

                //Drawing the logo image on the top
                PdfBitmap image = new PdfBitmap(Server.MapPath("~/Images/Logo.jpg"));
                graphics.DrawImage(image, 110, 0, 300, 100);

                //Drawing a rectangle below the logo in Coral color
                RectangleF bounds = new RectangleF(0, 100, graphics.ClientSize.Width, 30);
                PdfBrush   brush  = new PdfSolidBrush(new PdfColor(Color.Coral));
                graphics.DrawRectangle(brush, bounds);

                //Loading data from Database into DataSet by calling the GetInvoiceDetails method
                ds = GetInvoiceDetails(ddlInvoice.SelectedValue);

                //Creating PdfTextElement objects and placing them on the document
                PdfFont        textFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 14);
                PdfTextElement element  = new PdfTextElement("INVOICE ID: " + ddlInvoice.SelectedValue, textFont);
                element.Brush = PdfBrushes.White;
                PdfLayoutResult result = element.Draw(page, new PointF(10, bounds.Top + 8));

                string invoiceDate = "INVOICE DATE: " + ds.Tables[0].Rows[0][0];
                SizeF  textSize    = textFont.MeasureString(invoiceDate);
                element       = new PdfTextElement(invoiceDate, textFont);
                element.Brush = PdfBrushes.White;
                result        = element.Draw(page, bounds.Width - textSize.Width - 10, bounds.Top + 8);

                element       = new PdfTextElement("BILL TO:", textFont);
                element.Brush = PdfBrushes.Blue;
                result        = element.Draw(page, 10, result.Bounds.Bottom + 20);

                //byte[] imageData = (byte[])ds.Tables[1].Rows[0][3];
                //MemoryStream ms = new MemoryStream(imageData);
                //PdfBitmap customerImage = new PdfBitmap(ms);
                //graphics.DrawImage(customerImage, 410, result.Bounds.Bottom - 14, 100, 100);

                element = new PdfTextElement(ds.Tables[1].Rows[0][0].ToString(), textFont);
                result  = element.Draw(page, 15, result.Bounds.Bottom);
                element = new PdfTextElement(ds.Tables[1].Rows[0][1].ToString(), textFont);
                result  = element.Draw(page, 15, result.Bounds.Bottom);
                element = new PdfTextElement(ds.Tables[1].Rows[0][2].ToString(), textFont);
                result  = element.Draw(page, 15, result.Bounds.Bottom);

                PdfPen linePen    = new PdfPen(new PdfColor(Color.Coral), 0.75f);
                PointF startPoint = new PointF(0, result.Bounds.Bottom + 50);
                PointF endPoint   = new PointF(graphics.ClientSize.Width, result.Bounds.Bottom + 50);
                graphics.DrawLine(linePen, startPoint, endPoint);
                DataTable invoiceDetails = ds.Tables[2];
                PdfGrid   grid           = new PdfGrid();
                grid.DataSource = invoiceDetails;

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

                PdfGridRow header = grid.Headers[0];
                for (int i = 0; i < header.Cells.Count; i++)
                {
                    header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                }
                header.ApplyStyle(headerStyle);

                PdfGridColumnCollection columns = grid.Columns;
                columns[2].Format.Alignment = PdfTextAlignment.Right;
                columns[3].Format.Alignment = PdfTextAlignment.Right;
                columns[4].Format.Alignment = PdfTextAlignment.Right;

                PdfGridStyle cellStyle = new PdfGridStyle();
                cellStyle.Font      = new PdfStandardFont(PdfFontFamily.TimesRoman, 12f, PdfFontStyle.Regular);
                cellStyle.TextBrush = PdfBrushes.DarkGreen;
                grid.Style          = cellStyle;

                PdfGridLayoutResult gridResult = grid.Draw(page, new RectangleF(new PointF(0, result.Bounds.Bottom + 60),
                                                                                new SizeF(graphics.ClientSize.Width, graphics.ClientSize.Height - 100)));
                linePen    = new PdfPen(new PdfColor(Color.Coral), 0.75f);
                startPoint = new PointF((gridResult.Bounds.Width / 5) * 4, gridResult.Bounds.Bottom + 20);
                endPoint   = new PointF(graphics.ClientSize.Width, gridResult.Bounds.Bottom + 20);
                graphics.DrawLine(linePen, startPoint, endPoint);

                element = new PdfTextElement("TotalBill:", textFont);
                result  = element.Draw(page, new PointF((gridResult.Bounds.Width / 5) * 3, gridResult.Bounds.Bottom + 25));

                string billAmount = ds.Tables[3].Rows[0][0].ToString();
                textSize = textFont.MeasureString(billAmount);
                element  = new PdfTextElement(billAmount, textFont);
                result   = element.Draw(page, new PointF(graphics.ClientSize.Width - textSize.Width, gridResult.Bounds.Bottom + 25));

                linePen    = new PdfPen(new PdfColor(Color.Coral), 0.75f);
                startPoint = new PointF((gridResult.Bounds.Width / 5) * 4, gridResult.Bounds.Bottom + 45);
                endPoint   = new PointF(graphics.ClientSize.Width, gridResult.Bounds.Bottom + 45);
                graphics.DrawLine(linePen, startPoint, endPoint);
                string signature = "Signature";
                textSize = textFont.MeasureString(signature);
                element  = new PdfTextElement(signature, textFont);
                result   = element.Draw(page, new PointF(graphics.ClientSize.Width - textSize.Width - 20,
                                                         gridResult.Bounds.Bottom + 100));

                linePen    = new PdfPen(new PdfColor(Color.Coral), 0.75f);
                startPoint = new PointF(0, graphics.ClientSize.Height - 25);
                endPoint   = new PointF(graphics.ClientSize.Width, graphics.ClientSize.Height - 25);
                graphics.DrawLine(linePen, startPoint, endPoint);

                graphics.DrawString("13-74/292, Diamond Towers, Jubliee Hills - 33. Phone: 2381 9999, Fax: 2381 8899",
                                    new PdfStandardFont(PdfFontFamily.Courier, 10), PdfBrushes.DarkCyan,
                                    new PointF(0, graphics.ClientSize.Height - 20));

                graphics.DrawString("Email: [email protected], WebSite: www.paintcompany.com",
                                    new PdfStandardFont(PdfFontFamily.Courier, 10), PdfBrushes.DarkCyan,
                                    new PointF(0, graphics.ClientSize.Height - 10));

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

                document.Save("Invoice.pdf", HttpContext.Current.Response, HttpReadType.Save);
            };
        }