Exemple #1
0
 private static void ObjectSetting(IntPtr settings, string name, bool?value)
 {
     if (value.HasValue)
     {
         WkHtmlToXBinding.wkhtmltopdf_set_object_setting(settings, name, value.Value ? "true" : "false");
     }
 }
Exemple #2
0
 private static void ObjectSetting(IntPtr settings, string name, int?value)
 {
     if (value.HasValue)
     {
         WkHtmlToXBinding.wkhtmltopdf_set_object_setting(settings, name, value.ToString());
     }
 }
Exemple #3
0
        private static byte[] _HtmlToPdf(byte[] bytes, WkHtmlToPdfSettings settings)
        {
            var globalSettings = WkHtmlToXBinding.wkhtmltopdf_create_global_settings();
            var objectSettings = WkHtmlToXBinding.wkhtmltopdf_create_object_settings();


            // Set global and object settings
            FillSettings(globalSettings, objectSettings, settings);

            var converter = WkHtmlToXBinding.wkhtmltopdf_create_converter(globalSettings);

            WkHtmlToXBinding.wkhtmltopdf_set_error_callback(converter,
                                                            (cc, str) => { Console.WriteLine("Error: " + str); });

            WkHtmlToXBinding.wkhtmltopdf_add_object(converter, objectSettings, bytes);
            // WkHtmlToXBinding.wkhtmltopdf_add_object(converter, objectSettings, new byte[] { .. });

            if (!WkHtmlToXBinding.wkhtmltopdf_convert(converter))
            {
                return(null);
            }

            var ret = GetConversionResult(converter);

            // Destroy all
            WkHtmlToXBinding.wkhtmltopdf_destroy_global_settings(globalSettings);
            WkHtmlToXBinding.wkhtmltopdf_destroy_object_settings(objectSettings);
            WkHtmlToXBinding.wkhtmltopdf_destroy_converter(converter);

            return(ret);
        }
Exemple #4
0
 private static void ObjectSetting(IntPtr settings, string name, double?value)
 {
     if (value.HasValue)
     {
         WkHtmlToXBinding.wkhtmltopdf_set_object_setting(settings, name,
                                                         value.Value.ToString("0.##", CultureInfo.InvariantCulture));
     }
 }
Exemple #5
0
        private static byte[] GetConversionResult(IntPtr converter)
        {
            var length = WkHtmlToXBinding.wkhtmltopdf_get_output(converter, out var resultPointer);
            var result = new byte[length];

            Marshal.Copy(resultPointer, result, 0, length);

            return(result);
        }
Exemple #6
0
        private static void ObjectSetting(IntPtr settings, string name, string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return;
            }

            WkHtmlToXBinding.wkhtmltopdf_set_object_setting(settings, name, value);
        }
Exemple #7
0
        private static void Run()
        {
            if (WkHtmlToXBinding.wkhtmltopdf_init(0) != 1)
            {
                throw new Exception("Could not initialize WkHtmlToPDF library");
            }

            while (!_kill)
            {
                //get next conversion taks from blocking collection
                Task task = Conversions.Take();

                lock (task)
                {
                    //run taks on thread that called RunSynchronously method
                    task.RunSynchronously();

                    //notify caller thread that task is completed
                    Monitor.Pulse(task);
                }
            }
        }
Exemple #8
0
 private static int SetObjectSetting(IntPtr settings, string name, string value)
 {
     return(WkHtmlToXBinding.wkhtmltopdf_set_object_setting(settings, name, value));
 }
Exemple #9
0
 private static int SetGlobalSetting(IntPtr settings, string name, string value)
 {
     return(WkHtmlToXBinding.wkhtmltopdf_set_global_setting(settings, name, value));
 }
Exemple #10
0
 public static bool ExtendedQt()
 {
     return(WkHtmlToXBinding.wkhtmltopdf_extended_qt() == 1);
 }
Exemple #11
0
 public static string GetVersion()
 {
     return(Marshal.PtrToStringAnsi(WkHtmlToXBinding.wkhtmltopdf_version()));
 }