Exemplo n.º 1
0
        /// <summary>
        /// Add content in table of content and return the layout result.
        /// </summary>
        PdfLayoutResult AddTableOfContents(PdfPage page, string text, RectangleF bounds, bool isTitle, int pageNo, float x, float y, PdfPage destPage)
        {
            //Set font style.
            PdfFontStyle style = isTitle ? PdfFontStyle.Bold : PdfFontStyle.Regular;
            //Create a font and draw the text to PDF page.
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 13, style);

            page.Graphics.DrawString(pageNo.ToString(), font, PdfBrushes.Black, new RectangleF(480, bounds.Top + 5, bounds.Width, bounds.Height));
            //Create a pdf destination for document link annotation.
            PdfDestination pdfDestination   = new PdfDestination(destPage, new PointF(x, y));
            RectangleF     annotationBounds = RectangleF.Empty;

            if (isTitle)
            {
                annotationBounds = new RectangleF(bounds.Left, bounds.Top - 45, bounds.Width, font.Height);
            }
            else
            {
                annotationBounds = new RectangleF(bounds.Left + 20, bounds.Top - 45, bounds.Width - 20, font.Height);
            }
            //Create document link annotation with bounds.
            PdfDocumentLinkAnnotation annotation = new PdfDocumentLinkAnnotation(annotationBounds, pdfDestination);

            annotation.Border.Width = 0;
            //Add annotation to PDF page.
            page.Annotations.Add(annotation);

            //Measure the text size to draw in PDF page.
            string str   = text + ' ';
            float  width = isTitle ? font.MeasureString(text).Width + 20 : font.MeasureString(text).Width + 40;

            for (float i = width; i < 470;)
            {
                str = str + '.';
                i   = i + 3.6140000000000003F;
            }

            //Create text element and draw it to PDF page.
            PdfTextElement element = new PdfTextElement(str, font, PdfBrushes.Black);

            if (isTitle)
            {
                bounds = new RectangleF(bounds.Left, bounds.Top + 5, bounds.Width, bounds.Height);
            }
            else
            {
                bounds = new RectangleF(bounds.Left + 20, bounds.Top + 5, bounds.Width, bounds.Height);
            }

            return(element.Draw(page, bounds));
        }
Exemplo n.º 2
0
        void OnButtonClicked(object sender, EventArgs e)
        {
            Stream            docStream = typeof(Stamping).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Assets.Product Catalog.pdf");
            PdfLoadedDocument ldoc      = new PdfLoadedDocument(docStream);

            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 100f, PdfFontStyle.Regular);

            foreach (PdfPageBase lPage in ldoc.Pages)
            {
                PdfGraphics      g     = lPage.Graphics;
                PdfGraphicsState state = g.Save();
                g.TranslateTransform(ldoc.Pages[0].Size.Width / 2, ldoc.Pages[0].Size.Height / 2);
                g.SetTransparency(0.25f);
                SizeF waterMarkSize = font.MeasureString("Sample");
                g.RotateTransform(-40);
                g.DrawString("Sample", font, PdfPens.Red, PdfBrushes.Red, new PointF(-waterMarkSize.Width / 2, -waterMarkSize.Height / 2));
                g.Restore(state);
            }
            MemoryStream stream = new MemoryStream();

            ldoc.Save(stream);
            ldoc.Close(true);

            if (stream != null)
            {
                SaveAndroid androidSave = new SaveAndroid();
                androidSave.Save("Stamping.pdf", "application/pdf", stream, m_context);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds footer to the document
        /// </summary>
        /// <param name="width"></param>
        /// <param name="footerText"></param>
        private PdfPageTemplateElement AddFooter(float width, string footerText)
        {
            RectangleF rect = new RectangleF(0, 0, width, 50);
            //Create a new instance of PdfPageTemplateElement class.
            PdfPageTemplateElement footer = new PdfPageTemplateElement(rect);
            PdfGraphics            g      = footer.Graphics;

            // Draw footer text.
            PdfSolidBrush brush = new PdfSolidBrush(Color.Gray);
            PdfFont       font  = new PdfStandardFont(PdfFontFamily.Helvetica, 6, PdfFontStyle.Bold);
            float         x     = (width / 2) - (font.MeasureString(footerText).Width) / 2;

            g.DrawString(footerText, font, brush, new RectangleF(x, g.ClientSize.Height - 10, font.MeasureString(footerText).Width, font.Height));

            //Create page number field
            PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush);

            //Create page count field
            PdfPageCountField count = new PdfPageCountField(font, brush);

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

            compositeField.Bounds = footer.Bounds;
            compositeField.Draw(g, new PointF(470, 40));

            return(footer);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds header to the document
        /// </summary>
        /// <param name="width"></param>
        /// <param name="title"></param>
        /// <param name="description"></param>
        private PdfPageTemplateElement AddHeader(float width, string title, string description)
        {
            RectangleF rect = new RectangleF(0, 0, width, 50);
            //Create a new instance of PdfPageTemplateElement class.
            PdfPageTemplateElement header = new PdfPageTemplateElement(rect);
            PdfGraphics            g      = header.Graphics;

            //Draw title.
            PdfFont       font  = new PdfStandardFont(PdfFontFamily.Helvetica, 16, PdfFontStyle.Bold);
            PdfSolidBrush brush = new PdfSolidBrush(Color.FromArgb(44, 71, 120));
            float         x     = (width / 2) - (font.MeasureString(title).Width) / 2;

            g.DrawString(title, font, brush, new RectangleF(x, (rect.Height / 4) + 3, font.MeasureString(title).Width, font.Height));

            //Draw description
            brush = new PdfSolidBrush(Color.Gray);
            font  = new PdfStandardFont(PdfFontFamily.Helvetica, 16, PdfFontStyle.Bold);
            PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Bottom);

            g.DrawString(description, font, brush, new RectangleF(0, 0, header.Width, header.Height - 8), format);

            //Draw some lines in the header
            PdfPen pen = new PdfPen(Color.DarkBlue, 0.7f);

            g.DrawLine(pen, 0, 0, header.Width, 0);
            pen = new PdfPen(Color.DarkBlue, 2f);
            g.DrawLine(pen, 0, 03, header.Width + 3, 03);
            pen = new PdfPen(Color.DarkBlue, 2f);
            g.DrawLine(pen, 0, header.Height - 3, header.Width, header.Height - 3);
            g.DrawLine(pen, 0, header.Height, header.Width, header.Height);

            return(header);
        }
