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.FailedToExport + "\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);
        }
        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.FailedToExport + "\n" + "wkhtmltopdf error" + process.ExitCode);
            }

            File.Delete(tmpHtmlPath);
        }
Ejemplo n.º 3
0
        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            StreamWriter sw = new StreamWriter(sourcePath);

            sw.Write(content);
            sw.Close();

            DocumentExporter.Export("Html Local Mathjax",
                                    markdownType,
                                    cssFile,
                                    sourcePath,
                                    previewPath);

            model.ShouldReload = !model.ShouldReload;
            timer.Stop();
        }
Ejemplo n.º 4
0
        public void Export(string markdownType, string sourceCodePath, string cssFile, string outputPath)
        {
            var tmpFilePath = Path.GetTempFileName() + ".html";

            DocumentExporter.Export("Html", markdownType, cssFile, sourceCodePath, tmpFilePath);

            File.WriteAllBytes(outputPath, HtmlToXConverter.ConvertToPdf(File.ReadAllText(tmpFilePath)));
            //Process process = new Process();
            //process.StartInfo.FileName = "wkhtmltopdf";
            //process.StartInfo.Arguments = $"\"{tmpFilePath}\" \"{outputPath}\"";
            //process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            //process.Start();
            //process.WaitForExit();
            //if (process.ExitCode != 0)
            //    throw new Exception(Properties.Resources.FailedToExport + "\n" + "wkhtmltopdf error" + process.ExitCode);

            File.Delete(tmpFilePath);
        }