private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            Stream            docStream = typeof(StampDocument).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.Essential_Studio.pdf");
            PdfLoadedDocument ldoc      = new PdfLoadedDocument(docStream);

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

            foreach (PdfPageBase lPage in ldoc.Pages)
            {
                PdfGraphics      g     = lPage.Graphics;
                PdfGraphicsState state = g.Save();
                g.SetTransparency(0.25f);
                g.RotateTransform(-40);
                g.DrawString(stampText.Text, font, PdfPens.Red, PdfBrushes.Red, new PointF(-150, 450));

                if (imagewatermark.IsChecked.Value)
                {
                    Stream   imagestream = typeof(StampDocument).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.Ani.gif");
                    PdfImage image       = new PdfBitmap(imagestream);
                    g.Restore(state);
                    g.SetTransparency(0.25f);
                    g.DrawImage(image, 0, 0, lPage.Graphics.ClientSize.Width, lPage.Graphics.ClientSize.Height);
                    imagestream.Dispose();
                }
            }
            MemoryStream stream = new MemoryStream();
            await ldoc.SaveAsync(stream);

            ldoc.Close(true);
            Save(stream, "StampDocument.pdf");

            docStream.Dispose();
        }
示例#2
0
        private void btnImport_Click(object sender, System.EventArgs e)
        {
            PdfLoadedDocument lDoc = new PdfLoadedDocument(txtUrl.Tag.ToString());
            PdfFont           font = new PdfStandardFont(PdfFontFamily.Helvetica, 36f);

            foreach (PdfPageBase lPage in lDoc.Pages)
            {
                PdfGraphics      g     = lPage.Graphics;
                PdfGraphicsState state = g.Save();
                g.SetTransparency(0.25f);
                g.RotateTransform(-40);
                g.DrawString(txtStamp.Text, font, PdfPens.Red, PdfBrushes.Red, new PointF(-150, 450));
                g.Restore(state);

                if (chbWatermark.Checked)
                {
                    g.Save();
#if NETCORE
                    PdfImage image = new PdfBitmap(@"..\..\..\..\..\..\..\..\Common\Images\PDF\Ani.gif");
#else
                    PdfImage image = new PdfBitmap(@"..\..\..\..\..\..\..\Common\Images\PDF\Ani.gif");
#endif
                    g.SetTransparency(0.25f);
                    g.DrawImage(image, 0, 0, lPage.Graphics.ClientSize.Width, lPage.Graphics.ClientSize.Height);
                    g.Restore();
                }
            }


            lDoc.Save("Sample.pdf");

            //Message box confirmation to view the created PDF document.
            if (MessageBox.Show("Do you want to view the PDF file?", "PDF File Created",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Information)
                == DialogResult.Yes)
            {
                //Launching the PDF file using the default Application.[Acrobat Reader]
#if NETCORE
                System.Diagnostics.Process process = new System.Diagnostics.Process();
                process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.pdf")
                {
                    UseShellExecute = true
                };
                process.Start();
#else
                System.Diagnostics.Process.Start("Sample.pdf");
#endif
                this.Close();
            }
            else
            {
                // Exit
                this.Close();
            }
        }
示例#3
0
        void OnButtonClicked(object sender, EventArgs e)
        {
            Stream            docStream = typeof(Stamping).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Assets.Product Catalog.pdf");
            PdfLoadedDocument ldoc      = new PdfLoadedDocument(docStream);

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

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

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

            if (stream != null)
            {
                SaveAndroid androidSave = new SaveAndroid();
                androidSave.Save("Stamping.pdf", "application/pdf", stream, m_context);
            }
        }
示例#4
0
        void OnButtonClicked(object sender, EventArgs e)
        {
            Stream            docStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Assets.Syncfusion_Windows8_whitepaper.pdf");
            PdfLoadedDocument ldoc      = new PdfLoadedDocument(docStream);

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

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

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

            if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows)
            {
                Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("Stamping.pdf", "application/pdf", stream);
            }
            else
            {
                Xamarin.Forms.DependencyService.Get <ISave>().Save("Stamping.pdf", "application/pdf", stream);
            }
        }
