private static void Main(string[] args) { // Create the LatexEngine // Here you can pass a Configuration, otherwise // LatexEngine searches Configuration.xml // in the current directory and if it is not there // he searches it in ./Config/ var engine = new LatexEngine(); // Create an object, that you can use in your LaTeX var o = new { Value = 25, x = false, y = true, z = false, Headers = new string[] { "First", "Second", "Third", "Fourth" }, Entries = new[] { new[] { "11", "12", "13", "14" }, new[] { "21", "22", "23", "24" }, new[] { "31", "32", "33", "34" }, new[] { "41", "42", "43", "44" }, new[] { "51", "52", "53", "54" }, new[] { "61", "62", "63", "64" }, }, }; // Create the PDF var src = new FileInfo("TestFile.tex"); var dest = new FileInfo("TestFile.pdf"); using (var srcStream = src.OpenRead()) using (var destStream = new FileStream(dest.FullName, FileMode.Create)) engine.Generate(srcStream, o, destStream); // Show the PDF Process.Start(dest.FullName); }
public void LatexEngineTestTex() { string result; var o = new MyObject(); // locate miktexdummy.exe var miktexdummyFile = new FileInfo(typeof(miktexdummy.Program).Assembly.Location); if (!miktexdummyFile.Exists) { throw new System.Exception("Cannot find 'miktexdummy.exe'"); } // setup engine to use miktexdummy.exe var engine = new LatexEngine(new LatexEngine.TexConfig() { Command = miktexdummyFile.FullName, }); var input = @"%####% %## ##% %####% \documentclass{article} \usepackage{bchart} \begin{document} \begin{bchart}[step=2,max=10] {####} {## ##} {## print o.Value; ##} {## print o.Value2; ##} {## if (o.x) { ##} \bcbar{3.4} \smallskip {## } else if (o.y) { ##} \bcbar{5.6} \medskip {## } else if (o.z) { ##} \bcbar{7.2} \bigskip {## } else { ##} \bcbar{9.9} {## } ##} \end{bchart} \end{document}"; // testing using (var mem = new MemoryStream()) { using (var writer = new StreamWriter(mem, Encoding.UTF8, 1024, leaveOpen: true)) writer.Write(input); // reset position to start mem.Position = 0; // generate using (var memOut = new MemoryStream()) { engine.Generate(mem, o, memOut); // reset position to start memOut.Position = 0; // check output string output = null; using (var reader = new StreamReader(memOut, Encoding.UTF8, true, 1024, leaveOpen: true)) output = reader.ReadToEnd(); Assert.AreEqual(@"Ich bin ein PDF :D " + @" " + @" " + @" \documentclass{article} " + @" \usepackage{bchart} " + @" \begin{document} \begin{bchart}[step=2,max=10] " + @" " + @" " + o.Value.ToString() + @" " + o.Value2.ToString() + @" " + @" \bcbar{9.9} " + @" \end{bchart} \end{document}", output); } } }