Exemplo n.º 5
0
        private void AddFooters([NotNull] PdfDocument doc, [NotNull] PdfStandardFont font)
        {
            var pages = doc.Pages.OfType <PdfPage>().ToArray();

            var textSize = font.MeasureString(_model.Name);

            int i = 1;

            foreach (var page in pages)
            {
                var y = page.Graphics.ClientSize.Height - textSize.Height - 5;
                page.Graphics.DrawLine(PdfPens.Black, 0, y, page.Graphics.ClientSize.Width, y);
                WriteText(page, _model.Name, font, 0, y + 5);
                WriteText(page, $"Page {i}", font, 0, y + 5, null, true);
                i++;
            }
        }
Exemplo n.º 6
0
        void OnButtonClicked(object sender, EventArgs e)
        {
            //Load PDF document to stream.
#if COMMONSB
            Stream docStream = typeof(Stamping).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Samples.Assets.Product Catalog.pdf");
#else
            Stream docStream = typeof(Stamping).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.PDF.Samples.Assets.Product Catalog.pdf");
#endif

            //Load the PDF document into the loaded document object.
            PdfLoadedDocument ldoc = new PdfLoadedDocument(docStream);

            //Create font object.
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 100f, PdfFontStyle.Regular);

            //Stamp or watermark on all the pages.
            foreach (PdfPageBase lPage in ldoc.Pages)
            {
                PdfGraphics      g     = lPage.Graphics;
                PdfGraphicsState state = g.Save();
                g.TranslateTransform(ldoc.Pages[0].Size.Width / 2, ldoc.Pages[0].Size.Height / 2);
                g.SetTransparency(0.25f);
                SizeF waterMarkSize = font.MeasureString("Sample");
                g.RotateTransform(-40);
                g.DrawString("Sample", font, PdfPens.Red, PdfBrushes.Red, new PointF(-waterMarkSize.Width / 2, -waterMarkSize.Height / 2));
                g.Restore(state);
            }
            MemoryStream stream = new MemoryStream();

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

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

            //Open in default system viewer.
            if (Device.RuntimePlatform == Device.UWP)
            {
                Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("Stamping.pdf", "application/pdf", stream);
            }
            else
            {
                Xamarin.Forms.DependencyService.Get <ISave>().Save("Stamping.pdf", "application/pdf", stream);
            }
        }
Exemplo n.º 7
0
        private bool GeneratePdf([Required] string fileName)
        {
            using (var doc = new PdfDocument(PdfConformanceLevel.None))
            {
                doc.PageSettings.Orientation = PdfPageOrientation.Portrait;
                var page = doc.Pages.Add();
                var y    = AddPdfHeader(page);

                var font    = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
                var minSize = font.MeasureString("Ag");
                _minTextHeight = minSize.Height;
                var healthIndex = _analyzersManager.Analyze(_model,
                                                            QualityPropertySchemaManager.IsFalsePositive,
                                                            out var outcomes);
                AddSummary(doc, page, y + 10, font, healthIndex, outcomes);

                var analyzers = QualityAnalyzersManager.QualityAnalyzers?.ToArray();
                if (analyzers?.Any() ?? false)
                {
                    foreach (var analyzer in analyzers)
                    {
                        var outcome = outcomes?.FirstOrDefault(x => x.Id == analyzer.GetExtensionId());
                        if (outcome != null)
                        {
                            AddOutcomePage(doc, font, analyzer, outcome);
                        }
                    }
                }

                var schemaManager = new AnnotationsPropertySchemaManager(_model);
                var propertyType  = schemaManager.GetAnnotationsPropertyType();
                var containers    = GetContainers(schemaManager, propertyType)?.ToArray();
                if (containers?.Any() ?? false)
                {
                    AddReviewNotesPage(doc, font, containers, schemaManager, propertyType);
                }

                AddFooters(doc, font);

                doc.Save(fileName);
            }

            return(true);
        }