示例#5
0
        public ActionResult ImportAndStamp(string Browser, string Stamptext, HttpPostedFileBase file)
        {
            PdfLoadedDocument ldoc = null;

            if (file != null && file.ContentLength > 0)
            {
                ldoc = new PdfLoadedDocument(file.InputStream);

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

                foreach (PdfPageBase lPage in ldoc.Pages)
                {
                    PdfGraphics      graphics = lPage.Graphics;
                    PdfGraphicsState state    = graphics.Save();
                    graphics.SetTransparency(0.25f);
                    graphics.RotateTransform(-40);
                    graphics.DrawString(Stamptext, font, PdfPens.Red, PdfBrushes.Red, new PointF(-150, 450));
                    graphics.Restore(state);
                }
            }
            else
            {
                ViewBag.lab = "NOTE: Please select PDF document.";
                return(View());
            }
            //Stream the output to the browser.
            if (Browser == "Browser")
            {
                return(ldoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open));
            }
            else
            {
                return(ldoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save));
            }
        }
        private async void StampingSample()
        {
            //Load PDF document to stream.
            Stream docStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Assets.Syncfusion_Windows8_whitepaper.pdf");

            MemoryStream stream = new MemoryStream();

            //Load the PDF document into the loaded document object.
            using (PdfLoadedDocument ldoc = new PdfLoadedDocument(docStream))
            {
                //Create font object.
                PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 100f, PdfFontStyle.Regular);

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

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

            stream.Position = 0;

            if (IsToggled)
            {
                //Open in Essential PDF viewer.
                PdfViewerUI pdfViewer = new SampleBrowser.PdfViewerUI();
                pdfViewer.PdfDocumentStream = stream;
                if (Device.Idiom != TargetIdiom.Phone && Device.OS == TargetPlatform.Windows)
                {
                    await PDFViewModel.Navigation.PushModalAsync(new NavigationPage(pdfViewer));
                }
                else
                {
                    await PDFViewModel.Navigation.PushAsync(pdfViewer);
                }
            }
            else
            {
                //Open in default system viewer.
                if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows)
                {
                    Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("Stamping.pdf", "application/pdf", stream);
                }
                else
                {
                    Xamarin.Forms.DependencyService.Get <ISave>().Save("Stamping.pdf", "application/pdf", stream);
                }
            }
        }
