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_converter_get_output(VALUE self) {
  wkhtmltoimage_converter* converter;
  const unsigned char* data_cstr;
  long length;
  VALUE data;

  Data_Get_Struct(self, wkhtmltoimage_converter, converter);

  length = wkhtmltoimage_get_output(converter, &data_cstr);

  data = rb_str_new((char*)data_cstr, length);
  rb_enc_associate(data, rb_ascii8bit_encoding());

  return data;
}