Beispiel #1
0
        /// <summary>
        /// Fired when Header and Footer are exported to PDF
        /// </summary>
        /// <param name="sender">PDF Export_HeaderAndFooterExporting sender</param>
        /// <param name="e">PDF Export_HeaderAndFooterExporting EventArgs e</param>
        private void PdfExport_HeaderAndFooterExporting(object sender, PdfHeaderFooterEventArgs e)
        {
            var                    width    = e.PdfPage.GetClientSize().Width;
            PdfStandardFont        font     = null;
            PdfPageTemplateElement header   = new PdfPageTemplateElement(width, 60);
            var                    assmbely = this.GetType().GetTypeInfo().Assembly;

#if COMMONSB
            var imagestream = assmbely.GetManifestResourceStream("SampleBrowser.Icons.SyncfusionLogo.jpg");
#else
            var imagestream = assmbely.GetManifestResourceStream("SampleBrowser.SfDataGrid.Icons.SyncfusionLogo.jpg");
#endif
            PdfImage pdfImage = PdfImage.FromStream(imagestream);
            header.Graphics.DrawImage(pdfImage, new RectangleF(width - 148, 0, 148, 60));
            if (Device.RuntimePlatform == Device.iOS)
            {
                font = new PdfStandardFont(PdfFontFamily.Helvetica, 18, PdfFontStyle.Bold);
            }
            else
            {
                font = new PdfStandardFont(PdfFontFamily.Helvetica, 13, PdfFontStyle.Bold);
            }

            PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Left);
            header.Graphics.DrawString("Customer Details", font, PdfBrushes.Black, new RectangleF(0, 25, 200, 60), format);
            e.PdfDocumentTemplate.Top = header;
        }
        static async void PdfHeaderFooterEventHandler(object sender, TreeGridPdfHeaderFooterEventArgs e)
        {
            var width = e.PdfPage.GetClientSize().Width;

            PdfPageTemplateElement header = new PdfPageTemplateElement(width, 38);

            e.PdfDocumentTemplate.Top = header;

            PdfPageTemplateElement footer = new PdfPageTemplateElement(width, 30);

            e.PdfDocumentTemplate.Bottom = footer;
            var uri     = new Uri("ms-appx:///Images/Header.png", UriKind.RelativeOrAbsolute);
            var srcfile = await StorageFile.GetFileFromApplicationUriAsync(uri);

            var stream = await srcfile.OpenStreamForReadAsync();

            header.Graphics.DrawImage(PdfImage.FromStream(stream), 0, 0, width / 3f, 34);

            uri     = new Uri("ms-appx:///Images/Footer.png", UriKind.RelativeOrAbsolute);
            srcfile = await StorageFile.GetFileFromApplicationUriAsync(uri);

            stream = await srcfile.OpenStreamForReadAsync();

            footer.Graphics.DrawImage(PdfImage.FromStream(stream), 0, 0, width, 25);
            stream.Dispose();
        }
        public void ExportChart()
        {
            string Data = System.Web.HttpContext.Current.Request.Params["Data"];

            Data = Data.Remove(0, Data.IndexOf(',') + 1);
            string Data2 = System.Web.HttpContext.Current.Request.Params["Data1"];

            Data2 = Data2.Remove(0, Data2.IndexOf(',') + 1);
            string Data3 = System.Web.HttpContext.Current.Request.Params["Data2"];

            Data3 = Data3.Remove(0, Data3.IndexOf(',') + 1);
            string Data4 = System.Web.HttpContext.Current.Request.Params["Data3"];

            Data4 = Data4.Remove(0, Data4.IndexOf(',') + 1);
            string Data5 = System.Web.HttpContext.Current.Request.Params["Data4"];

            Data5 = Data5.Remove(0, Data5.IndexOf(',') + 1);

            MemoryStream stream  = new MemoryStream(Convert.FromBase64String(Data));
            MemoryStream stream2 = new MemoryStream(Convert.FromBase64String(Data2));
            MemoryStream stream3 = new MemoryStream(Convert.FromBase64String(Data3));
            MemoryStream stream4 = new MemoryStream(Convert.FromBase64String(Data4));
            MemoryStream stream5 = new MemoryStream(Convert.FromBase64String(Data5));
            PdfDocument  pdfDoc  = new PdfDocument();

            pdfDoc.Pages.Add();
            pdfDoc.Pages[0].Section.PageSettings.Orientation = PdfPageOrientation.Landscape;
            pdfDoc.Pages[0].Graphics.DrawImage(PdfImage.FromStream(stream), new RectangleF(10, 2, 550, 450));
            pdfDoc.Pages[0].Graphics.DrawImage(PdfImage.FromStream(stream2), new RectangleF(0, 10, 30, 15));
            pdfDoc.Pages[0].Graphics.DrawImage(PdfImage.FromStream(stream3), new RectangleF(30, 10, 30, 15));
            pdfDoc.Pages[0].Graphics.DrawImage(PdfImage.FromStream(stream3), new RectangleF(60, 10, 30, 15));
            pdfDoc.Pages[0].Graphics.DrawImage(PdfImage.FromStream(stream3), new RectangleF(90, 10, 30, 15));
            pdfDoc.Save("Map" + ".pdf", System.Web.HttpContext.Current.Response, HttpReadType.Save);
            pdfDoc.Close();
        }
Beispiel #4
0
        public IActionResult ConvertToPDF(IList <IFormFile> files)
        {
            //Creating the new PDF document
            PdfDocument document = new PdfDocument();

            foreach (var formFile in files)
            {
                if (formFile.Length > 0)
                {
                    MemoryStream file = new MemoryStream();
                    formFile.CopyTo(file);
                    if (formFile.ContentType == "image/tiff")
                    {
                        //Get the image from stream and draw frame by frame
                        PdfTiffImage tiffImage = new PdfTiffImage(file);

                        int frameCount = tiffImage.FrameCount;
                        for (int i = 0; i < frameCount; i++)
                        {
                            //Add pages to the document
                            var page = document.Pages.Add();
                            //Getting page size to fit the image within the page
                            SizeF pageSize = page.GetClientSize();
                            //Selecting frame in TIFF
                            tiffImage.ActiveFrame = i;
                            //Draw TIFF frame
                            page.Graphics.DrawImage(tiffImage, 0, 0, pageSize.Width, pageSize.Height);
                        }
                    }
                    else
                    {
                        //Loading the image
                        PdfImage image = PdfImage.FromStream(file);
                        //Adding new page
                        PdfPage page = page = document.Pages.Add();
                        //Drawing image to the PDF page
                        page.Graphics.DrawImage(image, new PointF(0, 0));
                    }
                    file.Dispose();
                }
            }
            //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 = "ImageToPDF.pdf";

            return(fileStreamResult);
        }
        private static PdfImage CreatePdfImage(string signature)
        {
            var base64 = GetBase64Image(signature);

            var binary = Convert.FromBase64String(base64);

            using (var stream = new MemoryStream(binary))
            {
                return(PdfImage.FromStream(stream));
            }
        }
        private void pdfExport_HeaderAndFooterExporting(object sender, PdfHeaderFooterEventArgs e)
        {
            var width = e.PdfPage.GetClientSize().Width;

            PdfPageTemplateElement header = new PdfPageTemplateElement(width, 60);
            var      assmbely             = Assembly.GetExecutingAssembly();
            var      imagestream          = assmbely.GetManifestResourceStream("SampleBrowser.Resources.Images.SyncfusionLogo.jpg");
            PdfImage pdfImage             = PdfImage.FromStream(imagestream);

            header.Graphics.DrawImage(pdfImage, new RectangleF(0, 0, width, 50));
            e.PdfDocumentTemplate.Top = header;
        }
Beispiel #7
0
        private void createHeader()
        {
            Stream logoStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("OrariUnibg.Resources.Image.Logo_flat.jpg");
            // header
            PdfPageTemplateElement header = new PdfPageTemplateElement(new RectangleF(new PointF(0, 0), new SizeF(_document.PageSettings.Width, heightHeader)));
            string tramite = string.Format("Condiviso tramite: {0}", Settings.AppName);

            if (Settings.IsLoggedIn)
            {
                tramite = string.Format("{0} tramite: {1}", Settings.Name, Settings.AppName);
            }

            header.Graphics.DrawString(tramite, smallFont, brushBlack, new PointF(marginLeft, 40));
            header.Graphics.DrawImage(PdfImage.FromStream(logoStream), new PointF(_document.PageSettings.Width + 5 - marginRight * 2, 15), new SizeF(40, 40));
            _document.Template.Top = header;
        }