Exemplo n.º 8
0
        private SizeF WriteText([NotNull] PdfPage page, [Required] string text,
                                PdfStandardFont font, float x, float y, PdfBrush brush = null,
                                bool alignRight = false, float maxWidth = 0, bool wordWrap = true)
        {
            if (maxWidth == 0)
            {
                maxWidth = page.Graphics.ClientSize.Width;
            }
            var format = new PdfStringFormat();

            if (wordWrap)
            {
                format.WordWrap = PdfWordWrapType.Word;
            }
            else
            {
                format.WordWrap = PdfWordWrapType.None;
            }

            var result = font.MeasureString(text, maxWidth, format);

            float newX;

            if (alignRight)
            {
                newX = page.Graphics.ClientSize.Width - result.Width - x;
            }
            else
            {
                newX = x;
            }

            page.Graphics.DrawString(text, font, brush ?? PdfBrushes.Black,
                                     new RectangleF(newX, y, result.Width, result.Height), format);

            if (result.Height < _minTextHeight)
            {
                result.Height = _minTextHeight;
            }

            return(result);
        }
Exemplo n.º 9
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");
        }
Exemplo n.º 10
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        //protected override void OnNavigatedTo(NavigationEventArgs e)
        //{
        //}

        private async void GeneratePDF_Click(object sender, RoutedEventArgs e)
        {
            Stream   image1     = typeof(ImageInsertion).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.AutoTag.jpg");
            Stream   image2     = typeof(ImageInsertion).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.autotagSmall.jpg");
            PdfColor blackColor = new PdfColor(System.Drawing.Color.FromArgb(255, 0, 0, 0));


            #region content string
            string toc      = "\r\n What can I do with C#? ..................................................................................................................................... 3 \r\n \r\n What is .NET? .................................................................................................................................................... 3 \r\n \r\n Writing, Running, and Deploying a C# Program .............................................................................................. 3 \r\n \r\n Starting a New Program..................................................................................................................................... 3";
            string Csharp   = "Welcome to C# Succinctly. True to the Succinctly series concept, this book is very focused on a single topic: the C# programming language. I might briefly mention some technologies that you can write with C# or explain how a feature fits into those technologies, but the whole of this book is about helping you become familiar with C# syntax. \r\n \r\n In this chapter, Ill start with some introductory information and then jump straight into a simple C# program.";
            string whatToD0 = "C# is a general purpose, object-oriented, component-based programming language. As a general purpose language, you have a number of ways to apply C# to accomplish many different tasks. You can build web applications with ASP.NET, desktop applications with Windows Presentation Foundation (WPF), or build mobile applications for Windows Phone. Other applications include code that runs in the cloud via Windows Azure, and iOS, Android, and Windows Phone support with the Xamarin platform. There might be times when you need a different language, like C or C++, to communicate with hardware or real-time systems. However, from a general programming perspective, you can do a lot with C#.";
            string dotnet   = "The runtime is more formally named the Common Language Runtime (CLR). Programming languages that target the CLR compile to an Intermediate Language (IL). The CLR itself is a virtual machine that runs IL and provides many services such as memory management, garbage collection, exception management, security, and more.\r\n \r\n The Framework Class Library (FCL) is a set of reusable code that provides both general services and technology-specific platforms. The general services include essential types such as collections, cryptography, networking, and more. In addition to general classes, the FCL includes technology-specific platforms like ASP.NET, WPF, web services, and more. The value the FCL offers is to have common components available for reuse, saving time and money without needing to write that code yourself. \r\n \r\n There is a huge ecosystem of open-source and commercial software that relies on and supports .NET. If you visit CodePlex, GitHub, or any other open-source code repository site, you will see a multitude of projects written in C#. Commercial offerings include tools and services that help you build code, manage systems, and offer applications. Syncfusion is part of this ecosystem, offering reusable components for many of the .NET technologies I have mentioned.";
            string prog     = "The previous section described plenty of great things you can do with C#, but most of them are so detailed that they require their own book. To stay focused on the C# programming language, the code in this book will be for the console application. A console application runs on the command line, which you will learn about in this section. You can write your code with any editor, but this book uses Visual Studio.";

            #endregion

            //Create a new PDF document.

            PdfDocument document = new PdfDocument();

            //Auto Tag the document

            document.AutoTag = true;
            document.DocumentInformation.Title = "AutoTag";
            #region page1
            //Add a page to the document.

            PdfPage page1 = document.Pages.Add();

            //Load the image from the disk.

            PdfBitmap image = new PdfBitmap(image1);

            //Draw the image

            page1.Graphics.DrawImage(image, 0, 0, page1.GetClientSize().Width, page1.GetClientSize().Height - 20);

            #endregion

            #region page2
            PdfPage page2 = document.Pages.Add();

            PdfFont fontnormal = new PdfStandardFont(PdfFontFamily.TimesRoman, 10);
            PdfFont fontTitle  = new PdfStandardFont(PdfFontFamily.TimesRoman, 22, PdfFontStyle.Bold);
            PdfFont fontHead   = new PdfStandardFont(PdfFontFamily.TimesRoman, 10, PdfFontStyle.Bold);
            PdfFont fontHead2  = new PdfStandardFont(PdfFontFamily.TimesRoman, 16, PdfFontStyle.Bold);

            page2.Graphics.DrawString("Table of Contents", fontTitle, PdfBrushes.Black, new PointF(300, 0));
            page2.Graphics.DrawLine(new PdfPen(PdfBrushes.Black, 0.5f), new PointF(0, 40), new PointF(page2.GetClientSize().Width, 40));

            page2.Graphics.DrawString("Chapter 1 Introducing C# and .NET .............................................................................................................. 3 \r\n ", fontHead, PdfBrushes.Black, new PointF(0, 60));
            page2.Graphics.DrawString(toc, fontnormal, PdfBrushes.Black, new PointF(0, 80));

            #endregion

            #region page3

            PdfPage page3 = document.Pages.Add();

            page3.Graphics.DrawString("C# Succinctly", new PdfStandardFont(PdfFontFamily.TimesRoman, 32, PdfFontStyle.Bold), PdfBrushes.Black, new PointF(160, 0));

            page3.Graphics.DrawLine(PdfPens.Black, new PointF(0, 40), new PointF(page3.GetClientSize().Width, 40));

            page3.Graphics.DrawString("Chapter 1 Introducing C# and .NET", fontTitle, PdfBrushes.Black, new PointF(160, 60));


            PdfTextElement element1 = new PdfTextElement(Csharp, fontnormal);
            element1.Brush = new PdfSolidBrush(blackColor);
            element1.Draw(page3, new RectangleF(0, 100, page3.GetClientSize().Width, 80));

            page3.Graphics.DrawString("What can I do with C#?", fontHead2, PdfBrushes.Black, new PointF(0, 180));
            PdfTextElement element2 = new PdfTextElement(whatToD0, fontnormal);
            element2.Brush = new PdfSolidBrush(blackColor);
            element2.Draw(page3, new RectangleF(0, 210, page3.GetClientSize().Width, 80));


            page3.Graphics.DrawString("What is .Net", fontHead2, PdfBrushes.Black, new PointF(0, 300));
            PdfTextElement element3 = new PdfTextElement(dotnet, fontnormal);
            element3.Brush = new PdfSolidBrush(blackColor);
            element3.Draw(page3, new RectangleF(0, 330, page3.GetClientSize().Width, 180));


            page3.Graphics.DrawString("Writing, Running, and Deploying a C# Program", fontHead2, PdfBrushes.Black, new PointF(0, 520));
            PdfTextElement element4 = new PdfTextElement(prog, fontnormal);
            element4.Brush = new PdfSolidBrush(blackColor);
            element4.Draw(page3, new RectangleF(0, 550, page3.GetClientSize().Width, 60));

            PdfBitmap img = new PdfBitmap(image2);
            page3.Graphics.DrawImage(img, new PointF(0, 630));
            page3.Graphics.DrawString("Note: The code samples in this book can be downloaded at", fontnormal, PdfBrushes.DarkBlue, new PointF(20, 630));
            page3.Graphics.DrawString("https://bitbucket.org/syncfusiontech/c-succinctly", fontnormal, PdfBrushes.Blue, new PointF(20, 640));
            SizeF      linkSize  = fontnormal.MeasureString("https://bitbucket.org/syncfusiontech/c-succinctly");
            RectangleF rectangle = new RectangleF(20, 640, linkSize.Width, linkSize.Height);

            //Creates a new Uri Annotation

            PdfUriAnnotation uriAnnotation = new PdfUriAnnotation(rectangle, "https://bitbucket.org/syncfusiontech/c-succinctly");
            uriAnnotation.Color = new PdfColor(255, 255, 255);
            //Adds this annotation to a new page
            page3.Annotations.Add(uriAnnotation);

            #endregion



            //Save the document and dispose it.

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

            document.Close(true);
            Save(stream, "AutotagSample.pdf");
        }
