Ejemplo n.º 1
0
/* 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;
}
Ejemplo n.º 2
0
VALUE wkhtml_toimage_globalsettings_alloc(VALUE self) {
  wkhtmltoimage_global_settings* settings = wkhtmltoimage_create_global_settings();
  return Data_Wrap_Struct(self, NULL, wkhtml_toimage_globalsettings_free, settings); 
}