public void CreatePdf(string template, dynamic context, FileInfo destination)
        {
            // run in temporary directory
            var tempDir = IOExtension.CreateTempDirectory();

            try {
                var texFile = new FileInfo(Path.Combine(tempDir.FullName, "template.tex"));
                using (var writer = new StreamWriter(texFile.FullName))
                    writer.Write(template);
                this.CreatePdf(texFile, context, destination);
            } finally {
                // cleanup temporary directory
                Directory.Delete(tempDir.FullName, true);
            }
        }
        public override void GenerateDynamic(Stream template, dynamic context, Stream output)
        {
            // run in temporary directory
            var tempDir = IOExtension.CreateTempDirectory();

            try {
                var pdfFile = new FileInfo(Path.Combine(tempDir.FullName, "output.pdf"));
                using (var stream = new StreamReader(template, Encoding.UTF8, true, 1024, leaveOpen: true))
                    this.CreatePdf(stream.ReadToEnd(), context, pdfFile);
                using (var stream = File.OpenRead(pdfFile.FullName))
                    stream.WriteTo(output);
            } finally {
                // cleanup temporary directory
                Directory.Delete(tempDir.FullName, true);
            }
        }
 public void CompileInTemporaryDirectory(FileInfo texFile, FileInfo destPdfFile, int count = 2)
 {
     // by default compile twice (count=2), because latex needs it for index and other files
     try {
         var tmpDir     = IOExtension.CreateTempDirectory();
         var texTmpFile = new FileInfo(Path.Combine(tmpDir.FullName, texFile.Name));
         texFile.CopyTo(texTmpFile.FullName);
         for (var i = 0; i < count; ++i)
         {
             this.compile(texTmpFile, destPdfFile);
         }
         tmpDir.Delete(true);
     } catch (Exception ex) {
         if (ex is TexCompilationException)
         {
             throw;
         }
         Debug.WriteLine(ex.Message);
         throw new TexCompilationException("An Error occured while processing file " + texFile.FullName + Environment.NewLine
                                           + "see inner exception for details", ex);
     }
 }