Beispiel #8
0
        static void PdfHeaderFooterEventHandler(object sender, PdfHeaderFooterEventArgs e)
        {
            var width = e.PdfPage.GetClientSize().Width;
            PdfPageTemplateElement header = new PdfPageTemplateElement(width, 38);
            Assembly assembly             = typeof(ExportToPdfCommands).Assembly;
            Stream   headerImgStream      = assembly.GetManifestResourceStream("syncfusion.datagriddemos.wpf.Assets.datagrid.Header.jpg");
            PdfImage img = PdfImage.FromStream(headerImgStream) as PdfImage;

            header.Graphics.DrawImage(img, 155, 5, width / 3f, 34);
            e.PdfDocumentTemplate.Top = header;
            PdfPageTemplateElement footer = new PdfPageTemplateElement(width, 30);
            Stream   footerImgStream      = assembly.GetManifestResourceStream("syncfusion.datagriddemos.wpf.Assets.datagrid.Footer.jpg");
            PdfImage bitmapFooter         = PdfImage.FromStream(footerImgStream) as PdfImage;

            footer.Graphics.DrawImage(bitmapFooter, 0, 0);
            e.PdfDocumentTemplate.Bottom = footer;
        }
        void table_BeginRowLayout(object sender, BeginRowLayoutEventArgs args)
        {
            if (args.RowIndex < 0)
            {
                //Header
                return;
            }
            DataTable dataTable = (sender as PdfTable).DataSource as DataTable;

            byte[] imageData = dataTable.Rows[args.RowIndex][6] as byte[];
            using (MemoryStream stream = new MemoryStream(imageData))
            {
                PdfImage image = PdfImage.FromStream(stream);
                args.MinimalHeight = 4 + image.PhysicalDimension.Height;
                dataTable.Rows[args.RowIndex][7] = image;
            }
        }
        public void ExportAsPDF(string filename, Stream chartStream, SfChart chart)
        {
            var doc = new PdfDocument();

            doc.PageSettings.Margins.All = 0;
            var page = doc.Pages.Add();
            var g    = page.Graphics;

            g.DrawImage(PdfImage.FromStream(chartStream), 0, 0, 600, 800);

            MemoryStream stream = new MemoryStream();

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

            var path     = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            var filePath = Path.Combine(path, filename);

            try
            {
                var fileStream = File.Open(filePath, FileMode.Create);
                stream.Position = 0;
                stream.CopyTo(fileStream);
                fileStream.Flush();
                fileStream.Close();
            }
            catch (Exception e)
            {
            }

            var currentController = UIApplication.SharedApplication.KeyWindow.RootViewController;

            while (currentController.PresentedViewController != null)
            {
                currentController = currentController.PresentedViewController;
            }
            var currentView = currentController.View;

            var           qlPreview = new QLPreviewController();
            QLPreviewItem item      = new QLPreviewItemBundle(filename, filePath);

            qlPreview.DataSource = new PreviewControllerDS(item);

            currentController.PresentViewController(qlPreview, true, null);
        }
Beispiel #11
0
        //向pdf指定位置添加图片,按照坐标
        /// <summary>
        /// 向PDF指定位置添加图片
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="newPath"></param>
        /// <param name="X"></param>
        /// <param name="Y"></param>
        /// <param name="BlobFiled">图片字符串</param>
        /// <param name="imgHeight">图片高度,为0时使用图片原始高度</param>
        /// <param name="imgWidth">图片宽度,为0时使用图片原始宽度</param>
        public void addImage2Pdf_point(string filePath, string newPath, float X, float Y, string BlobFiled, float imgWidth, float imgHeight)
        {
            try
            {
                //Create a pdf document
                PdfDocument doc = new PdfDocument();
                doc.LoadFromFile(filePath);

                //get the page
                PdfPageBase page = doc.Pages[0];

                byte[] numArray = System.Text.Encoding.UTF8.GetBytes(BlobFiled);

                //get the image
                if (numArray == null)
                {
                    return;
                }
                PdfImage image  = PdfImage.FromStream(new MemoryStream(numArray));
                float    width  = imgWidth;
                float    height = imgHeight;
                if (imgWidth == 0)
                {
                    width = image.Width;
                }
                if (imgHeight == 0)
                {
                    height = image.Height;
                }

                //insert image
                page.Canvas.DrawImage(image, X, Y, width, height);

                //save pdf file
                doc.SaveToFile(newPath);
                doc.Close();
            }
            catch (Exception ex)
            {
                classLims_NPOI.WriteLog(ex, "");
            }
        }
        public void ExportAsPDF(string filename, Stream chartStream, SfChart chart)
        {
            try
            {
                //Create a new PDF document.
                var document = new PdfDocument();
                var page     = document.Pages.Add();
                var graphics = page.Graphics;
                graphics.DrawImage(PdfImage.FromStream(chartStream), 0, 0, page.GetClientSize().Width, page.GetClientSize().Height);

                MemoryStream stream = new MemoryStream();
                document.Save(stream);
                document.Close(true);
                SavePDF(filename, stream);
            }
            finally
            {
                chartStream.Flush();
                chartStream.Close();

                var nativeChart = SfChartRenderer.GetNativeObject(typeof(SfChart), chart);
                ((Com.Syncfusion.Charts.SfChart)nativeChart).DrawingCacheEnabled = false;
            }
        }
        public static byte[] Image2Images(Stream inputFile)
        {
            // Create a pdf document with a section and page added.
            PdfDocument doc     = new PdfDocument();
            PdfSection  section = doc.Sections.Add();
            PdfPageBase page    = doc.Pages.Add();
            //Load a tiff image from system
            PdfImage image = PdfImage.FromStream(inputFile);
            //Set image display location and size in PDF
            float widthFitRate  = image.PhysicalDimension.Width / page.Canvas.ClientSize.Width;
            float heightFitRate = image.PhysicalDimension.Height / page.Canvas.ClientSize.Height;
            float fitRate       = Math.Max(widthFitRate, heightFitRate);
            float fitWidth      = image.PhysicalDimension.Width / fitRate;
            float fitHeight     = image.PhysicalDimension.Height / fitRate;

            page.Canvas.DrawImage(image, 30, 30, fitWidth, fitHeight);
            //save and launch the file
            MemoryStream stream = new MemoryStream();

            doc.SaveToStream(stream, Spire.Pdf.FileFormat.PDF);
            doc.Close();

            return(Pdf2Images(stream));
        }
Beispiel #14
0
        private void button1_Click(object sender, EventArgs e)
        {
            // Create a pdf document with a section and page added.
            PdfDocument pdf     = new PdfDocument();
            PdfSection  section = pdf.Sections.Add();
            PdfPageBase page    = section.Pages.Add();

            // Create a FileStream object to read the imag file
            FileStream fs = File.OpenRead(@"..\..\..\..\..\..\Data\Water.jpg");

            // Read the image into Byte array
            byte[] data = new byte[fs.Length];
            fs.Read(data, 0, data.Length);
            // Create a MemoryStream object from image Byte array
            MemoryStream ms = new MemoryStream(data);
            // Specify the image source as MemoryStream
            PdfImage image = PdfImage.FromStream(ms);

            //Set image display location and size in PDF
            //Calculate rate
            float widthFitRate  = image.PhysicalDimension.Width / page.Canvas.ClientSize.Width;
            float heightFitRate = image.PhysicalDimension.Height / page.Canvas.ClientSize.Height;
            float fitRate       = Math.Max(widthFitRate, heightFitRate);
            //Calculate the size of image
            float fitWidth  = image.PhysicalDimension.Width / fitRate;
            float fitHeight = image.PhysicalDimension.Height / fitRate;

            //Draw image
            page.Canvas.DrawImage(image, 0, 30, fitWidth, fitHeight);

            //save and launch the file
            string output = "ConvertImageStreamToPDF.pdf";

            pdf.SaveToFile(output);
            System.Diagnostics.Process.Start(output);
        }