示例#7
0
        public IActionResult CreateDocument()
        {
            //Opens the Word template document
            FileStream fileStreamPath = new FileStream(@"wwwroot/test_template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
            {
                //string[] fieldNames = { "ContactName", "CompanyName", "Address", "City", "Country", "Phone" };
                //string[] fieldValues = { "Nancy Davolio", "Syncfusion", "507 - 20th Ave. E.Apt. 2A", "Seattle, WA", "USA", "(206) 555-9857-x5467" };

                string[] fieldNames   = { "firstname", "lastname", "address", "age" };
                string[] fieldValues  = { "Dennis", "Huillca", "APV Agua Buena D-1 San Sebastian", "30" };
                string[] fieldValues2 = { "Roy", "Palacios", "Surco Lima", "31" };
                //Performs the mail merge
                document.MailMerge.Execute(fieldNames, fieldValues);
                document.MailMerge.Execute(fieldNames, fieldValues2);

                //Converts Word document to PDF
                DocIORenderer render      = new DocIORenderer();
                PdfDocument   pdfDocument = render.ConvertToPDF(document);
                render.Dispose();
                //adding the watermark
                PdfGraphics graphics = pdfDocument.Pages[0].Graphics;
                //set the font
                PdfFont          font  = new PdfStandardFont(PdfFontFamily.Helvetica, 60);
                PdfGraphicsState state = graphics.Save();
                graphics.SetTransparency(0.15f);
                graphics.RotateTransform(-30);
                graphics.DrawString("PREVIEW", font, PdfPens.Black, PdfBrushes.Red, new PointF(-40, 450));
                //Saves de pdf to disk
                FileStream outfs = new FileStream(@"wwwroot/foobar.pdf", FileMode.Create, FileAccess.Write);
                pdfDocument.Save(outfs);
                outfs.Close();
                pdfDocument.Close();

                //Saves the Word document to MemoryStream
                MemoryStream stream = new MemoryStream();
                document.Save(stream, FormatType.Docx);
                FileStream fs = new FileStream(@"wwwroot/foobar.docx", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
                document.Save(fs, FormatType.Docx);
                fs.Close();
                //stream.WriteTo(fs);

                stream.Position = 0;
                //Download Word document in the browser
                return(File(stream, "application/msword", "Result.docx"));
            }
        }
示例#8
0
        void OnButtonClicked(object sender, EventArgs e)
        {
            //Load PDF document to stream.
#if COMMONSB
            Stream docStream = typeof(Stamping).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Samples.Assets.Product Catalog.pdf");
#else
            Stream docStream = typeof(Stamping).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.PDF.Samples.Assets.Product Catalog.pdf");
#endif

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

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

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

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

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

            //Open in default system viewer.
            if (Device.RuntimePlatform == Device.UWP)
            {
                Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("Stamping.pdf", "application/pdf", stream);
            }
            else
            {
                Xamarin.Forms.DependencyService.Get <ISave>().Save("Stamping.pdf", "application/pdf", stream);
            }
        }
示例#9
0
        public ActionResult ImportAndStamp(string Browser, string Stamptext, IFormFile file)
        {
            PdfLoadedDocument ldoc = null;

            if (file != null && file.Length > 0)
            {
                ldoc = new PdfLoadedDocument(file.OpenReadStream());

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

                foreach (PdfPageBase lPage in ldoc.Pages)
                {
                    PdfGraphics      graphics = lPage.Graphics;
                    PdfGraphicsState state    = graphics.Save();
                    graphics.SetTransparency(0.25f);
                    graphics.RotateTransform(-40);
                    graphics.DrawString(Stamptext, font, PdfPens.Red, PdfBrushes.Red, new PointF(-150, 450));
                    graphics.Restore(state);
                }
            }
            else
            {
                ViewBag.lab = "NOTE: Please select PDF document.";
                return(View());
            }

            MemoryStream stream = new MemoryStream();

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

            stream.Position = 0;

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

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

            fileStreamResult.FileDownloadName = "Stamp.pdf";
            return(fileStreamResult);
        }
示例#10
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //Get the template PDF file stream from assembly.
            Stream documentStream = typeof(PdfWatermark).GetTypeInfo().Assembly.GetManifestResourceStream("syncfusion.pdfdemos.winui.Assets.pdf_succinctly.pdf");
            //Load the PDF document from stream.
            PdfLoadedDocument loadedDocument = new PdfLoadedDocument(documentStream);
            //Create a new font instance.
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 36f);

            //Adding a watermark text to all the PDF pages.
            foreach (PdfPageBase loadedPage in loadedDocument.Pages)
            {
                //Get the PDF page graphics.
                PdfGraphics graphics = loadedPage.Graphics;
                //Save the current graphics state.
                PdfGraphicsState state = graphics.Save();
                //Set transparency to add a watermark text.
                graphics.SetTransparency(0.25f);
                //Rotate the graphics to add a watermark text with 40 degree.
                graphics.RotateTransform(-40);
                //Draw a watermark text to PDF page graphics.
                graphics.DrawString(stampText.Text, font, PdfPens.Red, PdfBrushes.Red, new PointF(-150, 450));
                //Restore the graphics state.
                graphics.Restore(state);
            }

            //Creating the stream object.
            using (MemoryStream stream = new MemoryStream())
            {
                //Save the document into stream.
                loadedDocument.Save(stream);
                loadedDocument.Close();

                stream.Position = 0;
                //Save the output stream as a file using file picker.
                PdfUtil.Save("PdfWatermark.pdf", stream);
            }
        }
        public ActionResult DrawingShapes(string InsideBrowser)
        {
            // Create a new PDF document.
            PdfDocument doc = new PdfDocument();
            int         i;
            // Create a new page.
            PdfPage page = doc.Pages.Add();
            // Obtain PdfGraphics object.
            PdfGraphics g    = page.Graphics;
            PdfFont     font = new PdfStandardFont(PdfFontFamily.Helvetica, 14, PdfFontStyle.Bold);

            #region Polygon
            PdfPen pen = new PdfPen(Color.Black);
            pen.Width = 3;
            PointF p1 = new PointF(05, 10);
            PointF p2 = new PointF(05, 10);
            PointF p3 = new PointF(60, 70);
            PointF p4 = new PointF(40, 70);

            PointF[] points = { p1, p2, p3, p4 };

            int pointNum = 16;
            points = new PointF[pointNum];
            double       f      = 360.0 / pointNum * Math.PI / 180.0;
            const double r      = 100;
            PointF       center = new PointF(140, 140);

            for (i = 0; i < pointNum; ++i)
            {
                PointF p     = new PointF();
                double theta = i * f;

                p.Y = (float)(Math.Sin(theta) * r + center.Y);
                p.X = (float)(Math.Cos(theta) * r + center.X);

                points[i] = p;
            }

            PdfSolidBrush brush = new PdfSolidBrush(Color.Green);
            pen.Color    = Color.Brown;
            pen.Width    = 10;
            pen.LineJoin = PdfLineJoin.Round;
            g.DrawString("Polygon", font, PdfBrushes.DarkBlue, new PointF(50, 0));
            g.DrawPolygon(pen, brush, points);

            #endregion

            #region  Pie

            RectangleF rect = new RectangleF(200, 50, 200, 200);
            brush.Color = Color.Green;
            pen.Color   = Color.Brown;
            pen.Width   = 10;

            rect.Location = new PointF(20, 280);
            pen.LineJoin  = PdfLineJoin.Round;
            g.DrawString("Pie shape", font, PdfBrushes.DarkBlue, new PointF(50, 250));
            g.DrawPie(pen, brush, rect, 180, 60);
            g.DrawPie(pen, brush, rect, 360 - 60, 60);
            g.DrawPie(pen, brush, rect, 60, 60);

            #endregion

            #region Arc

            g.DrawString("Arcs", font, PdfBrushes.DarkBlue, new PointF(330, 0));
            pen         = new PdfPen(Color.Black);
            pen.Width   = 11;
            pen.LineCap = PdfLineCap.Round;
            pen.Color   = Color.Brown;
            rect        = new RectangleF(310, 40, 200, 200);
            g.DrawArc(pen, rect, 0, 90);

            pen.Color = Color.DarkGreen;
            rect.X   -= 10;
            g.DrawArc(pen, rect, 90, 90);

            pen.Color = Color.Brown;
            rect.Y   -= 10;
            g.DrawArc(pen, rect, 180, 90);

            pen.Color = Color.DarkGreen;
            rect.X   += 10;
            g.DrawArc(pen, rect, 270, 90);

            #endregion

            #region Rectangle
            rect        = new RectangleF(310, 280, 200, 100);
            brush.Color = Color.Green;
            pen.Color   = Color.Brown;
            g.DrawString("Simple Rectangle", font, PdfBrushes.DarkBlue, new PointF(310, 255));
            g.DrawRectangle(pen, brush, rect);
            #endregion

            #region ellipse
            pen  = new PdfPen(Color.Black);
            rect = new RectangleF(270, 400, 160, 1000);
            g.DrawString("Shape with pagination", font, PdfBrushes.DarkBlue, new PointF(300, 390));
            PdfEllipse      ellipse = new PdfEllipse(rect);
            PdfLayoutFormat format  = new PdfLayoutFormat();
            format.Break  = PdfLayoutBreakType.FitPage;
            format.Layout = PdfLayoutType.Paginate;
            ellipse.Brush = PdfBrushes.Brown;
            ellipse.Draw(page, 20, 20, format);

            brush         = new PdfSolidBrush(Color.Black);
            ellipse.Brush = PdfBrushes.DarkGreen;
            ellipse.Draw(page, 40, 40, format);

            #endregion

            #region Transaparency

            page = doc.Pages[1];
            g    = page.Graphics;
            g.DrawString("Transparent Rectangles", font, PdfBrushes.DarkBlue, new PointF(50, 80));
            PdfBrush gBrush;
            rect = new RectangleF(10, 150, 100, 100);

            pen    = new PdfPen(Color.Black);
            gBrush = new PdfSolidBrush(Color.DarkGreen);

            g.DrawRectangle(pen, gBrush, rect);
            gBrush  = new PdfSolidBrush(Color.Brown);
            rect.X += 20;
            rect.Y += 20;
            pen     = new PdfPen(Color.Brown);
            g.SetTransparency(0.7f);
            g.DrawRectangle(pen, gBrush, rect);

            rect.X += 20;
            rect.Y += 20;
            gBrush  = new PdfLinearGradientBrush(rect, Color.DarkGreen, Color.Brown, PdfLinearGradientMode.BackwardDiagonal);
            g.SetTransparency(0.5f);
            g.DrawRectangle(pen, gBrush, rect);

            rect.X += 20;
            rect.Y += 20;
            pen     = new PdfPen(Color.Blue);
            gBrush  = new PdfSolidBrush(Color.Gray);
            g.SetTransparency(0.25f);
            g.DrawRectangle(pen, gBrush, rect);

            rect.X += 20;
            rect.Y += 20;
            pen     = new PdfPen(Color.Black);
            gBrush  = new PdfSolidBrush(Color.Green);
            g.SetTransparency(0.1f);
            g.DrawRectangle(pen, gBrush, rect);

            #endregion

            #region Rectangle with Color space



            PointF location = new PointF(10, 50);
            page = doc.Pages.Add();
            g    = page.Graphics;

            doc.ColorSpace = (PdfColorSpace)i;

            // SolidBrush
            gBrush = new PdfSolidBrush(Color.Red);
            DrawRectangles(location, g, font, gBrush, pen, doc);

            // LinearGradient
            location = new PointF(180, 50);

            PointF point2 = location;

            point2.X += 180;
            gBrush    = new PdfLinearGradientBrush(location, point2, Color.Blue, Color.Red);
            DrawRectangles(location, g, font, gBrush, pen, doc);

            // Raidal Gradient
            location = new PointF(360, 50);
            point2   = location;

            point2 = new PointF(location.X + 50, location.Y + 50);
            //point2.Y += 250;
            //point2.X = 150;
            gBrush = new PdfRadialGradientBrush(point2, 0, point2, 100, Color.Blue, Color.Red);
            (gBrush as PdfRadialGradientBrush).Extend = PdfExtend.Both;
            DrawRectangles(location, g, font, gBrush, pen, doc);

            g.DrawString("Rectangle with color spaces", font, PdfBrushes.DarkBlue, new PointF(150, 0));
            #endregion

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

            doc.Save(ms);

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

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

            //Download the PDF document in the browser.
            FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf");
            fileStreamResult.FileDownloadName = "Shapes.pdf";
            return(fileStreamResult);
        }
        public ActionResult DrawingShapes(string InsideBrowser)
        {
            // Create a new PDF document.
            PdfDocument doc = new PdfDocument();
            int         i;
            // Create a new page.
            PdfPage page = doc.Pages.Add();
            // Obtain PdfGraphics object.
            PdfGraphics g    = page.Graphics;
            PdfFont     font = new PdfStandardFont(PdfFontFamily.Helvetica, 14, PdfFontStyle.Bold);

            #region Polygon
            PdfPen pen = new PdfPen(Color.Black);
            pen.Width = 3;
            PointF p1 = new PointF(05, 10);
            PointF p2 = new PointF(05, 10);
            PointF p3 = new PointF(60, 70);
            PointF p4 = new PointF(40, 70);

            PointF[] points = { p1, p2, p3, p4 };

            int pointNum = 16;
            points = new PointF[pointNum];
            double       f      = 360.0 / pointNum * Math.PI / 180.0;
            const double r      = 100;
            PointF       center = new PointF(140, 140);

            for (i = 0; i < pointNum; ++i)
            {
                PointF p     = new PointF();
                double theta = i * f;

                p.Y = (float)(Math.Sin(theta) * r + center.Y);
                p.X = (float)(Math.Cos(theta) * r + center.X);

                points[i] = p;
            }

            PdfSolidBrush brush = new PdfSolidBrush(Color.Green);
            pen.Color    = Color.Brown;
            pen.Width    = 10;
            pen.LineJoin = PdfLineJoin.Round;
            g.DrawString("Polygon", font, PdfBrushes.DarkBlue, new PointF(50, 0));
            g.DrawPolygon(pen, brush, points);

            #endregion

            #region  Pie

            RectangleF rect = new RectangleF(200, 50, 200, 200);
            brush.Color = Color.Green;
            pen.Color   = Color.Brown;
            pen.Width   = 10;

            rect.Location = new PointF(20, 280);
            pen.LineJoin  = PdfLineJoin.Round;
            g.DrawString("Pie shape", font, PdfBrushes.DarkBlue, new PointF(50, 250));
            g.DrawPie(pen, brush, rect, 180, 60);
            g.DrawPie(pen, brush, rect, 360 - 60, 60);
            g.DrawPie(pen, brush, rect, 60, 60);

            #endregion

            #region Arc

            g.DrawString("Arcs", font, PdfBrushes.DarkBlue, new PointF(330, 0));
            pen         = new PdfPen(Color.Black);
            pen.Width   = 11;
            pen.LineCap = PdfLineCap.Round;
            pen.Color   = Color.Brown;
            rect        = new RectangleF(310, 40, 200, 200);
            g.DrawArc(pen, rect, 0, 90);

            pen.Color = Color.DarkGreen;
            rect.X   -= 10;
            g.DrawArc(pen, rect, 90, 90);

            pen.Color = Color.Brown;
            rect.Y   -= 10;
            g.DrawArc(pen, rect, 180, 90);

            pen.Color = Color.DarkGreen;
            rect.X   += 10;
            g.DrawArc(pen, rect, 270, 90);

            #endregion

            #region Rectangle
            rect        = new RectangleF(310, 280, 200, 100);
            brush.Color = Color.Green;
            pen.Color   = Color.Brown;
            g.DrawString("Simple Rectangle", font, PdfBrushes.DarkBlue, new PointF(310, 255));
            g.DrawRectangle(pen, brush, rect);
            #endregion

            #region ellipse

            // Draw a simple ellipse.
            pen  = new PdfPen(Color.Black);
            rect = new RectangleF(80, 520, 100, 200);
            //page = doc.Pages[0];
            //g = page.Graphics;
            PdfLinearGradientBrush lgBrush = new PdfLinearGradientBrush(rect, Color.DarkGreen, Color.White, 90);

            brush       = new PdfSolidBrush(Color.Black);
            brush.Color = Color.DarkGreen;
            pen.Color   = Color.Brown;
            pen.Width   = 10.0f;
            g.DrawString("Ellipse with Gradient", font, PdfBrushes.DarkBlue, new PointF(50, 490));
            g.DrawEllipse(pen, lgBrush, rect);


            rect = new RectangleF(270, 400, 160, 1000);
            g.DrawString("Shape with pagination", font, PdfBrushes.DarkBlue, new PointF(300, 390));
            PdfEllipse      ellipse = new PdfEllipse(rect);
            PdfLayoutFormat format  = new PdfLayoutFormat();
            format.Break  = PdfLayoutBreakType.FitPage;
            format.Layout = PdfLayoutType.Paginate;
            ellipse.Brush = PdfBrushes.Brown;
            ellipse.Draw(page, 20, 20, format);

            brush         = new PdfSolidBrush(Color.Black);
            ellipse.Brush = PdfBrushes.DarkGreen;
            ellipse.Draw(page, 40, 40, format);

            #endregion

            #region Transaparency

            page = doc.Pages[1];
            g    = page.Graphics;
            g.DrawString("Transparent Rectangles", font, PdfBrushes.DarkBlue, new PointF(50, 80));
            PdfBrush gBrush;
            rect = new RectangleF(10, 150, 100, 100);

            pen    = new PdfPen(Color.Black);
            gBrush = new PdfSolidBrush(Color.DarkGreen);

            g.DrawRectangle(pen, gBrush, rect);
            gBrush  = new PdfSolidBrush(Color.Brown);
            rect.X += 20;
            rect.Y += 20;
            pen     = new PdfPen(Color.Brown);
            g.SetTransparency(0.7f);
            g.DrawRectangle(pen, gBrush, rect);

            rect.X += 20;
            rect.Y += 20;
            gBrush  = new PdfLinearGradientBrush(rect, Color.DarkGreen, Color.Brown, PdfLinearGradientMode.BackwardDiagonal);
            g.SetTransparency(0.5f);
            g.DrawRectangle(pen, gBrush, rect);

            rect.X += 20;
            rect.Y += 20;
            pen     = new PdfPen(Color.Blue);
            gBrush  = new PdfSolidBrush(Color.Gray);
            g.SetTransparency(0.25f);
            g.DrawRectangle(pen, gBrush, rect);

            rect.X += 20;
            rect.Y += 20;
            pen     = new PdfPen(Color.Black);
            gBrush  = new PdfSolidBrush(Color.Green);
            g.SetTransparency(0.1f);
            g.DrawRectangle(pen, gBrush, rect);

            #endregion

            #region Rectangle with Color space



            PointF location = new PointF(10, 50);
            page = doc.Pages.Add();
            g    = page.Graphics;

            doc.ColorSpace = (PdfColorSpace)i;

            // SolidBrush
            gBrush = new PdfSolidBrush(Color.Red);
            DrawRectangles(location, g, font, gBrush, pen, doc);

            // LinearGradient
            location = new PointF(180, 50);

            PointF point2 = location;

            point2.X += 100;
            gBrush    = new PdfLinearGradientBrush(location, point2, Color.Blue, Color.Red);
            DrawRectangles(location, g, font, gBrush, pen, doc);

            // Raidal Gradient
            location  = new PointF(360, 50);
            point2    = location;
            point2.Y += 250;
            point2.X  = 150;
            gBrush    = new PdfRadialGradientBrush(point2, 210, point2, 400, Color.Blue, Color.Red);
            (gBrush as PdfRadialGradientBrush).Extend = PdfExtend.End;
            DrawRectangles(location, g, font, gBrush, pen, doc);

            g.DrawString("Rectangle with color spaces", font, PdfBrushes.DarkBlue, new PointF(150, 0));
            #endregion
            //Stream the output to the browser.
            if (InsideBrowser == "Browser")
            {
                return(doc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open));
            }
            else
            {
                return(doc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save));
            }
        }