Exemplo n.º 11
0
        /// <summary>
        /// Draws the viewmodel on a pdf page.
        /// </summary>
        /// <param name="drawnItems"></param>
        /// <param name="widthHeightRatio"></param>
        public void DrawSingleOntoPage(PdfPage page, KeyValuePair <AnalysableImageViewModel, ExportReportAsPdfArguments> exportableVmToArgs)
        {
            // Setup data.
            var viewModel  = exportableVmToArgs.Key;
            var drawnItems = new List <FrameworkElement>();

            foreach (var o in exportableVmToArgs.Value.DrawnObjects)
            {
                if (o is FrameworkElement el)
                {
                    drawnItems.Add(el);
                }
            }
            var widthHeightRatio = exportableVmToArgs.Value.WidthHeightRatio;

            // Then draw the items onto the image.
            var analysedImage = BitmapHelper.DrawFrameworkElementsOntoBitmap(
                drawnItems,
                BitmapHelper.BitmapImage2Bitmap(viewModel.CleanImageCopy),
                widthHeightRatio.Item1,
                widthHeightRatio.Item2);

            // Draw Image ============================================================================================================
            #region Setup and draw image
            //Create PDF graphics for a page
            PdfGraphics graphics = page.Graphics;

            // Draw name of the image.
            var subheaderFont     = new PdfStandardFont(PdfFontFamily.Courier, 14);
            var subheader         = viewModel.ImageName;
            var subheaderFontSize = subheaderFont.MeasureString(subheader);
            graphics.DrawString(subheader, subheaderFont, PdfBrushes.Black, new PointF(260 - subheaderFontSize.Width / 2, 0));

            //Draw the analysed image
            PdfBitmap pdfImage = new PdfBitmap(analysedImage);
            // Scale the picture right so its not uneven
            double widthHeightRate = (double)analysedImage.Width / (double)analysedImage.Height;
            float  height          = (float)(520 / widthHeightRate); // +10 because of the title we draw before it.
            graphics.DrawImage(pdfImage, 0, 20, 520, (int)height);   // max width of pdf: 520! Adjust the height accordingly.
            height += 20;
            #endregion

            // Draw Comments =========================================================================================================
            #region Draw comments
            // Draw the comments ====================================================================================
            // table
            var pdfGrid   = new PdfGrid();
            var dataTable = new DataTable();
            dataTable.Columns.Add("Comments");

            foreach (var comment in viewModel.Comments)
            {
                dataTable.Rows.Add(comment);
            }

            pdfGrid.DataSource       = dataTable;
            pdfGrid.Headers[0].Style = new PdfGridCellStyle()
            {
                BackgroundBrush = PdfBrushes.LightBlue
            };
            pdfGrid.Style.Font = new PdfStandardFont(PdfFontFamily.Courier, 10);

            // pdfGridLayout contains x,y,widht and height coordiantes of the drawn datatable!
            var pdfGridLayout = pdfGrid.Draw(page, new PointF(0, height + 10));
            height += pdfGridLayout.Bounds.Height;
            #endregion

            //Draw the metadata as a table ===========================================================================================
            #region Draw metadata
            // title first
            subheaderFont     = new PdfStandardFont(PdfFontFamily.Courier, 14);
            subheader         = "Metadata";
            subheaderFontSize = subheaderFont.MeasureString(subheader);
            height           += 10;
            graphics.DrawString(subheader, subheaderFont, PdfBrushes.Black, new PointF(260 - subheaderFontSize.Width / 2, height));

            // then table
            pdfGrid   = new PdfGrid();
            dataTable = new DataTable();
            dataTable.Columns.Add("Name");
            dataTable.Columns.Add("Value");

            foreach (var pair in viewModel.Metadata)
            {
                dataTable.Rows.Add(pair.Key, pair.Value);
            }

            pdfGrid.DataSource       = dataTable;
            pdfGrid.Headers[0].Style = new PdfGridCellStyle()
            {
                BackgroundBrush = PdfBrushes.LightBlue
            };
            pdfGrid.Style.Font = new PdfStandardFont(PdfFontFamily.Courier, 10);

            // Keep track of the currently used height
            height += subheaderFontSize.Height + 10;
            // pdfGridLayout contains x,y,widht and height coordiantes of the drawn datatable!
            pdfGridLayout = pdfGrid.Draw(page, new PointF(0, height));
            #endregion

            //Draw the additonal information as a table ==============================================================================
            #region Draw Additional Information
            // title
            var pdfTextElement = new PdfTextElement("Additonal Information", new PdfStandardFont(PdfFontFamily.Courier, 14));
            subheaderFontSize = subheaderFont.MeasureString(pdfTextElement.Text);
            pdfTextElement.Draw(pdfGridLayout.Page, new PointF(260 - subheaderFontSize.Width / 2, pdfGridLayout.Bounds.Height + 10));

            dataTable = new DataTable();
            dataTable.Columns.Add("Name");
            dataTable.Columns.Add("Value");
            foreach (var tuple in viewModel.AdditionalInformation)
            {
                dataTable.Rows.Add(tuple.Item1, tuple.Item2);
            }

            pdfGrid.DataSource       = dataTable;
            pdfGrid.Headers[0].Style = new PdfGridCellStyle()
            {
                BackgroundBrush = PdfBrushes.LightBlue
            };
            // Keep track of the currently used height
            pdfGridLayout = pdfGrid.Draw(pdfGridLayout.Page, new PointF(0, pdfGridLayout.Bounds.Height + 30));
            #endregion
        }