Beispiel #15
0
        void OnButtonClicked(object sender, EventArgs e)
        {
            PdfDocument document = null;
            int         index    = layoutList.IndexOf(selectedLayout);

            if (index == 0)
            {
                //Create a new PDF document
                document = new PdfDocument(PdfConformanceLevel.Pdf_A1A);
            }
            else if (index == 1)
            {
                document = new PdfDocument(PdfConformanceLevel.Pdf_A1B);
            }
            else if (index == 2)
            {
                document = new PdfDocument(PdfConformanceLevel.Pdf_A2A);
            }
            else if (index == 3)
            {
                document = new PdfDocument(PdfConformanceLevel.Pdf_A2B);
            }
            else if (index == 4)
            {
                document = new PdfDocument(PdfConformanceLevel.Pdf_A2U);
            }
            else
            {
                if (index == 5)
                {
                    document = new PdfDocument(PdfConformanceLevel.Pdf_A3A);
                }
                else if (index == 6)
                {
                    document = new PdfDocument(PdfConformanceLevel.Pdf_A3B);
                }
                else if (index == 7)
                {
                    document = new PdfDocument(PdfConformanceLevel.Pdf_A3U);
                }
                Stream imgStream = typeof(Conformance).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Assets.Products.xml");

                PdfAttachment attachment = new PdfAttachment("PDF_A.xml", imgStream);
                attachment.Relationship     = PdfAttachmentRelationship.Alternative;
                attachment.ModificationDate = DateTime.Now;

                attachment.Description = "PDF_A";

                attachment.MimeType = "application/xml";

                document.Attachments.Add(attachment);
            }

            PdfPage page = document.Pages.Add();

            //Create font
            Stream arialFontStream = typeof(Conformance).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Assets.arial.ttf");
            Stream imageStream     = typeof(Conformance).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.AdventureCycle.jpg");

            PdfFont font = new PdfTrueTypeFont(arialFontStream, 14);

            //Create PDF graphics for the page.
            PdfGraphics graphics = page.Graphics;
            //Load the image from the disk.
            PdfImage img = PdfImage.FromStream(imageStream);

            //Draw the image in the specified location and size.
            graphics.DrawImage(img, new RectangleF(150, 30, 200, 100));


            PdfTextElement textElement = new PdfTextElement("Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based," +
                                                            " is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, " +
                                                            "European and Asian commercial markets. While its base operation is located in Bothell, Washington with 290 employees, several regional" +
                                                            " sales teams are located throughout their market base.")
            {
                Font = font
            };
            PdfLayoutResult layoutResult = textElement.Draw(page, new RectangleF(0, 150, page.GetClientSize().Width, page.GetClientSize().Height));

            MemoryStream stream = new MemoryStream();

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

            //Close the PDF document.
            document.Close();

            stream.Position = 0;

            if (stream != null)
            {
                SaveiOS iosSave = new SaveiOS();
                iosSave.Save("PDF_Ab.pdf", "application/pdf", stream);
            }
        }
        public ActionResult Conformance(string InsideBrowser, string conformance)
        {
            string basePath = _hostingEnvironment.WebRootPath;
            string dataPath = string.Empty;

            dataPath = basePath + @"/PDF/";

            PdfDocument document = null;

            if (conformance == "PDF/A-1a")
            {
                //Create a new document with PDF/A standard.
                document = new PdfDocument(PdfConformanceLevel.Pdf_A1A);
            }
            else if (conformance == "PDF/A-1b")
            {
                //Create a new document with PDF/A standard.
                document = new PdfDocument(PdfConformanceLevel.Pdf_A1B);
            }
            else if (conformance == "PDF/A-2a")
            {
                //Create a new document with PDF/A standard.
                document = new PdfDocument(PdfConformanceLevel.Pdf_A2A);
            }
            else if (conformance == "PDF/A-2b")
            {
                //Create a new document with PDF/A standard.
                document = new PdfDocument(PdfConformanceLevel.Pdf_A2B);
            }
            else if (conformance == "PDF/A-2u")
            {
                //Create a new document with PDF/A standard.
                document = new PdfDocument(PdfConformanceLevel.Pdf_A2U);
            }
            else
            {
                if (conformance == "PDF/A-3a")
                {
                    document = new PdfDocument(PdfConformanceLevel.Pdf_A3A);
                }
                else if (conformance == "PDF/A-3b")
                {
                    document = new PdfDocument(PdfConformanceLevel.Pdf_A3B);
                }
                else if (conformance == "PDF/A-3u")
                {
                    document = new PdfDocument(PdfConformanceLevel.Pdf_A3U);
                }
                //Read the file
                FileStream file = new FileStream(dataPath + "Text1.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

                //Creates an attachment
                PdfAttachment attachment = new PdfAttachment("Text1.txt", file);

                attachment.Relationship     = PdfAttachmentRelationship.Alternative;
                attachment.ModificationDate = DateTime.Now;

                attachment.Description = "PDF_A";

                attachment.MimeType = "application/xml";

                document.Attachments.Add(attachment);
            }


            //Add a page to the document.
            PdfPage page = document.Pages.Add();
            //Create PDF graphics for the page.
            PdfGraphics graphics = page.Graphics;

            FileStream imageStream = new FileStream(dataPath + "AdventureCycle.jpg", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            //Load the image from the disk.
            PdfImage img = PdfImage.FromStream(imageStream);

            //Draw the image in the specified location and size.
            graphics.DrawImage(img, new RectangleF(150, 30, 200, 100));


            //Create font
            FileStream fontFileStream = new FileStream(dataPath + "arial.ttf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            PdfFont    font           = new PdfTrueTypeFont(fontFileStream, 14);


            PdfTextElement textElement = new PdfTextElement("Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based," +
                                                            " is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, " +
                                                            "European and Asian commercial markets. While its base operation is located in Bothell, Washington with 290 employees, several regional" +
                                                            " sales teams are located throughout their market base.")
            {
                Font = font
            };
            PdfLayoutResult layoutResult = textElement.Draw(page, new RectangleF(0, 150, page.GetClientSize().Width, page.GetClientSize().Height));

            MemoryStream stream = new MemoryStream();

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

            fileStreamResult.FileDownloadName = "PDF_A.pdf";
            return(fileStreamResult);
        }
Beispiel #17
0
        public void ExportChart(string Data, string ChartModel)
        {
            // declaration
            ChartProperties obj         = ConvertChartObject(ChartModel);
            string          type        = obj.ExportSettings.Type.ToString().ToLower();
            string          fileName    = obj.ExportSettings.FileName;
            string          orientation = obj.ExportSettings.Orientation.ToString();

            if (type == "svg")      // for svg export
            {
                StringWriter oStringWriter = new StringWriter();
                string       data          = HttpUtility.HtmlDecode(Data);
                data = HttpUtility.UrlDecode(Data);
                data = System.Uri.UnescapeDataString(Data);
                oStringWriter.WriteLine(System.Uri.UnescapeDataString(Data));
                Response.ContentType = "text/plain";
                Response.AddHeader("Content-Disposition", String.Format("attachment;filename={0}", (obj.ExportSettings.FileName + ".svg")));
                Response.Clear();
                using (StreamWriter writer = new StreamWriter(Response.OutputStream))
                {
                    data = oStringWriter.ToString();
                    writer.Write(oStringWriter.ToString());
                }
                Response.End();
            }

            else if (type == "xlsx")       // to export chart as excel
            {
                List <ExportChartData> chartData = new List <ExportChartData>();
                chartData.Add(new ExportChartData("John", 10));
                chartData.Add(new ExportChartData("Jake", 12));
                chartData.Add(new ExportChartData("Peter", 18));
                chartData.Add(new ExportChartData("James", 11));
                chartData.Add(new ExportChartData("Mary", 9.7));

                ExcelExport exp = new ExcelExport();
                exp.Export(obj, (IEnumerable)chartData, fileName + ".xlsx", ExcelVersion.Excel2010, null, null);
            }

            else
            {
                Data = Data.Remove(0, Data.IndexOf(',') + 1);
                MemoryStream stream = new MemoryStream(Convert.FromBase64String(Data));

                if (type == "docx")        // to export as word document
                {
                    WordDocument document  = new WordDocument();
                    IWSection    section   = document.AddSection();
                    IWParagraph  paragraph = section.AddParagraph();

                    //Set orientation based on chart width
                    Image img = Image.FromStream(stream);
                    if (obj.ExportSettings.Orientation.ToString() == "Landscape" || section.PageSetup.ClientWidth < img.Width)
                    {
                        section.PageSetup.Orientation = PageOrientation.Landscape;
                    }
                    else
                    {
                        section.PageSetup.Orientation = PageOrientation.Portrait;
                    }
                    img.Dispose();

                    paragraph.AppendPicture(Image.FromStream(stream));
                    document.Save(fileName + ".doc", Syncfusion.DocIO.FormatType.Doc, HttpContext.ApplicationInstance.Response, Syncfusion.DocIO.HttpContentDisposition.Attachment);
                }
                else if (type == "pdf")      // to export as PDF
                {
                    PdfDocument pdfDoc = new PdfDocument();
                    pdfDoc.Pages.Add();

                    //Set chart width as pdf page width
                    Image img = Image.FromStream(stream);
                    pdfDoc.Pages[0].Section.PageSettings.Width = img.Width;
                    img.Dispose();

                    if (obj.ExportSettings.Orientation.ToString() == "Landscape")
                    {
                        pdfDoc.Pages[0].Section.PageSettings.Orientation = PdfPageOrientation.Landscape;
                    }
                    else
                    {
                        pdfDoc.Pages[0].Section.PageSettings.Orientation = PdfPageOrientation.Portrait;
                    }
                    pdfDoc.Pages[0].Graphics.DrawImage(PdfImage.FromStream(stream), new PointF(10, 30));
                    pdfDoc.Save(obj.ExportSettings.FileName + ".pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save);
                    pdfDoc.Close();
                }
                else                        // to export as image
                {
                    stream.WriteTo(Response.OutputStream);
                    Response.ContentType = "application/octet-stream";
                    Response.AddHeader("Content-Disposition", String.Format("attachment;filename={0}", fileName + "." + type));
                    Response.Flush();
                    stream.Close();
                    stream.Dispose();
                }
            }
        }
Beispiel #18
0
        internal void GenReport3Phase2()
        {
            string[] dt    = pmsutil.GetServerDateTime().Split(null);
            DateTime cDate = Convert.ToDateTime(dt[0]);
            DateTime cTime = DateTime.Parse(dt[1] + " " + dt[2]);

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

            PdfPageBase page = pdfDoc.Pages.Add();

            var      stream = this.GetType().GetTypeInfo().Assembly.GetManifestResourceStream("PMS.Assets.st_raphael_logo_dark.png");
            PdfImage logo   = PdfImage.FromStream(stream);
            float    _width = 200;
            float    height = 80;
            float    x      = (page.Canvas.ClientSize.Width - _width) / 2;

            page.Canvas.DrawImage(logo, 0, -25, _width, height);

            page.Canvas.DrawString("Peñaranda St, Legazpi Port District",
                                   new PdfFont(PdfFontFamily.TimesRoman, 13f),
                                   new PdfSolidBrush(System.Drawing.Color.Black),
                                   245, 0);

            page.Canvas.DrawString("Legazpi City, Albay",
                                   new PdfFont(PdfFontFamily.TimesRoman, 13f),
                                   new PdfSolidBrush(System.Drawing.Color.Black),
                                   280, 20);

            page.Canvas.DrawLine(new PdfPen(System.Drawing.Color.Black), new PointF(1, 49), new PointF(530, 49));

            page.Canvas.DrawString("PMS Index Report",
                                   new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                   new PdfSolidBrush(System.Drawing.Color.Black),
                                   350, 52);

            page.Canvas.DrawString("Generated on: " + DateTime.Now.ToString("MMMM dd, yyyy hh:mm tt"),
                                   new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                   new PdfSolidBrush(System.Drawing.Color.Black),
                                   10, 52);

            page.Canvas.DrawLine(new PdfPen(System.Drawing.Color.Black), new PointF(1, 70), new PointF(530, 70));

            page.Canvas.DrawString(_name.ToUpper(),
                                   new PdfFont(PdfFontFamily.TimesRoman, 18f, PdfFontStyle.Bold),
                                   new PdfSolidBrush(System.Drawing.Color.Black),
                                   10, 85);

            //page.Canvas.DrawLine(new PdfPen(System.Drawing.Color.Black), new PointF(10, 115), new PointF(330, 115));

            page.Canvas.DrawString("Birth Details",
                                   new PdfFont(PdfFontFamily.TimesRoman, 12f, PdfFontStyle.Bold),
                                   new PdfSolidBrush(System.Drawing.Color.Black),
                                   10, 125);

            page.Canvas.DrawString("Age: " + _age,
                                   new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                   new PdfSolidBrush(System.Drawing.Color.Black),
                                   10, 150);

            page.Canvas.DrawString("Residence: " + _residence,
                                   new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                   new PdfSolidBrush(System.Drawing.Color.Black),
                                   10, 170);

            page.Canvas.DrawString("Residence: " + _residence,
                                   new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                   new PdfSolidBrush(System.Drawing.Color.Black),
                                   10, 190);

            page.Canvas.DrawString("Parents: " + _parent1 + " & " + _parent2,
                                   new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                   new PdfSolidBrush(System.Drawing.Color.Black),
                                   10, 210);

            page.Canvas.DrawString("Burial Details",
                                   new PdfFont(PdfFontFamily.TimesRoman, 12f, PdfFontStyle.Bold),
                                   new PdfSolidBrush(System.Drawing.Color.Black),
                                   300, 125);

            page.Canvas.DrawString("Date of Death: " + _deathDate,
                                   new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                   new PdfSolidBrush(System.Drawing.Color.Black),
                                   300, 150);

            page.Canvas.DrawString("Burial Date: " + _burialDate,
                                   new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                   new PdfSolidBrush(System.Drawing.Color.Black),
                                   300, 170);

            page.Canvas.DrawString("Cause of Death: " + _causeOfDeath,
                                   new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                   new PdfSolidBrush(System.Drawing.Color.Black),
                                   300, 190);

            page.Canvas.DrawString("Sacrament: " + _sacrament,
                                   new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                   new PdfSolidBrush(System.Drawing.Color.Black),
                                   300, 210);

            page.Canvas.DrawString("Place of Interment: ",
                                   new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                   new PdfSolidBrush(System.Drawing.Color.Black),
                                   300, 230);

            page.Canvas.DrawString(_interment,
                                   new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                   new PdfSolidBrush(System.Drawing.Color.Black),
                                   300, 250);

            page.Canvas.DrawString("Location: ",
                                   new PdfFont(PdfFontFamily.TimesRoman, 12f, PdfFontStyle.Bold),
                                   new PdfSolidBrush(System.Drawing.Color.Black),
                                   300, 280);

            page.Canvas.DrawString("Block: " + _block,
                                   new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                   new PdfSolidBrush(System.Drawing.Color.Black),
                                   300, 300);

            page.Canvas.DrawString("Lot: " + _lot,
                                   new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                   new PdfSolidBrush(System.Drawing.Color.Black),
                                   300, 320);

            page.Canvas.DrawString("Plot: " + _plot,
                                   new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                   new PdfSolidBrush(System.Drawing.Color.Black),
                                   300, 340);

            page.Canvas.DrawString("Near the Location",
                                   new PdfFont(PdfFontFamily.TimesRoman, 14f),
                                   new PdfSolidBrush(System.Drawing.Color.Black),
                                   10, 360);

            DataTable dtNames = new DataTable();

            dtNames.Columns.Add("Name", typeof(string));
            dtNames.Columns.Add("Lot", typeof(string));
            dtNames.Columns.Add("Plot", typeof(string));

            dbman = new DBConnectionManager();
            using (conn = new MySqlConnection(dbman.GetConnStr()))
            {
                conn.Open();
                if (conn.State == ConnectionState.Open)
                {
                    MySqlCommand cmd = conn.CreateCommand();
                    cmd.CommandText = "SELECT * FROM records, burial_records, burial_directory WHERE records.record_id = burial_records.record_id AND burial_records.record_id = burial_directory.record_id AND burial_directory.block = @block AND burial_directory.lot = @lot;";
                    cmd.Parameters.AddWithValue("@block", _block);
                    cmd.Parameters.AddWithValue("@lot", _lot);
                    MySqlDataReader db_reader = cmd.ExecuteReader();
                    while (db_reader.Read())
                    {
                        if (db_reader.GetString("record_id") != _rid)
                        {
                            dtNames.Rows.Add(db_reader.GetString("recordholder_fullname"), db_reader.GetString("lot"), db_reader.GetString("plot"));
                        }
                    }
                }
            }

            PdfTable table = new PdfTable();

            table.Style.CellPadding = 2;
            //table.Style.DefaultStyle.BackgroundBrush = PdfBrushes.SkyBlue;
            table.Style.DefaultStyle.Font = new PdfTrueTypeFont(new Font("Times New Roman", 11f));

            table.Style.AlternateStyle = new PdfCellStyle
            {
                //table.Style.AlternateStyle.BackgroundBrush = PdfBrushes.LightYellow;
                Font = new PdfTrueTypeFont(new Font("Times New Roman", 11f))
            };

            table.Style.HeaderSource = PdfHeaderSource.ColumnCaptions;
            //table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.CadetBlue;
            table.Style.HeaderStyle.Font         = new PdfFont(PdfFontFamily.TimesRoman, 13f);
            table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);

            table.Style.ShowHeader = true;

            table.DataSourceType = PdfTableDataSourceType.TableDirect;
            table.DataSource     = dtNames;
            //Set the width of column
            float width = page.Canvas.ClientSize.Width - (table.Columns.Count + 1);

            table.Columns[0].Width        = width * 0.24f * width;
            table.Columns[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            table.Columns[1].Width        = width * 0.21f * width;
            table.Columns[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            table.Columns[2].Width        = width * 0.24f * width;
            table.Columns[2].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            table.Draw(page, new PointF(10, 380));

            //save
            pdfDoc.SaveToFile(@"..\..\index_report.pdf");
            //launch the pdf document
            System.Diagnostics.Process.Start(@"..\..\index_report.pdf");
        }
Beispiel #19
0
        private void GenerateDailyReport()
        {
            pmsutil = new PMSUtil();

            string[] dt    = pmsutil.GetServerDateTime().Split(null);
            DateTime cDate = Convert.ToDateTime(dt[0]);
            DateTime cTime = DateTime.Parse(dt[1] + " " + dt[2]);

            PdfDocument pdfDoc = new PdfDocument();

            PdfPageBase page   = pdfDoc.Pages.Add();
            var         stream = this.GetType().GetTypeInfo().Assembly.GetManifestResourceStream("PMS.Assets.st_raphael_logo_dark.png");
            PdfImage    logo   = PdfImage.FromStream(stream);
            float       _width = 200;
            float       height = 80;
            float       x      = (page.Canvas.ClientSize.Width - _width) / 2;

            page.Canvas.DrawImage(logo, 0, -25, _width, height);

            page.Canvas.DrawString("Peñaranda St, Legazpi Port District",
                                   new PdfFont(PdfFontFamily.TimesRoman, 13f),
                                   new PdfSolidBrush(Color.Black),
                                   245, 0);

            page.Canvas.DrawString("Legazpi City, Albay",
                                   new PdfFont(PdfFontFamily.TimesRoman, 13f),
                                   new PdfSolidBrush(Color.Black),
                                   280, 20);

            page.Canvas.DrawLine(new PdfPen(Color.Black), new PointF(1, 49), new PointF(530, 49));

            page.Canvas.DrawString("PMS Scheduling Module Report",
                                   new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                   new PdfSolidBrush(Color.Black),
                                   350, 52);

            page.Canvas.DrawString("Generated on: " + DateTime.Now.ToString("MMMM dd, yyyy hh:mm tt"),
                                   new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                   new PdfSolidBrush(Color.Black),
                                   10, 52);

            page.Canvas.DrawString("Type: " + ListType.Text,
                                   new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                   new PdfSolidBrush(System.Drawing.Color.Black),
                                   380, 90);

            page.Canvas.DrawLine(new PdfPen(Color.Black), new PointF(1, 70), new PointF(530, 70));

            if (ListType.SelectedIndex == 1)
            {
                page.Canvas.DrawString(cDate.ToString("MMMM dd, yyyy").ToUpper() + " (" + cDate.ToString("dddd").ToUpper() + ")",
                                       new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                       new PdfSolidBrush(Color.Black),
                                       10, 90);
            }
            else
            {
                page.Canvas.DrawString(DateTime.Parse(ListMinDate.SelectedDate.ToString()).ToString("MMMM dd, yyyy").ToUpper() + " TO " + DateTime.Parse(ListMaxDate.SelectedDate.ToString()).ToString("MMMM dd, yyyy").ToUpper(),
                                       new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                       new PdfSolidBrush(Color.Black),
                                       10, 90);
            }

            PdfTable table = new PdfTable();

            table.Style.CellPadding       = 2;
            table.Style.DefaultStyle.Font = new PdfTrueTypeFont(new Font("Times New Roman", 11f));

            table.Style.AlternateStyle      = new PdfCellStyle();
            table.Style.AlternateStyle.Font = new PdfTrueTypeFont(new Font("Times New Roman", 11f));

            table.Style.HeaderSource             = PdfHeaderSource.ColumnCaptions;
            table.Style.HeaderStyle.Font         = new PdfFont(PdfFontFamily.TimesRoman, 13f);
            table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);

            table.Style.ShowHeader = true;

            table.DataSourceType = PdfTableDataSourceType.TableDirect;
            table.DataSource     = GenerateList();
            //Set the width of column
            float width = page.Canvas.ClientSize.Width - (table.Columns.Count + 1);

            table.Columns[0].Width        = width * 0.24f * width;
            table.Columns[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            table.Columns[1].Width        = width * 0.21f * width;
            table.Columns[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            table.Columns[2].Width        = width * 0.24f * width;
            table.Columns[2].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            table.Columns[3].Width        = width * 0.24f * width;
            table.Columns[3].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            table.Columns[4].Width        = width * 0.24f * width;
            table.Columns[4].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            if (ListType.SelectedIndex == 2)
            {
                table.Columns[5].Width        = width * 0.24f * width;
                table.Columns[5].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            }
            table.Draw(page, new PointF(10, 120));

            string fname = "Scheduling_Report-" + ListType.Text + "-" + DateTime.Now.ToString("MMM_dd_yyyy") + ".pdf";

            //save
            pdfDoc.SaveToFile(@"..\..\" + fname);
            //launch the pdf document
            System.Diagnostics.Process.Start(@"..\..\" + fname);
        }
Beispiel #20
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);
                }
            }
        }
Beispiel #21
0
        /// <summary>
        /// Create a simple PDF document
        /// </summary>
        /// <returns>Return the created PDF document as stream</returns>
        public MemoryStream BulletsAndListPDF()
        {
            //Create a new Pdf document
            PdfDocument document = new PdfDocument();

            //Add a page
            PdfPage     page     = document.Pages.Add();
            PdfGraphics graphics = page.Graphics;

            //Create a unordered list
            PdfUnorderedList list = new PdfUnorderedList();

            //Set the marker style
            list.Marker.Style = PdfUnorderedMarkerStyle.Disk;

            //Create a font and write title
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14, PdfFontStyle.Bold);

            graphics.DrawString("List Features", font, PdfBrushes.DarkBlue, new PointF(225, 10));

            string[] products = { "Tools", "Grid", "Chart", "Edit", "Diagram", "XlsIO", "Grouping", "Calculate", "PDF", "HTMLUI", "DocIO" };
            string[] IO       = { "XlsIO", "PDF", "DocIO" };

            font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular);
            graphics.DrawString("This sample demonstrates various features of bullets and lists. A list can be ordered and Unordered. Essential PDF provides support for creating and formatting ordered and unordered lists.", font, PdfBrushes.Black, new RectangleF(0, 50, page.Graphics.ClientSize.Width, page.Graphics.ClientSize.Height));

            //Create string format
            PdfStringFormat format = new PdfStringFormat();

            format.LineSpacing = 10f;

            font = new PdfStandardFont(PdfFontFamily.TimesRoman, 10, PdfFontStyle.Bold);

            //Apply formattings to list
            list.Font         = font;
            list.StringFormat = format;

            //Set list indent
            list.Indent = 10;

            //Add items to the list
            list.Items.Add("List of Essential Studio products");
            list.Items.Add("IO products");

            //Set text indent
            list.TextIndent = 10;

            //Create Ordered list as sublist of parent list
            PdfOrderedList subList = new PdfOrderedList();

            subList.Marker.Brush  = PdfBrushes.Black;
            subList.Indent        = 20;
            list.Items[0].SubList = subList;

            //Set format for sub list
            font                 = new PdfStandardFont(PdfFontFamily.TimesRoman, 10, PdfFontStyle.Italic);
            subList.Font         = font;
            subList.StringFormat = format;
            foreach (string s in products)
            {
                //Add items
                subList.Items.Add(string.Concat("Essential ", s));
            }

            //Create unorderd sublist for the second item of parent list
            PdfUnorderedList SubsubList = new PdfUnorderedList();

            SubsubList.Marker.Brush = PdfBrushes.Black;
            SubsubList.Indent       = 20;
            list.Items[1].SubList   = SubsubList;

            string basePath = _hostingEnvironment.WebRootPath;
            string dataPath = string.Empty;

            dataPath = basePath + @"/PDF/";

            //Read the file
            FileStream file = new FileStream(ResolveApplicationPath("logo.png"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            PdfImage image = PdfImage.FromStream(file);

            font                    = new PdfStandardFont(PdfFontFamily.TimesRoman, 10, PdfFontStyle.Regular);
            SubsubList.Font         = font;
            SubsubList.StringFormat = format;

            //Add sub items
            SubsubList.Items.Add("Essential PDF: It is a .NET library with the capability to produce Adobe PDF files. It features a full-fledged object model for the easy creation of PDF files from any .NET language. It does not use any external libraries and is built from scratch in C#. It can be used on the server side (ASP.NET or any other environment) or with Windows Forms applications. Essential PDF supports many features for creating a PDF document. Drawing Text, Images, Shapes, etc can be drawn easily in the PDF document.");
            SubsubList.Items.Add("Essential DocIO: It is a .NET library that can read and write Microsoft Word files. It features a full-fledged object model similar to the Microsoft Office COM libraries. It does not use COM interop and is built from scratch in C#. It can be used on systems that do not have Microsoft Word installed. Here are some of the most common questions that arise regarding the usage and functionality of Essential DocIO.");
            SubsubList.Items.Add("Essential XlsIO: It is a .NET library that can read and write Microsoft Excel files (BIFF 8 format). It features a full-fledged object model similar to the Microsoft Office COM libraries. It does not use COM interop and is built from scratch in C#. It can be used on systems that do not have Microsoft Excel installed, making it an excellent reporting engine for tabular data. ");

            //Set image as marker
            SubsubList.Marker.Image = image;

            //Draw list
            list.Draw(page, new RectangleF(0, 130, page.Graphics.ClientSize.Width, page.Graphics.ClientSize.Height));

            //Save the PDF to the MemoryStream
            MemoryStream ms = new MemoryStream();

            document.Save(ms);

            //If the position is not set to '0' then the PDF will be empty.
            ms.Position = 0;
            //Close the PDF document.
            document.Close(true);
            return(ms);
        }
        void OnButtonClicked(object sender, EventArgs e)
        {
            doc = new PdfDocument();
            doc.PageSettings.Margins.All = 0;
            page = doc.Pages.Add();
            PdfGraphics g = page.Graphics;

            PdfFont headerFont     = new PdfStandardFont(PdfFontFamily.TimesRoman, 35);
            PdfFont subHeadingFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 16);

            g.DrawRectangle(new PdfSolidBrush(gray), new RectangleF(0, 0, page.Graphics.ClientSize.Width, page.Graphics.ClientSize.Height));
            g.DrawRectangle(new PdfSolidBrush(black), new RectangleF(0, 0, page.Graphics.ClientSize.Width, 130));
            g.DrawRectangle(new PdfSolidBrush(white), new RectangleF(0, 400, page.Graphics.ClientSize.Width, page.Graphics.ClientSize.Height - 450));
            g.DrawString("Enterprise", headerFont, new PdfSolidBrush(violet), new PointF(10, 20));
            g.DrawRectangle(new PdfSolidBrush(violet), new RectangleF(10, 63, 140, 35));
            g.DrawString("Reporting Solutions", subHeadingFont, new PdfSolidBrush(black), new PointF(15, 70));

            PdfLayoutResult result = HeaderPoints("Develop cloud-ready reporting applications in as little as 20% of the time.", 15);

            result = HeaderPoints("Proven, reliable platform thousands of users over the past 10 years.", result.Bounds.Bottom + 15);
            result = HeaderPoints("Microsoft Excel, Word, Adobe PDF, RDL display and editing.", result.Bounds.Bottom + 15);
            result = HeaderPoints("Why start from scratch? Rely on our dependable solution frameworks", result.Bounds.Bottom + 15);

            result = BodyContent("Deployment-ready framework tailored to your needs.", result.Bounds.Bottom + 45);
            result = BodyContent("Our architects and developers have years of reporting experience.", result.Bounds.Bottom + 25);
            result = BodyContent("Solutions available for web, desktop, and mobile applications.", result.Bounds.Bottom + 25);
            result = BodyContent("Backed by our end-to-end product maintenance infrastructure.", result.Bounds.Bottom + 25);
            result = BodyContent("The quickest path from concept to delivery.", result.Bounds.Bottom + 25);

            PdfPen redPen = new PdfPen(PdfBrushes.Red, 2);

            g.DrawLine(redPen, new PointF(40, result.Bounds.Bottom + 92), new PointF(40, result.Bounds.Bottom + 145));
            float          headerBulletsXposition = 40;
            PdfTextElement txtElement             = new PdfTextElement("The Experts");

            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20);
            txtElement.Draw(page, new RectangleF(headerBulletsXposition + 5, result.Bounds.Bottom + 90, 450, 200));

            PdfPen violetPen = new PdfPen(PdfBrushes.Violet, 2);

            g.DrawLine(violetPen, new PointF(headerBulletsXposition + 280, result.Bounds.Bottom + 92), new PointF(headerBulletsXposition + 280, result.Bounds.Bottom + 145));
            txtElement      = new PdfTextElement("Accurate Estimates");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20);
            result          = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 290, result.Bounds.Bottom + 90, 450, 200));

            txtElement      = new PdfTextElement("A substantial number of .NET reporting applications use our frameworks");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11, PdfFontStyle.Regular);
            result          = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 5, result.Bounds.Bottom + 5, 250, 200));


            txtElement      = new PdfTextElement("Given our expertise, you can expect estimates to be accurate.");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11, PdfFontStyle.Regular);
            result          = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 290, result.Bounds.Y, 250, 200));


            PdfPen greenPen = new PdfPen(PdfBrushes.Green, 2);

            g.DrawLine(greenPen, new PointF(40, result.Bounds.Bottom + 32), new PointF(40, result.Bounds.Bottom + 85));

            txtElement      = new PdfTextElement("Product Licensing");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20);
            txtElement.Draw(page, new RectangleF(headerBulletsXposition + 5, result.Bounds.Bottom + 30, 450, 200));

            PdfPen bluePen = new PdfPen(PdfBrushes.Blue, 2);

            g.DrawLine(bluePen, new PointF(headerBulletsXposition + 280, result.Bounds.Bottom + 32), new PointF(headerBulletsXposition + 280, result.Bounds.Bottom + 85));
            txtElement      = new PdfTextElement("About Syncfusion");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20);
            result          = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 290, result.Bounds.Bottom + 30, 450, 200));

            txtElement      = new PdfTextElement("Solution packages can be combined with product licensing for great cost savings.");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11, PdfFontStyle.Regular);
            result          = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 5, result.Bounds.Bottom + 5, 250, 200));


            txtElement      = new PdfTextElement("Syncfusion has more than 7,000 customers including large financial institutions and Fortune 100 companies.");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11, PdfFontStyle.Regular);
            result          = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 290, result.Bounds.Y, 250, 200));

            Stream imgStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Assets.Reporting-Edition.jpg");

            g.DrawImage(PdfImage.FromStream(imgStream), 280, 600, 300, 170);

            g.DrawString("All trademarks mentioned belong to their owners.", new PdfStandardFont(PdfFontFamily.TimesRoman, 8, PdfFontStyle.Italic), PdfBrushes.White, new PointF(10, g.ClientSize.Height - 30));
            PdfTextWebLink linkAnnot = new PdfTextWebLink();

            linkAnnot.Url   = "http://www.syncfusion.com";
            linkAnnot.Text  = "www.syncfusion.com";
            linkAnnot.Font  = new PdfStandardFont(PdfFontFamily.TimesRoman, 8, PdfFontStyle.Italic);
            linkAnnot.Brush = PdfBrushes.White;
            linkAnnot.DrawTextWebLink(page, new PointF(g.ClientSize.Width - 100, g.ClientSize.Height - 30));
            MemoryStream stream = new MemoryStream();

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

            if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows)
            {
                Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("GettingStarted.pdf", "application/pdf", stream);
            }
            else
            {
                Xamarin.Forms.DependencyService.Get <ISave>().Save("GettingStarted.pdf", "application/pdf", stream);
            }
        }
