コード例 #1
0
ファイル: Form1.cs プロジェクト: simoneluconi/LatexDocument
 private void btnCompile_Click(object sender, EventArgs e)
 {
     lt.CreatePdf("Test", true);
 }
コード例 #2
0
        private void btnStartGeneration_Click(object sender, EventArgs e)
        {
            _txt.Clear();
            string versionFile      = Settings.Default.ResultFolderLocation + Path.DirectorySeparatorChar + "versions.json";
            bool   isSectionsUpdate = false;
            string section1FileName =
                Settings.Default.ResultFolderLocation + Path.DirectorySeparatorChar + "section1.json";
            string section2FileName =
                Settings.Default.ResultFolderLocation + Path.DirectorySeparatorChar + "section2.json";
            string section3FileName =
                Settings.Default.ResultFolderLocation + Path.DirectorySeparatorChar + "section3.json";
            dynamic oldVersions = null, siteVersions;

            if (File.Exists(versionFile))
            {
                string versions = File.ReadAllText(versionFile);
                oldVersions = JObject.Parse(versions);
            }

            string siteVersion = _mySender.Get("https://dbvirtualeducation.com/ielts/api/versions ");

            siteVersions = JObject.Parse(siteVersion);
            if (oldVersions == null ||
                oldVersions.section1 == null
                | oldVersions.section1 != siteVersions.section1)
            {
                string section1 = _mySender.Get("https://dbvirtualeducation.com/ielts/api/section1 ");
                File.WriteAllText(section1FileName, section1);
                isSectionsUpdate = true;
            }
            if (oldVersions == null ||
                oldVersions.section2 == null
                | oldVersions.section2 != siteVersions.section2)
            {
                string section2 = _mySender.Get("https://dbvirtualeducation.com/ielts/api/section2");
                File.WriteAllText(section2FileName, section2);
                isSectionsUpdate = true;
            }
            if (oldVersions == null ||
                oldVersions.section3 == null
                | oldVersions.section3 != siteVersions.section3)
            {
                string section3 = _mySender.Get("https://dbvirtualeducation.com/ielts/api/section3");
                File.WriteAllText(section3FileName, section3);
                isSectionsUpdate = true;
            }
            if (isSectionsUpdate)
            {
                File.WriteAllText(versionFile, siteVersion);
            }
            if (!String.IsNullOrEmpty(Settings.Default.LaTexLocation))
            {
                _lt = new Document(Settings.Default.LaTexLocation, Settings.Default.ResultFolderLocation);
            }
            LatexPageTitle title = new LatexPageTitle("IELTS Assistant");

            if (!String.IsNullOrEmpty(Settings.Default.LaTexLocation))
            {
                _lt.Add(title);
            }
            _txt.AppendLine("IELTS Assistant");
            GenerateSection("Section 1", section1FileName);
            GenerateSection("Section 2", section2FileName);
            GenerateSection("Section 3", section3FileName);
            File.WriteAllText(Settings.Default.ResultFolderLocation + Path.DirectorySeparatorChar +
                              Settings.Default.ResultFileName +
                              (Settings.Default.IsDictionary ? Settings.Default.DictionaryPrefix : "") +
                              (Settings.Default.IsAnswers ? Settings.Default.AnswerPrefix : "") +
                              (Settings.Default.IsIdeas ? Settings.Default.IdeasPrefix : "")
                              + ".txt", _txt.ToString());
            if (!String.IsNullOrEmpty(Settings.Default.LaTexLocation))
            {
                _lt.CreatePdf(Settings.Default.ResultFileName +
                              (Settings.Default.IsDictionary ? Settings.Default.DictionaryPrefix: "") +
                              (Settings.Default.IsAnswers ? Settings.Default.AnswerPrefix : "") +
                              (Settings.Default.IsIdeas ? Settings.Default.IdeasPrefix : ""));
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: stepstefan/Drvogalant
        private void createtex()
        {
            TextArea                   = new Scintilla();
            TextArea.Dock              = DockStyle.Fill;
            TextArea.WrapMode          = WrapMode.None;
            TextArea.IndentationGuides = IndentView.LookBoth;

            InitNumberMargin();
            LatexDocumentMargins margins = new LatexDocumentMargins(0.25, 0.25, 0.75, 0.75);

            //lt = new LatexDocument.Document(@"C:\Program Files\MiKTeX 2.9\miktex\bin\x64\pdflatex.exe", @"C:\Users\stefa\Desktop\Porudzbine\", margins);
            lt = new LatexDocument.Document(@"C:\Program Files\MiKTeX 2.9\miktex\bin\x64\pdflatex.exe", @"C:\Users\user\Desktop\Porudzbine\", margins);


            LatexFont font = new LatexFont();

            font.Size = LatexFont.TEXT_Huge;
            lt.StartCenterAlign();
            StringBuilder title_text = new StringBuilder(naslov.Text.TrimEnd());

            for (int i = 0; i < title_text.Length; i++)
            {
                if (title_text[i] == ' ')
                {
                    title_text[i] = '-';
                }
            }
            LatexTextTitle title = new LatexTextTitle(naslov.Text.TrimEnd(), font);

            lt.Add(title);
            lt.EndAlign();
            font.Size = LatexFont.DEFAULT_FONT;
            lt.Add(new LatexText(doortype.Text, font));
            lt.NewLine();

            Bitmap bm = new Bitmap(mainpb.Image);
            int    j  = 0;
            int    c  = bm.Height;

            while (c > 840)
            {
                Bitmap temp = bm.Clone(new Rectangle(0, 0, 900, 840), bm.PixelFormat);
                bm = bm.Clone(new Rectangle(0, 840, bm.Width, bm.Height - 840), bm.PixelFormat);
                temp.Save(@"C:\Users\user\Desktop\Porudzbine\image" + j.ToString() + ".png");
                LatexImage itmp = new LatexImage(@"C:\Users\user\Desktop\Porudzbine\image" + j.ToString() + ".png", 0.8);
                lt.Add(itmp);
                c = c - 840;
                j++;
                lt.NewPage();
            }
            bm.Save(@"C:\Users\user\Desktop\Porudzbine\image" + (j).ToString() + ".png");
            //bm.Save(@"C:\Users\stefa\Desktop\Porudzbine\image" + (j).ToString()+".png");
            LatexImage img = new LatexImage(@"C:\Users\user\Desktop\Porudzbine\image" + (j).ToString() + ".png", 0.8);

            //LatexImage img = new LatexImage(@"C:\Users\stefa\Desktop\Porudzbine\image" + (j).ToString() + ".png", 0.8);
            lt.Add(img);
            if (allDoors.Count > 5)
            {
                lt.NewPage();
            }
            else
            {
                lt.NewLine();
                lt.NewLine();
                lt.NewLine();
            }

            font.Type = LatexFont.TEXT_BOLD;
            lt.Add(new LatexText("Vratno krilo: ", font));
            font.Type = null;
            lt.Add(new LatexText(krilatb.Text, font));
            List <string> tmp = new List <string>();

            foreach (string i in krila.Items)
            {
                tmp.Add(i);
            }
            lt.Add(new LatexList(LatexList.BULLET, tmp));
            tmp.Clear();

            font.Type = LatexFont.TEXT_BOLD;
            lt.Add(new LatexText("MDF28mm: ", font));
            font.Type = null;
            lt.Add(new LatexText(mdf28tb.Text, font));
            foreach (string i in mdf28.Items)
            {
                string o = "";
                if (!char.IsWhiteSpace(i[0]))
                {
                    int    p    = i.IndexOf('c');
                    string tmp1 = i.Substring(p + 1);
                    p += tmp1.IndexOf('c');
                    o  = i.Substring(0, p + 3) + " \\quad \\quad" + i.Substring(p + 3);
                }
                else
                {
                    o = " \\quad \\quad \\quad \\quad \\quad \\quad \\quad \\quad \\quad \\quad \\quad \\quad" + i;
                }

                tmp.Add(o);
            }
            lt.Add(new LatexList(LatexList.BULLET, tmp));
            tmp.Clear();

            font.Type = LatexFont.TEXT_BOLD;
            lt.Add(new LatexText("MDF18mm: ", font));
            font.Type = null;
            lt.Add(new LatexText(mdf18tb.Text, font));
            foreach (string i in mdf18.Items)
            {
                tmp.Add(i);
            }
            lt.Add(new LatexList(LatexList.BULLET, tmp));
            tmp.Clear();
            if (doortype.SelectedIndex == 3)
            {
                font.Type = LatexFont.TEXT_BOLD;
                lt.Add(new LatexText("Hrastove trake: ", font));
                font.Type = null;
                lt.Add(new LatexText(mdf16tb.Text, font));
                foreach (string i in mdf16.Items)
                {
                    tmp.Add(i);
                }
                lt.Add(new LatexList(LatexList.BULLET, tmp));
                tmp.Clear();

                if (mdf22.Items.Count != 0)
                {
                    font.Type = LatexFont.TEXT_BOLD;
                    lt.Add(new LatexText("MDF28mmStaklo: ", font));
                    font.Type = null;
                    lt.Add(new LatexText(mdf22tb.Text, font));
                    foreach (string i in mdf22.Items)
                    {
                        tmp.Add(i);
                    }
                    lt.Add(new LatexList(LatexList.BULLET, tmp));
                    tmp.Clear();
                }
            }
            else
            {
                font.Type = LatexFont.TEXT_BOLD;
                lt.Add(new LatexText("MDF16mm: ", font));
                font.Type = null;
                lt.Add(new LatexText(mdf16tb.Text, font));
                foreach (string i in mdf16.Items)
                {
                    tmp.Add(i);
                }
                lt.Add(new LatexList(LatexList.BULLET, tmp));
                tmp.Clear();

                font.Type = LatexFont.TEXT_BOLD;
                lt.Add(new LatexText("HDF4mm: ", font));
                font.Type = null;
                lt.Add(new LatexText(hdf4.Text, font));
                foreach (string i in hdf4.Items)
                {
                    tmp.Add(i);
                }
                lt.Add(new LatexList(LatexList.BULLET, tmp));
                tmp.Clear();

                if (mdf22.Items.Count != 0)
                {
                    font.Type = LatexFont.TEXT_BOLD;
                    lt.Add(new LatexText("MDF22mm: ", font));
                    font.Type = null;
                    lt.Add(new LatexText(mdf22tb.Text, font));
                    foreach (string i in mdf22.Items)
                    {
                        tmp.Add(i);
                    }
                    lt.Add(new LatexList(LatexList.BULLET, tmp));
                    tmp.Clear();
                }
            }
            lt.CreatePdf(title_text.ToString(), true);

            string[] aux = System.IO.Directory.GetFiles(@"C:\Users\user\Desktop\Porudzbine\", "*.aux");
            foreach (string file in aux)
            {
                System.IO.File.Delete(file);
            }
            string[] tex = System.IO.Directory.GetFiles(@"C:\Users\user\Desktop\Porudzbine\", "*.tex");
            foreach (string file in tex)
            {
                System.IO.File.Delete(file);
            }
            string[] log = System.IO.Directory.GetFiles(@"C:\Users\user\Desktop\Porudzbine\", "*.log");
            foreach (string file in log)
            {
                System.IO.File.Delete(file);
            }
            string[] png = System.IO.Directory.GetFiles(@"C:\Users\user\Desktop\Porudzbine\", "*.png");
            foreach (string file in png)
            {
                System.IO.File.Delete(file);
            }

            /*string[] dirs = System.IO.Directory.GetDirectories(@"C:\Users\user\Desktop\Porudzbine\");
             * foreach (string dir in dirs)
             * {
             *  System.IO.File.Delete(dir);
             * }*/
        }