Exemplo n.º 12
0
        private void CreatePdf(RapportVragenlijstVM answerlist)
        {
            Guid   mySerialNumber = Guid.NewGuid();
            string pdfName        = mySerialNumber + ".pdf";

            using (PdfDocument document = new PdfDocument())
            {
                //Add a page to the document
                PdfPage frontPage        = document.Pages.Add();
                PdfPage questionlistPage = document.Pages.Add();

                //Create PDF graphics for a page
                PdfGraphics graphics = frontPage.Graphics;
                //Set the standard font
                PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
                //Brush
                PdfBrush solidBrush = new PdfSolidBrush(new PdfColor(126, 151, 173));

                //Image
                try
                {
                    string    path        = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
                    string    correctPath = path.Substring(0, path.Length - 10) + "\\resources\\images\\festispec.png";
                    PdfBitmap image       = new PdfBitmap(correctPath);
                    graphics.DrawRectangle(solidBrush, new RectangleF(7, 00, 500, 80));
                    graphics.DrawImage(image, new RectangleF(7, 00, 500, 80));
                }
                catch (Exception e)
                {
                }

                //Show header information
                PdfGrid         table  = new PdfGrid();
                PdfLayoutResult result = table.Draw(frontPage, new PointF(0, 0));
                solidBrush = new PdfSolidBrush(new PdfColor(126, 151, 173));
                RectangleF bounds = new RectangleF(0, result.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);
                PdfTextElement element        = new PdfTextElement("Rapport: " + SelectedInspectie.Inspecteur.Naam + " " + SelectedInspectie.Inspecteur.Achternaam, subHeadingFont);
                element.Brush = PdfBrushes.White;

                //Draws the heading on the page
                result = element.Draw(frontPage, new PointF(10, result.Bounds.Bottom + 98));
                string currentDate = "DATUM: " + 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, PdfFontStyle.Bold);
                //Creates text elements to add the address and draw it to the page.
                element       = new PdfTextElement("ID: " + SelectedInspectie.Inspecteur.Id, timesRoman);
                element.Brush = new PdfSolidBrush(new PdfColor(126, 155, 203));
                result        = element.Draw(frontPage, new PointF(10, result.Bounds.Bottom + 12));
                element       = new PdfTextElement("Mail: " + SelectedInspectie.Inspecteur.Email, timesRoman);
                element.Brush = new PdfSolidBrush(new PdfColor(126, 155, 203));
                result        = element.Draw(frontPage, new PointF(10, result.Bounds.Bottom + 8));
                element       = new PdfTextElement("Telefoonnummer: " + SelectedInspectie.Inspecteur.Telefoonnummer, timesRoman);
                element.Brush = new PdfSolidBrush(new PdfColor(126, 155, 203));
                result        = element.Draw(frontPage, new PointF(10, result.Bounds.Bottom + 8));

                DrawLine(frontPage, result);

                element       = new PdfTextElement("Bedrijf: " + SelectedInspectie.CustomerName, timesRoman);
                element.Brush = new PdfSolidBrush(new PdfColor(126, 155, 203));
                result        = element.Draw(frontPage, new PointF(10, result.Bounds.Bottom + 12));
                element       = new PdfTextElement("Uitgevoerd op: " + SelectedInspectie.InspectieDatum, timesRoman);
                element.Brush = new PdfSolidBrush(new PdfColor(126, 155, 203));
                result        = element.Draw(frontPage, new PointF(10, result.Bounds.Bottom + 8));

                bounds = new RectangleF(0, result.Bounds.Bottom + 10, frontPage.Graphics.ClientSize.Width, 30);
                frontPage.Graphics.DrawRectangle(new PdfSolidBrush(new PdfColor(126, 151, 173)), bounds);

                //QuestionList options
                //Show header information
                PdfGrid         layout       = new PdfGrid();
                PdfLayoutResult afterResult  = table.Draw(questionlistPage, new PointF(0, 0));
                RectangleF      secondBounds = new RectangleF(0, afterResult.Bounds.Bottom + 90, graphics.ClientSize.Width, 30);
                //Draws a rectangle to place the heading in that region.
                graphics.DrawRectangle(solidBrush, secondBounds);
                element       = new PdfTextElement(SelectedInspectie.Naam, font);
                element.Brush = PdfBrushes.White;

                //Heading
                secondBounds = new RectangleF(0, afterResult.Bounds.Bottom + 10, questionlistPage.Graphics.ClientSize.Width, 30);
                questionlistPage.Graphics.DrawRectangle(new PdfSolidBrush(new PdfColor(126, 151, 173)), secondBounds);

                element       = new PdfTextElement(SelectedInspectie.Naam, subHeadingFont);
                element.Brush = new PdfSolidBrush(new PdfColor(126, 155, 203));
                afterResult   = element.Draw(questionlistPage, new PointF(10, afterResult.Bounds.Bottom + 45));

                DrawLine(questionlistPage, afterResult);

                //Read the questionlist
                afterResult = ReadFilledForm(questionlistPage, afterResult, element, answerlist);
                InsertChart(questionlistPage, afterResult, document, element, graphics, answerlist);
                CreateInputField(questionlistPage, afterResult, document);
                document.Save(pdfName);
            }
            //Show confirmation message
            ShowMessage(pdfName);
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
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);
                }
            }
        }
