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));
                g.Restore(state);

                if (imagewatermark.IsChecked.Value)
                {
                    g.Save();
                    Stream   imagestream = typeof(StampDocument).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.Ani.gif");
                    PdfImage image       = new PdfBitmap(imagestream);
                    g.SetTransparency(0.25f);
                    g.DrawImage(image, 0, 0, lPage.Graphics.ClientSize.Width, lPage.Graphics.ClientSize.Height);
                    imagestream.Dispose();
                    g.Restore();
                }
            }
            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
        private void DrawRectangles(PointF startPoint, PdfGraphics g, PdfFont font, PdfBrush brush, PdfPen pen, PdfDocument doc)
        {
            PdfBrush   textBrush = new PdfSolidBrush(Color.Black);
            RectangleF rect      = new RectangleF(startPoint.X, startPoint.Y, 100, 100);

            g.Save();

            g.DrawString("Default: " + doc.ColorSpace.ToString(), font, textBrush, rect.Location);
            rect.Y += 20;
            g.DrawRectangle(pen, brush, rect);
            rect.Y += 106;

            doc.ColorSpace = PdfColorSpace.RGB;

            g.DrawString("RGB color space.", font, textBrush, rect.Location);
            rect.Y += 20;
            g.DrawRectangle(pen, brush, rect);
            rect.Y += 106;

            doc.ColorSpace = PdfColorSpace.CMYK;

            g.DrawString("CMYK color space.", font, textBrush, rect.Location);
            rect.Y += 20;
            g.DrawRectangle(pen, brush, rect);
            rect.Y += 106;

            doc.ColorSpace = PdfColorSpace.GrayScale;

            g.DrawString("Gray scale color space.", font, textBrush, rect.Location);
            rect.Y += 20;
            g.DrawRectangle(pen, brush, rect);
            rect.Y += 106;

            g.Restore();
        }
示例#6
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);
                }
            }
        }
示例#8
0
        void IPainter.PaintText(string text, Point atPoint, int pixelHeight, int argb, int spaceBetweenCharacters, FontBasePainter.TextDirection direction)
        {
            var state = PdfGraphics.Save();

            var font = GetPdfFont(pixelHeight);

            if (direction == FontBasePainter.TextDirection.VerticalUpward)
            {
                PdfGraphics.RotateAtTransform(-90, new XPoint(atPoint.X + Shift.Width, atPoint.Y + Shift.Height));
            }

            PdfGraphics.DrawString(text ?? "", font, GetBrush(argb), atPoint.X + Shift.Width, atPoint.Y + Shift.Height + pixelHeight);

            PdfGraphics.Restore(state);
        }
示例#9
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"));
            }
        }
示例#10
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);
            }
        }
示例#11
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);
        }
示例#12
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);
            }
        }
示例#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"));
        }