Exemplo n.º 1
0
        public static string CreatePDFFileFromTxtFile(string textfilefullpath, string playerName)
        {
            Document doc     = new Document();
            Section  section = doc.AddSection();

            section.PageSetup.TopMargin    = 25;
            section.PageSetup.LeftMargin   = 30;
            section.PageSetup.RightMargin  = 30;
            section.PageSetup.BottomMargin = 25;

            MigraDoc.DocumentObjectModel.Font font = new MigraDoc.DocumentObjectModel.Font("Adobe Garamond Pro", 22);
            font.Bold      = true;
            font.Italic    = false;
            font.Underline = Underline.None;
            Paragraph paragraph = section.AddParagraph();

            paragraph.AddFormattedText(playerName + "'s Stats up to Season " + ConfigFile.SEASON_LAST, font);
            paragraph.Format.Shading.Color = Colors.LightSteelBlue;
            paragraph.Format.Alignment     = ParagraphAlignment.Center;
            Paragraph paragraph2 = section.AddParagraph();

            paragraph2.AddFormattedText("  ", new MigraDoc.DocumentObjectModel.Font("Courier New", 24));

            if (new FileInfo(Path.Combine(ConfigFile.DIRECTORY_OUTPUT.FullName, "chart.png")).Exists)
            {
                MigraDoc.DocumentObjectModel.Shapes.Image image = section.AddImage(Path.Combine(ConfigFile.DIRECTORY_OUTPUT.FullName, "chart.png"));
                image.Width              = "18cm";
                image.LockAspectRatio    = true;
                image.Left               = MigraDoc.DocumentObjectModel.Shapes.ShapePosition.Center;
                image.LineFormat.Visible = true;
                image.LineFormat.Width   = 1;
                image.LineFormat.Color   = Colors.LightGreen;
            }
            Paragraph paragraph3 = section.AddParagraph();

            paragraph3.AddFormattedText("  ", new MigraDoc.DocumentObjectModel.Font("Courier New", 10));

            if (new FileInfo(Path.Combine(ConfigFile.DIRECTORY_OUTPUT.FullName, "chart2.png")).Exists)
            {
                MigraDoc.DocumentObjectModel.Shapes.Image image = section.AddImage(Path.Combine(ConfigFile.DIRECTORY_OUTPUT.FullName, "chart2.png"));
                image.Width              = "18cm";
                image.LockAspectRatio    = true;
                image.Left               = MigraDoc.DocumentObjectModel.Shapes.ShapePosition.Center;
                image.LineFormat.Visible = true;
                image.LineFormat.Width   = 1;
                image.LineFormat.Color   = Colors.LightCoral;
            }
            Paragraph paragraph4 = section.AddParagraph();

            paragraph4.AddFormattedText("  ", new MigraDoc.DocumentObjectModel.Font("Courier New", 10));

            if (new FileInfo(Path.Combine(ConfigFile.DIRECTORY_OUTPUT.FullName, "chart3.png")).Exists)
            {
                MigraDoc.DocumentObjectModel.Shapes.Image image = section.AddImage(Path.Combine(ConfigFile.DIRECTORY_OUTPUT.FullName, "chart3.png"));
                image.Width              = "18cm";
                image.LockAspectRatio    = true;
                image.Left               = MigraDoc.DocumentObjectModel.Shapes.ShapePosition.Center;
                image.LineFormat.Visible = true;
                image.LineFormat.Width   = 1;
                image.LineFormat.Color   = Colors.LightBlue;
            }

            section.AddPageBreak();


            //just font arrangements as you wish

            section = DataOps.PrintDataSeason(section, textfilefullpath);
            section.AddPageBreak();
            section = DataOps.PrintDataByCategory(section, textfilefullpath);
            //add each line to pdf
            //foreach (string line in textFileLines)
            //{
            //    MigraDoc.DocumentObjectModel.Font font = new MigraDoc.DocumentObjectModel.Font("Courier New", 10);
            //    font.Bold = true;

            //    Paragraph paragraph = section.AddParagraph();
            //    paragraph.AddFormattedText(line, font);

            //}


            //save pdf document
            PdfDocumentRenderer renderer = new PdfDocumentRenderer();

            renderer.Document = doc;
            renderer.RenderDocument();
            FileInfo fileName = new FileInfo(Path.Combine(ConfigFile.DIRECTORY_OUTPUT.FullName, playerName + "_" + ConfigFile.SEASON_LAST.ToString() + ".pdf"));

            FileOps.CheckFile(fileName, true);
            renderer.Save(fileName.FullName);
            //if(fileName.Exists)
            //    Process.Start(fileName.FullName);
            return(fileName.FullName);
        }