Exemplo n.º 15
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;
        }
        public async Task <IActionResult> CreateDocument()
        {
            string user        = User.FindFirst("Index").Value;
            var    Currentuser = await _taskRepository.GetCurrentUser(user);

            ViewBag.photo = Currentuser.PhotoURL;
            //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;
            //Loads the image as stream
            PdfFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 24);

            graphics.DrawString("Daily Time Sheet  -  ", font, PdfBrushes.Blue, new PointF(170, 30));
            string  Date        = DateTime.Now.ToString("MM/dd/yyyy");
            PdfFont font4       = new PdfStandardFont(PdfFontFamily.Helvetica, 18);
            string  currentDate = "DATE " + DateTime.Now.ToString("MM/dd/yyyy");

            graphics.DrawString(Date, font4, PdfBrushes.Blue, new PointF(370, 33));

            PdfFont font2 = new PdfStandardFont(PdfFontFamily.Helvetica, 16);

            graphics.DrawString("Ishara Maduhansi", font2, PdfBrushes.Black, new PointF(190, 70));

            PdfFont font3 = new PdfStandardFont(PdfFontFamily.Helvetica, 13);

            graphics.DrawString("Software Engineer", font3, PdfBrushes.Black, new PointF(190, 95));

            FileStream imageStream = new FileStream("wwwroot/images/bell.jpg", FileMode.Open, FileAccess.Read);
            RectangleF bounds      = new RectangleF(10, 0, 150, 150);
            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, 160, 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("Time Sheet ", subHeadingFont);

            element.Brush = PdfBrushes.White;

            //Draws the heading on the page
            PdfLayoutResult result = element.Draw(page, new PointF(10, 165));
            //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, 165);

            //Draws the date by using DrawString method
            graphics.DrawString(currentDate, subHeadingFont, element.Brush, textPosition);

            //Creates text elements to add the address and draw it to the page.
            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
            // Creates the grid cell styles
            //Create a PdfGrid.
            PdfGrid pdfGrid = new PdfGrid();
            //Add values to list

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

            object[] ary  = new object[2];
            Object   row1 = new { task = "Login", Start_Date = Date, End_Date = Date, Effort = "2 h 40 Min" };
            Object   row2 = new { task = "Time Sheet", Start_Date = Date, End_Date = Date, Effort = "3 h " };
            Object   row3 = new { task = "Employee", Start_Date = Date, End_Date = Date, Effort = "2 h 40 Min" };
            Object   row4 = new { task = "Leave Part", Start_Date = Date, End_Date = Date, Effort = "4 h 20 Min" };
            Object   row5 = new { task = "Attendence Part", Start_Date = Date, End_Date = Date, Effort = "1 h 40 Min" };

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

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

            MemoryStream stream = new MemoryStream();

            document.Save(stream);
            //If the position is not set to '0' then the PDF will be empty.
            stream.Position = 0;
            //Close the document.
            FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf");

            //Creates a FileContentResult object by using the file contents, content type, and file name.
            return(fileStreamResult);
        }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
