public void Export(string markdownType, string sourceCodePath, string cssFile, string outputPath) { var tmpHtmlPath = Path.GetDirectoryName(sourceCodePath) + "\\~" + Path.GetRandomFileName() + ".html";; DocumentExporter.Export("Html", markdownType, cssFile, sourceCodePath, tmpHtmlPath); if (File.Exists(outputPath)) { File.Delete(outputPath); } //File.WriteAllBytes(outputPath, HtmlToXConverter.ConvertToPdf(File.ReadAllText(tmpFilePath))); Process process = new Process(); process.StartInfo.FileName = "WkHtmlToPdfWrapper"; process.StartInfo.Arguments = $"\"{tmpHtmlPath}\" \"{outputPath}\""; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.Start(); process.WaitForExit(); if (process.ExitCode != 0) { throw new Exception(Properties.Resources.ErrorMsgFailedToExport + "\n" + "wkhtmltopdf error" + process.ExitCode); } File.Delete(tmpHtmlPath); }
public void Export(string markdownType, string sourceCodePath, string cssFile, string outputPath) { var tmpFilePath = Path.GetTempFileName() + ".html"; DocumentExporter.Export("Html", markdownType, cssFile, sourceCodePath, tmpFilePath); if (File.Exists(outputPath)) { File.Delete(outputPath); } Process process = new Process(); process.StartInfo.FileName = "WkHtmlToImageWrapper"; process.StartInfo.Arguments = $"\"{tmpFilePath}\" \"{outputPath}\""; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.Start(); process.WaitForExit(); if (process.ExitCode != 0) { throw new Exception(Properties.Resources.ErrorMsgFailedToExport + "\n" + "wkhtmltoimage error" + process.ExitCode); } //var html = File.ReadAllText(tmpFilePath); //var extension = Path.GetExtension(outputPath).Remove(0, 1).ToLower(); //var image = HtmlToXConverter.ConvertToImage(html, extension, 600, 0); //File.WriteAllBytes(outputPath, image); File.Delete(tmpFilePath); }
private void TimerOnElapsed(object sender, ElapsedEventArgs e) { StreamWriter sw = new StreamWriter(sourcePath); sw.Write(content); sw.Close(); DocumentExporter.Export("Html Local Mathjax", markdownType, cssFile, sourcePath, destPath); //Smodel.ShouldReload = !model.ShouldReload; timer.Stop(); }