Beispiel #23
0
        public string SaveRightMovePdf(RightMoveModel rightMoveModel)
        {
            try
            {
                PdfLoadedDocument loadedDocument = new PdfLoadedDocument(new FileStream(templatePath, FileMode.Open));

                if (!Directory.Exists(archiveFolder))
                {
                    Directory.CreateDirectory(archiveFolder);
                }

                if (loadedDocument.PageCount > 0)
                {
                    PdfLoadedPage pdfLoadedPage = loadedDocument.Pages[1] as PdfLoadedPage;

                    PdfTemplate pdfTemplate = new PdfTemplate(900, 600);

                    PdfFont pdfFont = new PdfStandardFont(PdfFontFamily.Helvetica, 15);

                    PdfBrush brush = new PdfSolidBrush(SfDrawing.Color.Black);

                    byte[] imageBytes  = new WebClient().DownloadData(rightMoveModel.PropertyMainPicture);
                    Stream imageStream = new MemoryStream(imageBytes);

                    pdfTemplate.Graphics.DrawString($"Property Address: {rightMoveModel.PropertyAddress}", pdfFont, brush, 100, 30);
                    pdfTemplate.Graphics.DrawString($"Property Type: {rightMoveModel.PropertyType}", pdfFont, brush, 100, 50);
                    pdfTemplate.Graphics.DrawString($"PropertyPrice: {rightMoveModel.PropertyPrice} ", pdfFont, brush, 100, 70);
                    pdfTemplate.Graphics.DrawImage(PdfImage.FromStream(imageStream), new SfDrawing.PointF(100, 100), new SfDrawing.SizeF(400, 400));

                    pdfLoadedPage.Graphics.DrawPdfTemplate(pdfTemplate, SfDrawing.PointF.Empty);

                    string rawName = rightMoveModel
                                     .PropertyUrl
                                     .Replace("/", "")
                                     .Replace("-", "")
                                     .Replace(".", "")
                                     .Replace(":", "")
                                     .Replace("//", "");

                    string fileName = Regex.Match(rawName, @"(\d+(?:\.\d{1,2})?)").Value;

                    PdfDocument propertyHeatMapPdfDocument = htmlConverter.Convert(rightMoveModel.PropertyHeatHtmlString, string.Empty);
                    PdfDocument homeCoUKHtmlPdfDocument    = htmlConverter.Convert(rightMoveModel.HomeCoUKHtmlString, string.Empty);

                    string tempPropertyHeatMap = Path.Combine(tempFolder, $"propertyHeatMap{fileName}.pdf");

                    using (FileStream propertyHeatMapStream = new FileStream(tempPropertyHeatMap, FileMode.Create))
                    {
                        propertyHeatMapPdfDocument.Save(propertyHeatMapStream);
                        propertyHeatMapPdfDocument.Close(true);
                        propertyHeatMapPdfDocument.Dispose();

                        propertyHeatMapStream.Close();
                        propertyHeatMapStream.Dispose();
                    }

                    string tempHomeCoUK = Path.Combine(tempFolder, $"homeCoUK{fileName}.pdf");

                    using (FileStream homeCoUKHtmlPdfStream = new FileStream(tempHomeCoUK, FileMode.Create))
                    {
                        homeCoUKHtmlPdfDocument.Save(homeCoUKHtmlPdfStream);
                        homeCoUKHtmlPdfDocument.Close(true);
                        homeCoUKHtmlPdfDocument.Dispose();

                        homeCoUKHtmlPdfStream.Close();
                        homeCoUKHtmlPdfStream.Dispose();
                    }

                    using (FileStream propertyHeatMapReadStream = new FileStream(tempPropertyHeatMap, FileMode.Open))
                    {
                        PdfLoadedDocument tempPropertyHeatMapDocument = new PdfLoadedDocument(propertyHeatMapReadStream);
                        loadedDocument.ImportPage(tempPropertyHeatMapDocument, 0);

                        propertyHeatMapReadStream.Close();
                        propertyHeatMapReadStream.Dispose();
                    }

                    using (FileStream homeCoUKReadStream = new FileStream(tempHomeCoUK, FileMode.Open))
                    {
                        PdfLoadedDocument tempHomeCoUKDocument = new PdfLoadedDocument(homeCoUKReadStream);

                        loadedDocument.ImportPage(tempHomeCoUKDocument, 0);

                        homeCoUKReadStream.Close();
                        homeCoUKReadStream.Dispose();
                    }

                    string savePath = Path.Combine(archiveFolder, $"{fileName}.pdf");

                    using (FileStream saveStream = new FileStream(savePath, FileMode.Create))
                    {
                        loadedDocument.Save(saveStream);
                        loadedDocument.Close(true);
                        loadedDocument.Dispose();
                        saveStream.Close();
                        saveStream.Dispose();
                    }

                    return($"file successfully saved at: {savePath}");
                }
                else
                {
                    Console.WriteLine("Invalid PDF file");
                    return($"Invalid PDF file");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Unable to save the file. {ex.Message}");

                return($"Unable to save the file");
            }
        }
        void OnButtonClicked(object sender, EventArgs e)
        {
            PdfDocument document = null;

            if (this.comformance.Items[this.comformance.SelectedIndex] == "PDF/A-1a")
            {
                //Create a new PDF document
                document = new PdfDocument(PdfConformanceLevel.Pdf_A1A);
            }
            else if (this.comformance.Items[this.comformance.SelectedIndex] == "PDF/A-1b")
            {
                document = new PdfDocument(PdfConformanceLevel.Pdf_A1B);
            }
            else if (this.comformance.Items[this.comformance.SelectedIndex] == "PDF/A-2a")
            {
                document = new PdfDocument(PdfConformanceLevel.Pdf_A2A);
            }
            else if (this.comformance.Items[this.comformance.SelectedIndex] == "PDF/A-2b")
            {
                document = new PdfDocument(PdfConformanceLevel.Pdf_A2B);
            }
            else if (this.comformance.Items[this.comformance.SelectedIndex] == "PDF/A-2u")
            {
                document = new PdfDocument(PdfConformanceLevel.Pdf_A2U);
            }
            else
            {
                if (this.comformance.Items[this.comformance.SelectedIndex] == "PDF/A-3a")
                {
                    document = new PdfDocument(PdfConformanceLevel.Pdf_A3A);
                }
                else if (this.comformance.Items[this.comformance.SelectedIndex] == "PDF/A-3b")
                {
                    document = new PdfDocument(PdfConformanceLevel.Pdf_A3B);
                }
                else if (this.comformance.Items[this.comformance.SelectedIndex] == "PDF/A-3u")
                {
                    document = new PdfDocument(PdfConformanceLevel.Pdf_A3U);
                }
#if COMMONSB
                Stream imgStream = typeof(Conformance).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Samples.Assets.Products.xml");
#else
                Stream imgStream = typeof(Conformance).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.PDF.Samples.Assets.Products.xml");
#endif

                PdfAttachment attachment = new PdfAttachment("PDF_A.xml", imgStream);
                attachment.Relationship     = PdfAttachmentRelationship.Alternative;
                attachment.ModificationDate = DateTime.Now;

                attachment.Description = "PDF_A";

                attachment.MimeType = "application/xml";

                document.Attachments.Add(attachment);
            }
            //Add a page
            PdfPage page = document.Pages.Add();

            //Create font
#if COMMONSB
            Stream arialFontStream = typeof(Conformance).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Samples.Assets.arial.ttf");
            Stream imageStream     = typeof(Conformance).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Samples.Assets.AdventureCycle.jpg");
#else
            Stream arialFontStream = typeof(Conformance).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.PDF.Samples.Assets.arial.ttf");
            Stream imageStream     = typeof(Conformance).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.PDF.Samples.Assets.AdventureCycle.jpg");
#endif
            PdfFont font = new PdfTrueTypeFont(arialFontStream, 14);

            //Create PDF graphics for the page.
            PdfGraphics graphics = page.Graphics;
            //Load the image from the disk.
            PdfImage img = PdfImage.FromStream(imageStream);
            //Draw the image in the specified location and size.
            graphics.DrawImage(img, new RectangleF(150, 30, 200, 100));


            PdfTextElement textElement = new PdfTextElement("Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based," +
                                                            " is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, " +
                                                            "European and Asian commercial markets. While its base operation is located in Bothell, Washington with 290 employees, several regional" +
                                                            " sales teams are located throughout their market base.")
            {
                Font = font
            };
            PdfLayoutResult layoutResult = textElement.Draw(page, new RectangleF(0, 150, page.GetClientSize().Width, page.GetClientSize().Height));


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

            //Close the PDF document.
            document.Close();

            stream.Position = 0;

            if (Device.RuntimePlatform == Device.UWP)
            {
                Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("PDF_A.pdf", "application/pdf", stream);
            }
            else
            {
                Xamarin.Forms.DependencyService.Get <ISave>().Save("PDF_A.pdf", "application/pdf", stream);
            }
        }
Beispiel #25
0
        void OnButtonClicked(object sender, EventArgs e)
        {
            doc = new PdfDocument();
            doc.PageSettings.Margins.All = 0;
            page = doc.Pages.Add();
            PdfGraphics g = page.Graphics;

            PdfFont headerFont     = new PdfStandardFont(PdfFontFamily.TimesRoman, 35);
            PdfFont subHeadingFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 16);

            g.DrawRectangle(new PdfSolidBrush(gray), new RectangleF(0, 0, page.Graphics.ClientSize.Width, page.Graphics.ClientSize.Height));
            g.DrawRectangle(new PdfSolidBrush(black), new RectangleF(0, 0, page.Graphics.ClientSize.Width, 130));
            g.DrawRectangle(new PdfSolidBrush(white), new RectangleF(0, 400, page.Graphics.ClientSize.Width, page.Graphics.ClientSize.Height - 450));
            g.DrawString("Syncfusion", headerFont, new PdfSolidBrush(violet), new PointF(10, 20));
            g.DrawRectangle(new PdfSolidBrush(violet), new RectangleF(10, 63, 155, 35));
            g.DrawString("File Formats", subHeadingFont, new PdfSolidBrush(black), new PointF(45, 70));

            PdfLayoutResult result = HeaderPoints("Optimized for usage in a server environment where spread and low memory usage in critical.", 15);

            result = HeaderPoints("Proven, reliable platform thousands of users over the past 10 years.", result.Bounds.Bottom + 15);
            result = HeaderPoints("Microsoft Excel, Word, Presentation, PDF and PDF Viewer.", result.Bounds.Bottom + 15);
            result = HeaderPoints("Why start from scratch? Rely on our dependable solution frameworks.", result.Bounds.Bottom + 15);

            result = BodyContent("Deployment-ready framework tailored to your needs.", result.Bounds.Bottom + 45);
            result = BodyContent("Enable your applications to read and write file formats documents easily.", result.Bounds.Bottom + 25);
            result = BodyContent("Solutions available for web, desktop, and mobile applications.", result.Bounds.Bottom + 25);
            result = BodyContent("Backed by our end-to-end product maintenance infrastructure.", result.Bounds.Bottom + 25);
            result = BodyContent("The quickest path from concept to delivery.", result.Bounds.Bottom + 25);

            PdfPen redPen = new PdfPen(PdfBrushes.Red, 2);

            g.DrawLine(redPen, new PointF(40, result.Bounds.Bottom + 92), new PointF(40, result.Bounds.Bottom + 145));
            float          headerBulletsXposition = 40;
            PdfTextElement txtElement             = new PdfTextElement("The Experts");

            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20);
            txtElement.Draw(page, new RectangleF(headerBulletsXposition + 5, result.Bounds.Bottom + 90, 450, 200));

            PdfPen violetPen = new PdfPen(PdfBrushes.Violet, 2);

            g.DrawLine(violetPen, new PointF(headerBulletsXposition + 280, result.Bounds.Bottom + 92), new PointF(headerBulletsXposition + 280, result.Bounds.Bottom + 145));
            txtElement      = new PdfTextElement("Accurate Estimates");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20);
            result          = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 290, result.Bounds.Bottom + 90, 450, 200));

            txtElement      = new PdfTextElement("A substantial number of .NET reporting applications use our frameworks.");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11, PdfFontStyle.Regular);
            result          = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 5, result.Bounds.Bottom + 5, 250, 200));


            txtElement      = new PdfTextElement("Given our expertise, you can expect estimates to be accurate.");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11, PdfFontStyle.Regular);
            result          = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 290, result.Bounds.Y, 250, 200));


            PdfPen greenPen = new PdfPen(PdfBrushes.Green, 2);

            g.DrawLine(greenPen, new PointF(40, result.Bounds.Bottom + 32), new PointF(40, result.Bounds.Bottom + 85));

            txtElement      = new PdfTextElement("No-Hassle Licensing");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20);
            txtElement.Draw(page, new RectangleF(headerBulletsXposition + 5, result.Bounds.Bottom + 30, 450, 200));

            PdfPen bluePen = new PdfPen(PdfBrushes.Blue, 2);

            g.DrawLine(bluePen, new PointF(headerBulletsXposition + 280, result.Bounds.Bottom + 32), new PointF(headerBulletsXposition + 280, result.Bounds.Bottom + 85));
            txtElement      = new PdfTextElement("About Syncfusion");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20);
            result          = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 290, result.Bounds.Bottom + 30, 450, 200));

            txtElement      = new PdfTextElement("No royalties, run time, or server deployment fees means no surprises.");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11, PdfFontStyle.Regular);
            result          = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 5, result.Bounds.Bottom + 5, 250, 200));


            txtElement      = new PdfTextElement("Syncfusion is the enterprise technology partner of choice for software development, delivering a board range of web, mobile, and desktop controls.");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11, PdfFontStyle.Regular);
            result          = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 290, result.Bounds.Y, 250, 200));

            Stream imgStream = typeof(GettingStartedPDF).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Assets.Xamarin_bannerEdit.jpg");

            g.DrawImage(PdfImage.FromStream(imgStream), 180, 630, 280, 150);

            g.DrawString("All trademarks mentioned belong to their owners.", new PdfStandardFont(PdfFontFamily.TimesRoman, 8, PdfFontStyle.Italic), PdfBrushes.White, new PointF(10, g.ClientSize.Height - 30));
            PdfTextWebLink linkAnnot = new PdfTextWebLink();

            linkAnnot.Url   = "http://www.syncfusion.com";
            linkAnnot.Text  = "www.syncfusion.com";
            linkAnnot.Font  = new PdfStandardFont(PdfFontFamily.TimesRoman, 8, PdfFontStyle.Italic);
            linkAnnot.Brush = PdfBrushes.White;
            linkAnnot.DrawTextWebLink(page, new PointF(g.ClientSize.Width - 100, g.ClientSize.Height - 30));
            MemoryStream stream = new MemoryStream();

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

            if (stream != null)
            {
                SaveAndroid androidSave = new SaveAndroid();
                androidSave.Save("GettingStarted.pdf", "application/pdf", stream, m_context);
            }
        }