0
        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);

        }
Exemplo n.º 19
0
        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);
        }
Exemplo n.º 20
0
        public IActionResult xuatpdf()
        {
            var dbContext = new shopContext();
            //Create a new PDF document
            PdfDocument doc = new PdfDocument();
//Add a page.
            PdfPage page = doc.Pages.Add();
            //Create a PdfGrid.
            PdfGrid pdfGrid = new PdfGrid();

            // create a graphics
            PdfGraphics graphics = page.Graphics;
            //Add values to list

            // List<object> data = new List<object>();
            // Object row1 = new { ID = "E01", Name = "Clay" };
            // Object row2 = new { ID = "E02", Name = "Thomas" };
            // Object row3 = new { ID = "E03", Name = "Andrew" };
            // Object row4 = new { ID = "E04", Name = "Paul" };
            // Object row5 = new { ID = "E05", Name = "Gray" };
            // data.Add(row1);
            // data.Add(row2);
            // data.Add(row3);
            // data.Add(row4);
            // data.Add(row5);

            //Add list to IEnumerable

            var data = (from d in dbContext.Sanpham select d).ToList();
            IEnumerable <object> dataTable = data;

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


            RectangleF bounds     = new RectangleF(176, 0, 390, 130);
            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("INVOICE " + "ok baby", subHeadingFont);

            element.Brush = PdfBrushes.White;

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


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

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

            //Creates a FileContentResult object by using the file contents, content type, and file name.
            return(File(stream, contentType, fileName));
        }
