public ActionResult ConvertToPDF(int canId)
        {
            try
            {
                PdfData pdfData = new PdfData();
                pdfData.ExamSubmissionResults = examRepository.GetAll().Where(can => can.CandidateId == canId).ToList();
                pdfData.Candidate             = canRepository.Get(canId);
                pdfData.Candidate.Position    = posRepository.Get(pdfData.Candidate.PositionId);
                pdfData.DocumentTitle         = "Exam Result";

                return(new ViewAsPdf("Index", pdfData)
                {
                    FileName = pdfData.Candidate.Id + "." + pdfData.Candidate.Name + ".pdf",
                    PageSize = Rotativa.AspNetCore.Options.Size.A4,
                    PageOrientation = Rotativa.AspNetCore.Options.Orientation.Portrait,
                    PageMargins = { Left = 20, Bottom = 20, Right = 20, Top = 20 }
                });
            }
            catch (Exception ex)
            {
                logger.LogError($"Error while generating the pdf : {ex}");
            }

            ViewBag.ErrorTitle   = $"Error Occurred";
            ViewBag.ErrorMessage = $"Error while generating PDF";
            return(View("Error"));
        }
Ejemplo n.º 2
0
        public static PdfData getPdfStreamDataByLimit(int limit)
        {
            //如果需要POST数据
            Json j = new Json();

            j.limit = limit;
            string data = JsonConvert.SerializeObject(j);

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(PathUtil.selectUrl);

            req.Method      = "POST";
            req.ContentType = "application/json";
            Stream reqstream = req.GetRequestStream();

            byte[] b = Encoding.ASCII.GetBytes(data);
            reqstream.Write(b, 0, b.Length);
            StreamReader responseReader = new StreamReader(req.GetResponse().GetResponseStream(), System.Text.Encoding.Default);
            string       str            = responseReader.ReadToEnd(); //url返回的值

            Console.WriteLine(str);
            PdfData _list = null;

            if (str != null && !str.Equals(""))
            {
                _list = JsonConvert.DeserializeObject <PdfData>(str);
            }
            //LogHelper.WriteLog(typeof(HttpUtil), str);
            responseReader.Close();
            reqstream.Close();
            return(_list);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns true if ImageSaveAsPDFResponse instances are equal
        /// </summary>
        /// <param name="input">Instance of ImageSaveAsPDFResponse to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(ImageSaveAsPDFResponse input)
        {
            if (input == null)
            {
                return(false);
            }

            return
                ((
                     Error == input.Error ||
                     (Error != null &&
                      Error.Equals(input.Error))
                     ) &&
                 (
                     RemainingTokens == input.RemainingTokens ||
                     RemainingTokens.Equals(input.RemainingTokens)
                 ) &&
                 (
                     PdfData == input.PdfData ||
                     (PdfData != null &&
                      PdfData.Equals(input.PdfData))
                 ) &&
                 (
                     FileName == input.FileName ||
                     (FileName != null &&
                      FileName.Equals(input.FileName))
                 ));
        }
Ejemplo n.º 4
0
        void AddAspiration(XGraphics gfx, PdfData pdfData)
        {
            int ItemHeight = 20;

            var            fontTitle = new XFont("OpenSans", 10, XFontStyle.Bold);
            XTextFormatter tfTitle   = new XTextFormatter(gfx);
            XRect          rectTitle = new XRect(leftMargin - 10, startingHeight, 100, ItemHeight);

            gfx.DrawRectangle(XBrushes.White, rectTitle);
            tfTitle.DrawString("Aspiration", fontTitle, XBrushes.Black, rectTitle, XStringFormats.TopLeft);
            startingHeight = startingHeight + ItemHeight;

            int xMargin = 0;

            XRect rectTitle1 = new XRect(xMargin + leftMargin, startingHeight, 500, ItemHeight);

            gfx.DrawRectangle(XBrushes.LightSeaGreen, rectTitle1);
            tfTitle.DrawString("  " + "Description", fontTitle, XBrushes.White, rectTitle1, XStringFormats.TopLeft);

            startingHeight = startingHeight + ItemHeight + 1;
            for (int i = 0; i < pdfData.Aspiration.Count; i++)
            {
                var            font = new XFont("OpenSans", 10, XFontStyle.Regular);
                XTextFormatter tf   = new XTextFormatter(gfx);

                XRect rect = new XRect(leftMargin, startingHeight, 500, ItemHeight);
                gfx.DrawRectangle(XBrushes.AliceBlue, rect);
                var data = $"{"  " + pdfData.Aspiration[i].Description}";
                tf.DrawString(data, font, XBrushes.Black, rect, XStringFormats.TopLeft);

                startingHeight = startingHeight + ItemHeight + 1;
            }
        }
Ejemplo n.º 5
0
        public IActionResult CreatePdf()
        {
            var data = new PdfData
            {
                DocumentTitle    = "This is my demo document Title",
                DocumentName     = "myFirst",
                CreatedBy        = "Damien",
                Description      = "some data description which I have, and want to display in the PDF file..., This is another text, what is happening here, why is this text display...",
                DisplayListItems = new List <ItemsToDisplay>
                {
                    new ItemsToDisplay {
                        Id = "Print Servers", Data1 = "some data", Data2 = "more data to display"
                    },
                    new ItemsToDisplay {
                        Id = "Network Stuff", Data1 = "IP4", Data2 = "any left"
                    },
                    new ItemsToDisplay {
                        Id = "Job details", Data1 = "too many", Data2 = "say no"
                    },
                    new ItemsToDisplay {
                        Id = "Firewall", Data1 = "what", Data2 = "Let's burn it"
                    }
                }
            };
            var path = _pdfService.CreatePdf(data);

            var stream = new FileStream(path, FileMode.Open);

            return(new FileStreamResult(stream, "application/pdf")
            {
                FileDownloadName = "TestPdf.pdf"
            });
        }
Ejemplo n.º 6
0
        private void DemonstrateAspirationSimpleTable(Document document, PdfData pdfData)
        {
            document.LastSection.AddParagraph("Aspiration", "Heading2");

            Table table = new Table();

            table.Borders.Width = 0.75;

            Column column = table.AddColumn(Unit.FromCentimeter(18));

            column.Format.Alignment = ParagraphAlignment.Center;

            Row row = table.AddRow();

            row.Shading.Color = Colors.Azure;
            Cell cell = row.Cells[0];

            cell.AddParagraph("Aspiration");

            for (int i = 0; i < pdfData.Aspiration.Count; i++)
            {
                row  = table.AddRow();
                cell = row.Cells[0];
                cell.AddParagraph(pdfData.Aspiration[i].Description);
            }

            table.SetEdge(0, 0, 1, pdfData.Aspiration.Count + 1, Edge.Box, BorderStyle.Single, 1.5, Colors.Black);

            document.LastSection.Add(table);
        }
Ejemplo n.º 7
0
        public FileStreamResult CreatePdf(int Id)
        {
            Log l = new Log();

            try
            {
                var mentor     = _IMentor.GetUserMentorList(Id);
                var user       = _IUser.GetUser(Id);
                var aspiration = _IAspiration.GetUserAspirationList(Id);
                var allocation = _IAllocation.GetUserAllocationList(Id);
                var iinternal  = _IInternal.GetUserInternalList(Id);
                var training   = _ITraining.GetUserTrainingList(Id);
                var data       = new PdfData
                {
                    DocumentTitle = "Career Development Plan",
                    DocumentName  = "CDP",
                    CreatedBy     = "Automatic generated file",
                    //Description = "some data description which I have, and want to display in the PDF file..., This is another text, what is happening here, why is this text display...",
                    Description      = "some data description ...",
                    DisplayListItems = new List <ItemsToDisplay>
                    {
                        new ItemsToDisplay {
                            Id = "Print Servers", Data1 = "some data", Data2 = "more data to display"
                        },
                        new ItemsToDisplay {
                            Id = "Network Stuff", Data1 = "IP4", Data2 = "any left"
                        },
                        new ItemsToDisplay {
                            Id = "Job details", Data1 = "too many", Data2 = "say no"
                        },
                        new ItemsToDisplay {
                            Id = "Firewall", Data1 = "what", Data2 = "Let's burn it"
                        }
                    },
                    User       = user,
                    Training   = training,
                    Allocation = allocation,
                    Aspiration = aspiration,
                    IInternal  = iinternal,
                    Mentor     = mentor
                };

                var path = _pdfService.CreatePdf(data);
                l.CreatedOn        = System.DateTime.UtcNow;
                l.ShortDescription = "Calling Log";
                l.FullDescription  = "Called Service";
                _ILog.InsertLog(l);
                var stream = new FileStream(path, FileMode.Open);
                //return new FileContentResult(pdf, "application/pdf");
                return(File(stream, "application/pdf"));
            }
            catch (Exception ex)
            {
                l.CreatedOn        = System.DateTime.UtcNow;
                l.ShortDescription = ex.Message;
                l.FullDescription  = ex.InnerException.ToString();
                _ILog.InsertLog(l);
                throw ex;
            }
        }
Ejemplo n.º 8
0
        private void DefineAspirationTables(Document document, PdfData pdfData)
        {
            //Paragraph paragraph = document.LastSection.AddParagraph("Table Overview", "Heading1");
            //paragraph.AddBookmark("Tables");

            DemonstrateAspirationSimpleTable(document, pdfData);
        }
Ejemplo n.º 9
0
        void AddInternal(XGraphics gfx, PdfData pdfData)
        {
            int ItemHeight = 20;

            var            fontTitle = new XFont("OpenSans", 10, XFontStyle.Bold);
            XTextFormatter tfTitle   = new XTextFormatter(gfx);
            XRect          rectTitle = new XRect(leftMargin - 10, startingHeight, 100, ItemHeight);

            gfx.DrawRectangle(XBrushes.White, rectTitle);
            tfTitle.DrawString("Internal", fontTitle, XBrushes.Black, rectTitle, XStringFormats.TopLeft);
            startingHeight = startingHeight + ItemHeight;

            int xMargin = 0;
            //Draw table Header
            XRect rectTitle1 = new XRect(xMargin + leftMargin, startingHeight, 166, ItemHeight);

            gfx.DrawRectangle(XBrushes.LightSeaGreen, rectTitle1);
            tfTitle.DrawString("  " + "Topic", fontTitle, XBrushes.White, rectTitle1, XStringFormats.TopLeft);
            xMargin = 167;

            XRect rectTitle2 = new XRect(xMargin + leftMargin, startingHeight, 166, ItemHeight);

            gfx.DrawRectangle(XBrushes.LightSeaGreen, rectTitle2);
            tfTitle.DrawString("  " + "Training Mode", fontTitle, XBrushes.White, rectTitle2, XStringFormats.TopLeft);
            xMargin = 334;

            XRect rectTitle3 = new XRect(xMargin + leftMargin, startingHeight, 166, ItemHeight);

            gfx.DrawRectangle(XBrushes.LightSeaGreen, rectTitle3);
            tfTitle.DrawString("  " + "Description", fontTitle, XBrushes.White, rectTitle3, XStringFormats.TopLeft);

            startingHeight = startingHeight + ItemHeight + 1;

            //Draw table
            for (int i = 0; i < pdfData.IInternal.Count; i++)
            {
                var            font = new XFont("OpenSans", 10, XFontStyle.Regular);
                XTextFormatter tf   = new XTextFormatter(gfx);

                XRect rect = new XRect(leftMargin, startingHeight, 166, ItemHeight);
                gfx.DrawRectangle(XBrushes.AliceBlue, rect);
                var data = $"{"  " + pdfData.IInternal[i].Topic}";
                tf.DrawString(data, font, XBrushes.Black, rect, XStringFormats.TopLeft);

                XRect rect2 = new XRect(167 + leftMargin, startingHeight, 166, ItemHeight);
                gfx.DrawRectangle(XBrushes.AliceBlue, rect2);
                var data2 = $"{"  " + pdfData.IInternal[i].TrainingMode}";
                tf.DrawString(data2, font, XBrushes.Black, rect2, XStringFormats.TopLeft);

                XRect rect3 = new XRect(334 + leftMargin, startingHeight, 166, ItemHeight);
                gfx.DrawRectangle(XBrushes.AliceBlue, rect3);
                var data3 = $"{"  " + pdfData.IInternal[i].Description}";
                tf.DrawString(data3, font, XBrushes.Black, rect3, XStringFormats.TopLeft);

                startingHeight = startingHeight + ItemHeight + 1;
            }
            startingHeight = startingHeight + 5;
        }
Ejemplo n.º 10
0
        void AddDescription(XGraphics gfx, PdfData pdfData)
        {
            var            font = new XFont("OpenSans", 14, XFontStyle.Regular);
            XTextFormatter tf   = new XTextFormatter(gfx);
            XRect          rect = new XRect(40, 100, 520, 100);

            gfx.DrawRectangle(XBrushes.White, rect);
            tf.DrawString(pdfData.Description, font, XBrushes.Black, rect, XStringFormats.TopLeft);
        }
Ejemplo n.º 11
0
        void AddAllocation(XGraphics gfx, PdfData pdfData)
        {
            //int startingHeight = 135;
            int ItemHeight = 20;

            var            fontTitle = new XFont("OpenSans", 10, XFontStyle.Bold);
            XTextFormatter tfTitle   = new XTextFormatter(gfx);
            XRect          rectTitle = new XRect(leftMargin - 10, startingHeight, 100, ItemHeight);

            gfx.DrawRectangle(XBrushes.White, rectTitle);
            tfTitle.DrawString("Allocation", fontTitle, XBrushes.Black, rectTitle, XStringFormats.TopLeft);
            startingHeight = startingHeight + ItemHeight;

            int xMargin = 0;
            //Draw table Header
            //for (int i = 0; i < 2; i++)
            //{
            //    XRect rectTitle1 = new XRect(xMargin + 60, startingHeight, 250, ItemHeight);
            //    gfx.DrawRectangle(XBrushes.SlateGray, rectTitle1);
            //    tfTitle.DrawString("  " + "Header" + i.ToString(), fontTitle, XBrushes.White, rectTitle1, XStringFormats.TopLeft);
            //    //startingHeight = startingHeight + ItemHeight;
            //    xMargin = 251;
            //}

            XRect rectTitle1 = new XRect(xMargin + leftMargin, startingHeight, 250, ItemHeight);

            gfx.DrawRectangle(XBrushes.LightSeaGreen, rectTitle1);
            tfTitle.DrawString("  " + "Allocation", fontTitle, XBrushes.White, rectTitle1, XStringFormats.TopLeft);
            xMargin = 251;

            XRect rectTitle2 = new XRect(xMargin + leftMargin, startingHeight, 250, ItemHeight);

            gfx.DrawRectangle(XBrushes.LightSeaGreen, rectTitle2);
            tfTitle.DrawString("  " + "Comment", fontTitle, XBrushes.White, rectTitle2, XStringFormats.TopLeft);

            startingHeight = startingHeight + ItemHeight + 1;
            for (int i = 0; i < pdfData.Allocation.Count; i++)
            {
                var            font = new XFont("OpenSans", 10, XFontStyle.Regular);
                XTextFormatter tf   = new XTextFormatter(gfx);

                XRect rect = new XRect(leftMargin, startingHeight, 250, ItemHeight);
                gfx.DrawRectangle(XBrushes.AliceBlue, rect);
                //var data = $"{i} {pdfData.Allocation[i].Allocation} | {pdfData.Allocation[i].Comment}";
                var data = $"{"  " + pdfData.Allocation[i].Allocation}";
                tf.DrawString(data, font, XBrushes.Black, rect, XStringFormats.TopLeft);


                XRect rect2 = new XRect(251 + leftMargin, startingHeight, 250, ItemHeight);
                gfx.DrawRectangle(XBrushes.AliceBlue, rect2);
                //var data = $"{i} {pdfData.Allocation[i].Allocation} | {pdfData.Allocation[i].Comment}";
                var data2 = $"{" " + pdfData.Allocation[i].Comment}";
                tf.DrawString(data2, font, XBrushes.Black, rect2, XStringFormats.TopLeft);

                startingHeight = startingHeight + ItemHeight + 1;
            }
        }
Ejemplo n.º 12
0
        //void AddInternal(XGraphics gfx, PdfData pdfData)
        //{
        //    //int startingHeight = 135;
        //    int ItemHeight = 20;

        //    var fontTitle = new XFont("OpenSans", 11, XFontStyle.Bold);
        //    XTextFormatter tfTitle = new XTextFormatter(gfx);
        //    XRect rectTitle = new XRect(60, startingHeight, 100, ItemHeight);
        //    gfx.DrawRectangle(XBrushes.White, rectTitle);
        //    tfTitle.DrawString("Internal", fontTitle, XBrushes.Black, rectTitle, XStringFormats.TopLeft);
        //    startingHeight = startingHeight + ItemHeight;

        //    for (int i = 0; i < pdfData.IInternal.Count; i++)
        //    {
        //        var font = new XFont("OpenSans", 11, XFontStyle.Regular);
        //        XTextFormatter tf = new XTextFormatter(gfx);
        //        XRect rect = new XRect(60, startingHeight, 500, ItemHeight);
        //        gfx.DrawRectangle(XBrushes.SlateGray, rect);
        //        var data = $"{pdfData.IInternal[i].Topic} | {pdfData.IInternal[i].TrainingMode} | {pdfData.IInternal[i].Description}";
        //        tf.DrawString(data, font, XBrushes.White, rect, XStringFormats.TopLeft);

        //        startingHeight = startingHeight + ItemHeight;
        //    }
        //}
        void AddMentor(XGraphics gfx, PdfData pdfData)
        {
            //int startingHeight = 135;
            int ItemHeight = 20;

            var            fontTitle = new XFont("OpenSans", 10, XFontStyle.Bold);
            XTextFormatter tfTitle   = new XTextFormatter(gfx);
            XRect          rectTitle = new XRect(leftMargin - 10, startingHeight, 100, ItemHeight);

            gfx.DrawRectangle(XBrushes.White, rectTitle);
            tfTitle.DrawString("Mentors", fontTitle, XBrushes.Black, rectTitle, XStringFormats.TopLeft);
            startingHeight = startingHeight + ItemHeight;

            int xMargin = 0;
            //Draw table Header
            XRect rectTitle1 = new XRect(xMargin + leftMargin, startingHeight, 166, ItemHeight);

            gfx.DrawRectangle(XBrushes.LightSeaGreen, rectTitle1);
            tfTitle.DrawString("  " + "Mentor", fontTitle, XBrushes.White, rectTitle1, XStringFormats.TopLeft);
            xMargin = 167;

            XRect rectTitle2 = new XRect(xMargin + leftMargin, startingHeight, 166, ItemHeight);

            gfx.DrawRectangle(XBrushes.LightSeaGreen, rectTitle2);
            tfTitle.DrawString("  " + "Training Category", fontTitle, XBrushes.White, rectTitle2, XStringFormats.TopLeft);
            xMargin = 334;

            XRect rectTitle3 = new XRect(xMargin + leftMargin, startingHeight, 166, ItemHeight);

            gfx.DrawRectangle(XBrushes.LightSeaGreen, rectTitle3);
            tfTitle.DrawString("  " + "Comment", fontTitle, XBrushes.White, rectTitle3, XStringFormats.TopLeft);

            startingHeight = startingHeight + ItemHeight + 1;
            for (int i = 0; i < pdfData.Mentor.Count; i++)
            {
                var            font = new XFont("OpenSans", 10, XFontStyle.Regular);
                XTextFormatter tf   = new XTextFormatter(gfx);

                XRect rect = new XRect(leftMargin, startingHeight, 166, ItemHeight);
                gfx.DrawRectangle(XBrushes.AliceBlue, rect);
                var data = $"{"  " + pdfData.Mentor[i].Mentor}";
                tf.DrawString(data, font, XBrushes.Black, rect, XStringFormats.TopLeft);

                XRect rect2 = new XRect(167 + leftMargin, startingHeight, 166, ItemHeight);
                gfx.DrawRectangle(XBrushes.AliceBlue, rect2);
                var data2 = $"{"  " + pdfData.Mentor[i].TrainingCategory}";
                tf.DrawString(data2, font, XBrushes.Black, rect2, XStringFormats.TopLeft);

                XRect rect3 = new XRect(334 + leftMargin, startingHeight, 166, ItemHeight);
                gfx.DrawRectangle(XBrushes.AliceBlue, rect3);
                var data3 = $"{"  " + pdfData.Mentor[i].Comment}";
                tf.DrawString(data3, font, XBrushes.Black, rect3, XStringFormats.TopLeft);

                startingHeight = startingHeight + ItemHeight + 1;
            }
            startingHeight = startingHeight + 5;
        }
Ejemplo n.º 13
0
        private void DefineEmployeeTables(Document document, PdfData pdfData)
        {
            //Paragraph paragraph = document.LastSection.AddParagraph("Table Overview", "Heading1");
            //paragraph.AddBookmark("Tables");

            DemonstrateEmployeeSimpleTable(document, pdfData);
            //DemonstrateTableAlignment(document);
            //DemonstrateCellMerge(document);
        }
Ejemplo n.º 14
0
        void AddDescription(XGraphics gfx, PdfData pdfData)
        {
            int            ItemHeight = 20;
            var            font       = new XFont("OpenSans", 14, XFontStyle.Regular);
            XTextFormatter tf         = new XTextFormatter(gfx);
            XRect          rect       = new XRect(40, startingHeight, 520, ItemHeight);

            gfx.DrawRectangle(XBrushes.White, rect);
            tf.DrawString(pdfData.Description, font, XBrushes.Black, rect, XStringFormats.TopLeft);
            startingHeight = startingHeight + ItemHeight;
        }
Ejemplo n.º 15
0
        private void DemonstrateEnablementIndent(Document document, PdfData pdfData)
        {
            document.LastSection.AddParagraph("Enablement", "Heading2");

            var primary   = pdfData.Training.AsEnumerable().Where(a => a.IsPrimary == true).OrderBy(a => a.TrainingCategory);
            var secondary = pdfData.Training.AsEnumerable().Where(a => a.IsPrimary == false);

            if (primary.Count() > 0)
            {
                document.LastSection.AddParagraph("Primary Skills", "Heading3").Format.LeftIndent = "0.2cm";
                //document.LastSection
                var groups = primary.GroupBy(a => a.TrainingCategory);

                foreach (var group in groups)
                {
                    Paragraph paragraph1 = document.LastSection.AddParagraph();
                    paragraph1.Format.LeftIndent = "0.5cm";
                    paragraph1.AddText(group.Key);
                    paragraph1.Format.Font.Size = 12;
                    paragraph1.Format.Font.Bold = true;
                    foreach (var v in group)
                    {
                        Paragraph paragraph2 = document.LastSection.AddParagraph();
                        paragraph2.Format.LeftIndent = "1cm";
                        paragraph2.AddText(v.TrainingCode + " - " + v.Training);
                        paragraph1.Format.Font.Size = 11;
                    }
                }
            }

            if (secondary.Count() > 0)
            {
                document.LastSection.AddParagraph("Secondary Skills", "Heading3").Format.LeftIndent = "0.2cm";
                var groups = secondary.GroupBy(a => a.TrainingCategory);

                foreach (var group in groups)
                {
                    Paragraph paragraph1 = document.LastSection.AddParagraph();
                    paragraph1.Format.LeftIndent = "0.5cm";
                    paragraph1.AddText(group.Key);
                    paragraph1.Format.Font.Size = 12;
                    paragraph1.Format.Font.Bold = true;
                    foreach (var v in group)
                    {
                        Paragraph paragraph2 = document.LastSection.AddParagraph();
                        paragraph2.Format.LeftIndent = "1cm";
                        paragraph2.AddText(v.TrainingCode + " - " + v.Training);
                        paragraph1.Format.Font.Size = 11;
                    }
                }
            }
        }
Ejemplo n.º 16
0
        public IActionResult Index(int canId)
        {
            PdfData pdfData = new PdfData();

            if (canId != 0)
            {
                pdfData.ExamSubmissionResults = examRepository.GetAll().Where(can => can.CandidateId == canId).ToList();
                pdfData.Candidate             = canRepository.Get(canId);
                pdfData.Candidate.Position    = posRepository.Get(pdfData.Candidate.PositionId);
                pdfData.DocumentTitle         = "Exam Result";
            }
            return(View(pdfData));
        }
Ejemplo n.º 17
0
        public FileStreamResult CreateMigraDocPdf(int Id)
        {
            try
            {
                var mentor     = _IMentor.GetUserMentorList(Id);
                var user       = _IUser.GetUser(Id);
                var aspiration = _IAspiration.GetUserAspirationList(Id);
                var allocation = _IAllocation.GetUserAllocationList(Id);
                var iinternal  = _IInternal.GetUserInternalList(Id);
                var training   = _ITraining.GetUserTrainingList(Id);

                var data = new PdfData
                {
                    DocumentTitle    = "CDP for " + user.Name,
                    DocumentName     = "CDP - " + Regex.Replace(user.Name, @"\t|\n|\r", ""),
                    CreatedBy        = "system",
                    Description      = "Career Development Plan",
                    DisplayListItems = new List <ItemsToDisplay>
                    {
                        new ItemsToDisplay {
                            Id = "Print Servers", Data1 = "some data", Data2 = "more data to display"
                        },
                        new ItemsToDisplay {
                            Id = "Network Stuff", Data1 = "IP4", Data2 = "any left"
                        },
                        new ItemsToDisplay {
                            Id = "Job details", Data1 = "too many", Data2 = "say no"
                        },
                        new ItemsToDisplay {
                            Id = "Firewall", Data1 = "what", Data2 = "Let's burn it"
                        }
                    },
                    User       = user,
                    Training   = training,
                    Allocation = allocation,
                    Aspiration = aspiration,
                    IInternal  = iinternal,
                    Mentor     = mentor
                };
                var path = _migraDocService.CreateMigraDocPdf(data);

                var stream = new FileStream(path, FileMode.Open);
                return(File(stream, "application/pdf"));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 18
0
        void AddList(XGraphics gfx, PdfData pdfData)
        {
            int startingHeight = 200;
            int listItemHeight = 30;

            for (int i = 0; i < pdfData.DisplayListItems.Count; i++)
            {
                var            font = new XFont("OpenSans", 14, XFontStyle.Regular);
                XTextFormatter tf   = new XTextFormatter(gfx);
                XRect          rect = new XRect(60, startingHeight, 500, listItemHeight);
                gfx.DrawRectangle(XBrushes.White, rect);
                var data = $"{i}. {pdfData.DisplayListItems[i].Id} | {pdfData.DisplayListItems[i].Data1} | {pdfData.DisplayListItems[i].Data2}";
                tf.DrawString(data, font, XBrushes.Black, rect, XStringFormats.TopLeft);

                startingHeight = startingHeight + listItemHeight;
            }
        }
Ejemplo n.º 19
0
        public string CreateMigraDocPdf(PdfData pdfData)
        {
            // Create a MigraDoc document
            Document document  = CreateDocument(pdfData);
            string   mdddlName = $"{_createdDocsPath}/{pdfData.DocumentName}-{DateTime.UtcNow.ToOADate()}.mdddl";
            string   docName   = $"{_createdDocsPath}/{pdfData.DocumentName}-{DateTime.UtcNow.ToOADate()}.pdf";

            MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document, mdddlName);

            PdfDocumentRenderer renderer = new PdfDocumentRenderer(true);

            renderer.Document = document;
            renderer.RenderDocument();
            renderer.PdfDocument.Save(docName);

            return(docName);
        }
Ejemplo n.º 20
0
        private void DemonstrateEmployeeSimpleTable(Document document, PdfData pdfData)
        {
            document.LastSection.AddParagraph("Employee Detail", "Heading2");

            Table table = new Table();

            table.Borders.Width = 0.75;

            Column column = table.AddColumn(Unit.FromCentimeter(5));

            column.Format.Alignment = ParagraphAlignment.Center;

            table.AddColumn(Unit.FromCentimeter(3));
            table.AddColumn(Unit.FromCentimeter(5));
            table.AddColumn(Unit.FromCentimeter(5));

            Row row = table.AddRow();

            row.Shading.Color = Colors.Azure;
            Cell cell = row.Cells[0];

            cell.AddParagraph("Name");
            cell = row.Cells[1];
            cell.AddParagraph("Trigram");
            cell = row.Cells[2];
            cell.AddParagraph("Manager");
            cell = row.Cells[3];
            cell.AddParagraph("Manager Trigram");

            row  = table.AddRow();
            cell = row.Cells[0];
            cell.AddParagraph(pdfData.User.Name);
            cell = row.Cells[1];
            cell.AddParagraph(pdfData.User.Trigram);
            cell = row.Cells[2];
            cell.AddParagraph(pdfData.User.Manager);
            cell = row.Cells[3];
            cell.AddParagraph(pdfData.User.ManagerTrigram);

            table.SetEdge(0, 0, 4, 2, Edge.Box, BorderStyle.Single, 1.5, Colors.Black);

            document.LastSection.Add(table);
        }
Ejemplo n.º 21
0
        static void Main(string[] args)
        {
#if DEBUG
            try {
//              PdfData data = PdfStandard.Standard;

                using (BinaryWriter writer = new BinaryWriter(new FileStream(@"..\Data.bin", FileMode.Create, FileAccess.Write, FileShare.None))) {
                    PdfData.ReadFromFiles().WriteTo(writer);
                }
            }
            catch (Exception err) {
                while (err != null)
                {
                    Console.WriteLine("ERROR: " + err.Message);
                    err = err.InnerException;
                }
            }
#endif
        }
Ejemplo n.º 22
0
        private void DemonstrateMentorSimpleTable(Document document, PdfData pdfData)
        {
            document.LastSection.AddParagraph("Mentor", "Heading2");

            Table table = new Table();

            table.Borders.Width = 0.75;

            Column column = table.AddColumn(Unit.FromCentimeter(6));

            column.Format.Alignment = ParagraphAlignment.Center;

            table.AddColumn(Unit.FromCentimeter(6));
            table.AddColumn(Unit.FromCentimeter(6));

            Row row = table.AddRow();

            row.Shading.Color = Colors.Azure;
            Cell cell = row.Cells[0];

            cell.AddParagraph("Mentor");
            cell = row.Cells[1];
            cell.AddParagraph("Training Category");
            cell = row.Cells[2];
            cell.AddParagraph("Comment");

            for (int i = 0; i < pdfData.Mentor.Count; i++)
            {
                row  = table.AddRow();
                cell = row.Cells[0];
                cell.AddParagraph(pdfData.Mentor[i].Mentor);
                cell = row.Cells[1];
                cell.AddParagraph(pdfData.Mentor[i].TrainingCategory);
                cell = row.Cells[2];
                cell.AddParagraph(pdfData.Mentor[i].Comment == null ? "" : pdfData.Mentor[i].Comment);
            }

            table.SetEdge(0, 0, 3, pdfData.Mentor.Count + 1, Edge.Box, BorderStyle.Single, 1.5, Colors.Black);

            document.LastSection.Add(table);
        }
Ejemplo n.º 23
0
        private void DefineCover(Document document, PdfData pdfData)
        {
            Section section = document.AddSection();

            Paragraph paragraph = section.AddParagraph();

            paragraph.Format.SpaceAfter = "3cm";

            Image image = section.AddImage($"{_imagesPath}\\logo.png");

            image.Width = "4cm";

            paragraph = section.AddParagraph("Career Development Plan document for " + pdfData.User.Name);
            paragraph.Format.Font.Size   = 18;
            paragraph.Format.Font.Color  = Colors.DarkRed;
            paragraph.Format.SpaceBefore = "2cm";
            paragraph.Format.SpaceAfter  = "10cm";

            paragraph = section.AddParagraph("Auto Generate Date: ");
            paragraph.AddDateField();
        }
Ejemplo n.º 24
0
        public string CreatePdf(PdfData pdfData)
        {
            if (GlobalFontSettings.FontResolver == null)
            {
                GlobalFontSettings.FontResolver = new FontResolver(_resourcesPath);
            }

            var document = new PdfDocument();
            var page     = document.AddPage();
            var gfx      = XGraphics.FromPdfPage(page);

            AddTitleLogo(gfx, page, $"{_imagesPath}\\logo.jpg", 0, 0);
            AddTitleAndFooter(page, gfx, pdfData.DocumentTitle, document, pdfData);
            AddDescription(gfx, pdfData);
            AddList(gfx, pdfData);

            string docName = $"{_createdDocsPath}/{pdfData.DocumentName}-{DateTime.UtcNow.ToOADate()}.pdf";

            document.Save(docName);
            return(docName);
        }
Ejemplo n.º 25
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         int hashCode = 41;
         if (Error != null)
         {
             hashCode = hashCode * 59 + Error.GetHashCode();
         }
         hashCode = hashCode * 59 + RemainingTokens.GetHashCode();
         if (PdfData != null)
         {
             hashCode = hashCode * 59 + PdfData.GetHashCode();
         }
         if (FileName != null)
         {
             hashCode = hashCode * 59 + FileName.GetHashCode();
         }
         return(hashCode);
     }
 }