Beispiel #26
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);
        }
Beispiel #27
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;
        }
Beispiel #28
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);
        }
Beispiel #29
0
        public ActionResult InteractiveFeatures(string InsideBrowser)
        {
            #region Field Definitions
            document = new PdfDocument();
            document.PageSettings.Margins.All = 0;
            document.PageSettings.Size        = new SizeF(PdfPageSize.A4.Width, 600);
            interactivePage = document.Pages.Add();
            PdfGraphics g    = interactivePage.Graphics;
            RectangleF  rect = new RectangleF(0, 0, interactivePage.Graphics.ClientSize.Width, 100);

            PdfBrush whiteBrush  = new PdfSolidBrush(white);
            PdfPen   whitePen    = new PdfPen(white, 5);
            PdfBrush purpleBrush = new PdfSolidBrush(new PdfColor(255, 158, 0, 160));
            PdfFont  font        = new PdfStandardFont(PdfFontFamily.Helvetica, 25);
            Syncfusion.Drawing.Color maroonColor = Color.FromArgb(255, 188, 32, 60);
            Syncfusion.Drawing.Color orangeColor = Color.FromArgb(255, 255, 167, 73);
            #endregion

            #region Header
            g.DrawRectangle(purpleBrush, rect);
            g.DrawPie(whitePen, whiteBrush, new RectangleF(-20, 35, 700, 200), 20, -180);
            g.DrawRectangle(whiteBrush, new RectangleF(0, 99.5f, 700, 200));
            g.DrawString("Invoice", new PdfStandardFont(PdfFontFamily.TimesRoman, 24), PdfBrushes.White, new PointF(500, 10));

            string basePath = _hostingEnvironment.WebRootPath;
            string dataPath = string.Empty;
            dataPath = basePath + @"/PDF/";

            //Read the file
            FileStream file = new FileStream(dataPath + "AdventureCycle.jpg", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            g.DrawImage(PdfImage.FromStream(file), new RectangleF(100, 70, 390, 130));
            #endregion

            #region Body

            //Invoice Number
            Random invoiceNumber = new Random();
            g.DrawString("Invoice No: " + invoiceNumber.Next().ToString(), new PdfStandardFont(PdfFontFamily.Helvetica, 14), new PdfSolidBrush(maroonColor), new PointF(50, 210));
            g.DrawString("Date: ", new PdfStandardFont(PdfFontFamily.Helvetica, 14), new PdfSolidBrush(maroonColor), new PointF(350, 210));

            //Current Date
            PdfTextBoxField textBoxField = new PdfTextBoxField(interactivePage, "date");
            textBoxField.Font          = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
            textBoxField.Bounds        = new RectangleF(384, 204, 150, 30);
            textBoxField.ForeColor     = new PdfColor(maroonColor);
            textBoxField.ReadOnly      = true;
            document.Actions.AfterOpen = new PdfJavaScriptAction(@"var newdate = new Date(); 
            var thisfieldis = this.getField('date');  
            
            var theday = util.printd('dddd',newdate); 
            var thedate = util.printd('d',newdate); 
            var themonth = util.printd('mmmm',newdate);
            var theyear = util.printd('yyyy',newdate);  
            
            thisfieldis.strokeColor=color.transparent;
            thisfieldis.value = theday + ' ' + thedate + ', ' + themonth + ' ' + theyear ;");
            document.Form.Fields.Add(textBoxField);

            //invoice table
            PdfLightTable table = new PdfLightTable();
            table.Style.ShowHeader = true;
            g.DrawRectangle(new PdfSolidBrush(Syncfusion.Drawing.Color.FromArgb(238, 238, 238, 248)), new RectangleF(50, 240, 500, 140));

            //Header Style
            PdfCellStyle headerStyle = new PdfCellStyle();
            headerStyle.Font            = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Bold);
            headerStyle.TextBrush       = whiteBrush;
            headerStyle.StringFormat    = new PdfStringFormat(PdfTextAlignment.Center);
            headerStyle.BackgroundBrush = new PdfSolidBrush(orangeColor);
            headerStyle.BorderPen       = new PdfPen(whiteBrush, 0);
            table.Style.HeaderStyle     = headerStyle;

            //Cell Style
            PdfCellStyle bodyStyle = new PdfCellStyle();
            bodyStyle.Font           = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
            bodyStyle.StringFormat   = new PdfStringFormat(PdfTextAlignment.Left);
            bodyStyle.BorderPen      = new PdfPen(whiteBrush, 0);
            table.Style.DefaultStyle = bodyStyle;
            table.DataSource         = GetProductReport(_hostingEnvironment.WebRootPath);
            table.Columns[0].Width   = 90;
            table.Columns[1].Width   = 160;
            table.Columns[3].Width   = 100;
            table.Columns[4].Width   = 65;
            table.Style.CellPadding  = 3;
            table.BeginCellLayout   += table_BeginCellLayout;

            PdfLightTableLayoutResult result = table.Draw(interactivePage, new RectangleF(50, 240, 500, 140));

            g.DrawString("Grand Total:", new PdfStandardFont(PdfFontFamily.Helvetica, 12), new PdfSolidBrush(Syncfusion.Drawing.Color.FromArgb(255, 255, 167, 73)), new PointF(result.Bounds.Right - 150, result.Bounds.Bottom));
            CreateTextBox(interactivePage, "GrandTotal", "Grand Total", new RectangleF(result.Bounds.Width - 15, result.Bounds.Bottom - 2, 66, 18), true, "");


            //Send to Server
            PdfButtonField sendButton = new PdfButtonField(interactivePage, "OrderOnline");
            sendButton.Bounds      = new RectangleF(200, result.Bounds.Bottom + 70, 80, 25);
            sendButton.BorderColor = white;
            sendButton.BackColor   = maroonColor;
            sendButton.ForeColor   = white;
            sendButton.Text        = "Order Online";
            PdfSubmitAction submitAction = new PdfSubmitAction("http://stevex.net/dump.php");
            submitAction.DataFormat    = SubmitDataFormat.Html;
            sendButton.Actions.MouseUp = submitAction;
            document.Form.Fields.Add(sendButton);

            //Order by Mail
            PdfButtonField sendMail = new PdfButtonField(interactivePage, "sendMail");
            sendMail.Bounds      = new RectangleF(300, result.Bounds.Bottom + 70, 80, 25);
            sendMail.Text        = "Order By Mail";
            sendMail.BorderColor = white;
            sendMail.BackColor   = maroonColor;
            sendMail.ForeColor   = white;

            // Create a javascript action.
            PdfJavaScriptAction javaAction = new PdfJavaScriptAction("address = app.response(\"Enter an e-mail address.\",\"SEND E-MAIL\",\"\");"
                                                                     + "var aSubmitFields = [];"
                                                                     + "for( var i = 0 ; i < this.numFields; i++){"
                                                                     + "aSubmitFields[i] = this.getNthFieldName(i);"
                                                                     + "}"
                                                                     + "if (address){ cmdLine = \"mailto:\" + address;this.submitForm(cmdLine,true,false,aSubmitFields);}");

            sendMail.Actions.MouseUp = javaAction;
            document.Form.Fields.Add(sendMail);

            //Print
            PdfButtonField printButton = new PdfButtonField(interactivePage, "print");
            printButton.Bounds          = new RectangleF(400, result.Bounds.Bottom + 70, 80, 25);
            printButton.BorderColor     = white;
            printButton.BackColor       = maroonColor;
            printButton.ForeColor       = white;
            printButton.Text            = "Print";
            printButton.Actions.MouseUp = new PdfJavaScriptAction("this.print (true); ");
            document.Form.Fields.Add(printButton);
            file = new FileStream(dataPath + "Product Catalog.pdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            PdfAttachment attachment = new PdfAttachment("Product Catalog.pdf", file);
            attachment.ModificationDate = DateTime.Now;
            attachment.Description      = "Specification";
            document.Attachments.Add(attachment);

            //Open Specification
            PdfButtonField openSpecificationButton = new PdfButtonField(interactivePage, "openSpecification");
            openSpecificationButton.Bounds          = new RectangleF(50, result.Bounds.Bottom + 20, 87, 15);
            openSpecificationButton.TextAlignment   = PdfTextAlignment.Left;
            openSpecificationButton.Font            = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
            openSpecificationButton.BorderStyle     = PdfBorderStyle.Underline;
            openSpecificationButton.BorderColor     = orangeColor;
            openSpecificationButton.BackColor       = new PdfColor(255, 255, 255);
            openSpecificationButton.ForeColor       = orangeColor;
            openSpecificationButton.Text            = "Open Specification";
            openSpecificationButton.Actions.MouseUp = new PdfJavaScriptAction("this.exportDataObject({ cName: 'Product Catalog.pdf', nLaunch: 2 });");
            document.Form.Fields.Add(openSpecificationButton);

            RectangleF     uriAnnotationRectangle = new RectangleF(interactivePage.Graphics.ClientSize.Width - 160, interactivePage.Graphics.ClientSize.Height - 30, 80, 20);
            PdfTextWebLink linkAnnot = new PdfTextWebLink();
            linkAnnot.Url   = "http://www.adventure-works.com";
            linkAnnot.Text  = "http://www.adventure-works.com";
            linkAnnot.Font  = new PdfStandardFont(PdfFontFamily.Helvetica, 8);
            linkAnnot.Brush = PdfBrushes.White;
            linkAnnot.DrawTextWebLink(interactivePage, uriAnnotationRectangle.Location);
            #endregion

            #region Footer
            g.DrawRectangle(purpleBrush, new RectangleF(0, interactivePage.Graphics.ClientSize.Height - 100, interactivePage.Graphics.ClientSize.Width, 100));
            g.DrawPie(whitePen, whiteBrush, new RectangleF(-20, interactivePage.Graphics.ClientSize.Height - 250, 700, 200), 0, 180);
            #endregion

            //Save the PDF to the MemoryStream
            MemoryStream ms = new MemoryStream();

            document.Save(ms);

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

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

            //Download the PDF document in the browser.
            FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf");
            fileStreamResult.FileDownloadName = "Interactive features.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);
        }