VALUE wkhtml_toimage_converter_http_error_code(VALUE self) { wkhtmltoimage_converter* converter; int http_error_code; Data_Get_Struct(self, wkhtmltoimage_converter, converter); http_error_code = wkhtmltoimage_http_error_code(converter); return http_error_code == 0 ? Qnil : INT2NUM(http_error_code); //0 is treated as success and should be nil }
/* Main method convert image */ int main() { wkhtmltoimage_global_settings * gs; wkhtmltoimage_converter * c; const unsigned char * data; long len; /* Init wkhtmltoimage in graphics less mode */ wkhtmltoimage_init(false); /* * Create a global settings object used to store options that are not * related to input objects, note that control of this object is parsed to * the converter later, which is then responsible for freeing it */ gs = wkhtmltoimage_create_global_settings(); /* We want to convert to convert the qstring documentation page */ wkhtmltoimage_set_global_setting(gs, "in", "http://www.google.com/"); wkhtmltoimage_set_global_setting(gs, "fmt", "jpeg"); /* Create the actual converter object used to convert the pages */ c = wkhtmltoimage_create_converter(gs, NULL); /* Call the progress_changed function when progress changes */ wkhtmltoimage_set_progress_changed_callback(c, progress_changed); /* Call the phase _changed function when the phase changes */ wkhtmltoimage_set_phase_changed_callback(c, phase_changed); /* Call the error function when an error occures */ wkhtmltoimage_set_error_callback(c, error); /* Call the waring function when a warning is issued */ wkhtmltoimage_set_warning_callback(c, warning); /* Perform the actual convertion */ if (!wkhtmltoimage_convert(c)) fprintf(stderr, "Convertion failed!"); /* Output possible http error code encountered */ printf("httpErrorCode: %d\n", wkhtmltoimage_http_error_code(c)); len = wkhtmltoimage_get_output(c, &data); printf("%ld len\n", len); /* Destroy the converter object since we are done with it */ wkhtmltoimage_destroy_converter(c); /* We will no longer be needing wkhtmltoimage funcionality */ wkhtmltoimage_deinit(); return 0; }