Ejemplo n.º 26
0
        public static PdfData getPdfStreamDataByUserUpload(int limit)
        {
            StringBuilder url = new StringBuilder(PathUtil.userUploadUrl);

            url.Append("?programName=");
            url.Append(SystemConstant.PROGRAMNAME);
            url.Append("&docType=");
            url.Append(PathUtil.testDocType);
            url.Append("&limit=");
            url.Append(limit);
            Console.WriteLine("url-" + url);
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url.ToString());

            req.Method      = "GET";
            req.ContentType = "application/json";
            StreamReader responseReader = new StreamReader(req.GetResponse().GetResponseStream(), System.Text.Encoding.Default);
            string       str            = responseReader.ReadToEnd(); //url返回的值

            Console.WriteLine(str);
            PdfStreamObj _list = null;

            if (str != null && !str.Equals(""))
            {
                _list = JsonConvert.DeserializeObject <PdfStreamObj>(str);
            }
            //LogHelper.WriteLog(typeof(HttpUtil), str);
            responseReader.Close();
            PdfData pdfData = new PdfData();

            if (_list.data != null && _list.data.Count > 0)
            {
                foreach (PdfStreamInfo info in _list.data)
                {
                    PdfStream stream = new PdfStream();
                    parseStreamToStreamInfo(stream, info);
                    pdfData.data.Add(stream);
                }
            }
            return(pdfData);
        }