示例#13
0
文件: Program.cs 项目: svcqa1/POCs
        public static void updateEffectiveDate(string strSiteUrl, string strUserId, string strPassword, string strEffectiveListName, string strDcrDocId)
        {
            try
            {
                using (var context = new ClientContext(strSiteUrl))
                {
                    SecureString passWord = new SecureString();
                    foreach (char c in strPassword.ToCharArray())
                    {
                        passWord.AppendChar(c);
                    }
                    context.Credentials = new SharePointOnlineCredentials(strUserId, passWord);
                    // Gets list object using the list Url
                    List      oList     = context.Web.Lists.GetByTitle(strEffectiveListName);
                    CamlQuery camlQuery = new CamlQuery();
                    camlQuery.ViewXml = "<View><Query><Where><Eq><FieldRef Name='CE_DCRDocID'/>" +
                                        "<Value Type='Lookup'>" + strDcrDocId +
                                        "</Value></Eq></Where></Query></View>";
                    ListItemCollection collListItem = oList.GetItems(camlQuery);
                    context.Load(collListItem);
                    context.ExecuteQuery();
                    foreach (ListItem item in collListItem)
                    {
                        var filePath = item["FileRef"];
                        docFileName = (string)item["FileLeafRef"];


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

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

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

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

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

                            document.Save(docFileName);
                            document.Close(true);
                            loadedDocument.Close(true);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
示例#14
0
        private FileStreamResult ExportPDF(List <EOD> edo)
        {
            // Load the PDF Template
            Stream pdfStream = System.IO.File.OpenRead(_hostingEnvironment.WebRootPath + @"\assets\templates\CloseShop2.pdf");

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

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

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

            int     numPage = 1;
            PdfPage pdfPage;

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

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

                pdfPage = pdfDocument.Pages[numPage - 1];

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

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

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


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


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


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


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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

                numPage++;
            });

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

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

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

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

            //Add the fields in composite fields.
            PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Page {0} of {1}", pageNumber, count);

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

            compositeField.Bounds = footer.Bounds;

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

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

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

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

            // Close file
            pdfStream.Dispose();

            //Save the document.
            return(File(ms, "Application/pdf"));
        }