Exemplo n.º 21
0
        public static void updateEffectiveDate(string strSiteUrl, string strUserId, string strPassword, string strEffectiveListName, string strDcrDocId)
        {
            try
            {
                using (var context = new ClientContext(strSiteUrl))
                {
                    SecureString passWord = new SecureString();
                    foreach (char c in strPassword.ToCharArray())
                    {
                        passWord.AppendChar(c);
                    }
                    context.Credentials = new SharePointOnlineCredentials(strUserId, passWord);
                    // Gets list object using the list Url
                    List      oList     = context.Web.Lists.GetByTitle(strEffectiveListName);
                    CamlQuery camlQuery = new CamlQuery();
                    camlQuery.ViewXml = "<View><Query><Where><Eq><FieldRef Name='CE_DCRDocID'/>" +
                                        "<Value Type='Lookup'>" + strDcrDocId +
                                        "</Value></Eq></Where></Query></View>";
                    ListItemCollection collListItem = oList.GetItems(camlQuery);
                    context.Load(collListItem);
                    context.ExecuteQuery();
                    foreach (ListItem item in collListItem)
                    {
                        var filePath = item["FileRef"];
                        docFileName = (string)item["FileLeafRef"];


                        Microsoft.SharePoint.Client.File file = item.File;
                        docLinkUrl = new Uri(context.Url).GetLeftPart(UriPartial.Authority) + filePath;
                        if (file != null)
                        {
                            //Loading Uploaded file
                            context.Load(file);
                            context.ExecuteQuery();
                            string dskFilePath = System.IO.Path.Combine(@"C:\Srini\Celitotech\Dev\PDF files\", file.Name);
                            using (System.IO.FileStream Local_stream = System.IO.File.Open(dskFilePath, System.IO.FileMode.CreateNew, System.IO.FileAccess.ReadWrite))
                            {
                                var fileInformation = Microsoft.SharePoint.Client.File.OpenBinaryDirect(context, file.ServerRelativeUrl);
                                var Sp_Stream       = fileInformation.Stream;
                                Sp_Stream.CopyTo(Local_stream);
                            }

                            PdfLoadedDocument loadedDocument = new PdfLoadedDocument(dskFilePath);
                            PdfDocument       document       = new PdfDocument();
                            document.ImportPageRange(loadedDocument, 0, loadedDocument.Pages.Count - 1);
                            document.Template.Top    = AddHeader(document, spHeaderLine1, spHeaderLine2, spHeaderLine3, spWaterMark, spExpiryDays);
                            document.Template.Bottom = AddFooter(document, spFooterLine1, spFooterLine2, spFooterLine3);

                            for (int i = 0; i < document.Pages.Count; i++)
                            {
                                PdfPageBase loadedPage = document.Pages[i];
                                PdfGraphics graphics   = loadedPage.Graphics;
                                PdfFont     font       = new PdfStandardFont(PdfFontFamily.Helvetica, 45);

                                //Add watermark text
                                PdfGraphicsState state = graphics.Save();
                                graphics.SetTransparency(0.25f);
                                graphics.RotateTransform(-40);
                                string text = spWaterMark;
                                SizeF  size = font.MeasureString(text);
                                graphics.DrawString(spWaterMark, font, PdfPens.Gray, PdfBrushes.Gray, new PointF(-150, 450));
                            }

                            DateTime            currentTime          = DateTime.Now;
                            Double              dbleExpiryDays       = Convert.ToDouble(spExpiryDays);
                            DateTime            addDaysToCurrentTime = currentTime.AddDays(dbleExpiryDays);
                            PdfJavaScriptAction scriptAction         = new PdfJavaScriptAction("function Expire(){ var currentDate = new Date();  var expireDate = new Date(2021, 3, 8);      if (currentDate < expireDate) {  app.alert(\"This Document has Expired.  You need a new one.\"); this.closeDoc();   }  } Expire(); ");
                            document.Actions.AfterOpen = scriptAction;

                            document.Save(docFileName);
                            document.Close(true);
                            loadedDocument.Close(true);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 22
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);
        }
Exemplo n.º 23
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);
            };
        }