Ejemplo n.º 27
0
        private Document CreateDocument(PdfData pdfData)
        {
            // Create a new MigraDoc document
            Document document = new Document();

            document.Info.Title   = pdfData.DocumentTitle;
            document.Info.Subject = pdfData.Description;
            document.Info.Author  = pdfData.CreatedBy;

            DefineStyles(document);

            DefineCover(document);
            DefineTableOfContents(document);

            DefineContentSection(document);

            DefineParagraphs(document);
            DefineTables(document);
            DefineCharts(document);

            return(document);
        }
Ejemplo n.º 28
0
        private Document CreateCDPDocument(PdfData pdfData)
        {
            // Create a new MigraDoc document
            Document document = new Document();

            document.Info.Title   = pdfData.DocumentTitle;
            document.Info.Subject = pdfData.Description;
            document.Info.Author  = pdfData.CreatedBy;

            DefineNewStyles(document);

            DefineCover(document, pdfData);

            DefineContentSection(document);
            DefineEmployeeTables(document, pdfData);
            if (pdfData.Training.Count > 0)
            {
                DefineEnablementParagraphs(document, pdfData);
            }
            if (pdfData.Aspiration.Count > 0)
            {
                DefineAspirationTables(document, pdfData);
            }
            if (pdfData.Mentor.Count > 0)
            {
                DefineMentorTables(document, pdfData);
            }
            if (pdfData.Allocation.Count > 0)
            {
                DefineAllocationTables(document, pdfData);
            }
            if (pdfData.IInternal.Count > 0)
            {
                DefineInternalTables(document, pdfData);
            }

            return(document);
        }
