private static void Convert(ConversionSource conversionSource)
        {
            var processStartInfo = GetProcessStartInfo();
            var process = Process.Start(processStartInfo);

            process.Convert(conversionSource);
        }
 private static string SerializeToJson(ConversionSource conversionSource)
 {
     using (var stream = new MemoryStream())
     {
         new DataContractJsonSerializer(typeof(ConversionSource)).WriteObject(stream, conversionSource);
         stream.Position = 0;
         return new StreamReader(stream).ReadToEnd();
     }
 }
Exemplo n.º 3
0
        private static void ConvertToPdf(ConversionSource conversionSource)
        {
            using (var wkhtmlToPdfContext = WkHtmlToPdfContext.Create())
            {
                foreach (var globalSetting in conversionSource.GlobalSettings)
                {
                    WkHtmlToX.WkHtmlToPdf.wkhtmltopdf_set_global_setting(wkhtmlToPdfContext.GlobalSettingsPointer,
                                                                         globalSetting.Key,
                                                                         globalSetting.Value);
                }

                foreach (var objectSetting in conversionSource.ObjectSettings)
                {
                    WkHtmlToX.WkHtmlToPdf.wkhtmltopdf_set_object_setting(wkhtmlToPdfContext.ObjectSettingsPointer,
                                                                         objectSetting.Key,
                                                                         objectSetting.Value);
                }

                wkhtmlToPdfContext.Convert(conversionSource.Html);
            }
        }
 private static string SerializeToBase64EncodedString(ConversionSource conversionSource)
 {
     var result = SerializeToJson(conversionSource);
     return System.Convert.ToBase64String(Encoding.UTF8.GetBytes(result));
 }
 private static void WriteToStandardInput(this Process process, ConversionSource conversionSource)
 {
     process.StandardInput.Write(SerializeToBase64EncodedString(conversionSource));
     process.StandardInput.Close();
 }
 private static void Convert(this Process process, ConversionSource conversionSource)
 {
     process.WriteToStandardInput(conversionSource);
     process.WaitForExit();
     RaiseExceptionIfErrorOccured(process);
 }
 private static ConversionSource ToConversionSource(string html, IDictionary<string, string> globalSettings, IDictionary<string, string> objectSettings)
 {
     var conversionSource = new ConversionSource
     {
         Html = html,
         GlobalSettings = globalSettings,
         ObjectSettings = objectSettings
     };
     return conversionSource;
 }