Ejemplo n.º 29
0
        public static PdfData getPdfStreamData()
        {
            WebRequest wRequest = WebRequest.Create(PathUtil.selectUrl);

            wRequest.Method      = "GET";
            wRequest.ContentType = "text/html;charset=UTF-8";
            WebResponse  wResponse = wRequest.GetResponse();
            Stream       stream    = wResponse.GetResponseStream();
            StreamReader reader    = new StreamReader(stream, System.Text.Encoding.Default);
            string       str       = reader.ReadToEnd(); //url返回的值

            Console.WriteLine(str);
            PdfData _list = null;

            if (str != null && !str.Equals(""))
            {
                //String jsonText = "{\"data\":[{\"id\":6014621,\"doc_id\":1482324,\"doc_type\":2,\"pdf_path\":\"luobo/2017/09/07/0000000000000j2gb1.pdf\",\"excel_flag\":0},{\"id\":6014621,\"doc_id\":14812324,\"doc_type\":2,\"pdf_path\":\"luobo/2017/09/07/0000000000000j2gb1.pdf\",\"excel_flag\":0}]}";
                _list = JsonConvert.DeserializeObject <PdfData>(str);
            }
            //LogHelper.WriteLog(typeof(HttpUtil), str);
            reader.Close();
            wResponse.Close();
            return(_list);
        }
Ejemplo n.º 30
0
        //将需要OCR的文件复制到指定的文件中
        public void Execute(IJobExecutionContext context)
        {
            DirectoryInfo needOcrFolder = new DirectoryInfo(PathUtil.needOcrDestFilePath);

            if (needOcrFolder.GetFiles().Length >= SystemConstant.FILE_COUNT)  //
            {
                Console.WriteLine(DateTime.Now + ":需要ocr的目录中文件个数大于等于2,暂时不添加数据");
                return;
            }

            defaultDate = DateTime.Now;  //保存需要下载文件的时间
            try
            {
                //从接口获取需要ocr数据
                PdfData pdfData = HttpUtil.getPdfStreamDataByPipeLining(SystemConstant.LIMIT);
                foreach (PdfStream pdfInfo in pdfData.data)
                {
                    pdfInfo.program_name = SystemConstant.PROGRAMNAME;
                    String needOcrSourcePath = Path.Combine(PathUtil.tempSoucePath + Path.GetFileName(pdfInfo.pdf_path));
                    String remotePath        = "";
                    //微信文章跟其他类型的报告路径不一样
                    if (pdfInfo.doc_type == SystemConstant.ARTICLE_TYPE)
                    {
                        remotePath = Path.Combine(SystemConstant.ARICLE_PATH, pdfInfo.pdf_path);
                    }
                    else
                    {
                        remotePath = Path.Combine(SystemConstant.NORMAL_PATH, pdfInfo.pdf_path);
                    }
                    bool isExist = Ftp.checkFile(remotePath);
                    if (!isExist)
                    {
                        Console.WriteLine("服务器文件不存在");
                        pdfInfo.ocr_flag = OcrConstant.SERVER_FILE_NO_EXIST;
                        updatePdfStreamOcrStatus(pdfInfo);
                        return;
                    }
                    bool isSuccess = Ftp.donwload(needOcrSourcePath, remotePath);
                    if (!isSuccess)
                    {
                        pdfInfo.ocr_flag = OcrConstant.DOWNLOAD_FAIL;
                        Console.WriteLine("服务器文件下载失败");
                        updatePdfStreamOcrStatus(pdfInfo);
                        return;
                    }

                    if (!File.Exists(needOcrSourcePath))   //将标识更新为文件不存在 -2
                    {
                        pdfInfo.ocr_flag = OcrConstant.FILE_NO_EXIST;
                        updatePdfStreamOcrStatus(pdfInfo);
                        return;
                    }
                    fileNameVal++;
                    String fileName = Path.GetFileName(pdfInfo.pdf_path);  //获取文件名
                    //将文件名做一个映射关系
                    String descFilePath = Path.Combine(PathUtil.needOcrDestFilePath, fileNameVal + Path.GetExtension(fileName));
                    Console.WriteLine(descFilePath);
                    try
                    {
                        TxtUtil.addId(fileNameVal, pdfInfo.id, pdfInfo.doc_type, pdfInfo.pdf_path);
                        File.Move(needOcrSourcePath, descFilePath);
                        Console.WriteLine("复制成功...");
                        //插入数据库
                        Dao dao = new Dao();
                        Task.Run(() =>                                          //异步开始执行
                        {
                            //查询数据库是否存在这条记录
                            if (!dao.select(pdfInfo.id))
                            {
                                dao.insert(pdfInfo.id, pdfInfo.doc_type);
                            }
                            Console.WriteLine("插入数据库成功。。。");                   //异步执行完成标记
                        });
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("复制失败...");
                        Console.WriteLine(ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }