Required files:
1. Run the dll file required by wkhtmltopdf, for example:
2. Required lib library files, such:
3. The required include files, such:
Dev-C ++ Configuration:
1. Add the lib file to the project.
2. Add the lib directory to the project.
3. Add the include directory to the project.
[Cpp]
# Include <stdio. h>
# Include <stdlib. h>
# Include <stdbool. h>
# Include <wkhtmltox \ pdf. h>
Void progress_changed (wkhtmltopdf_converter * c, int p ){
Printf ("% 3d % \ r", p );
Fflush (stdout );
}
Void phase_changed (wkhtmltopdf_converter * c ){
Int phase = wkhtmltopdf_current_phase (c );
Printf ("% s \ n", wkhtmltopdf_phase_description (c, phase ));
}
Void error (wkhtmltopdf_converter * c, const char * msg ){
Fprintf (stderr, "Error: % s \ n", msg );
}
Void warning (wkhtmltopdf_converter * c, const char * msg ){
Fprintf (stderr, "Warning: % s \ n", msg );
}
Int main (int argc, char * argv []) {
If (argc! = 3 ){
Fprintf (stderr, "Usage: html2pdf <url> <filename> \ r \ n ");
Return-1;
}
Wkhtmltopdf_global_settings * gs;
Wkhtmltopdf_object_settings * OS;
Wkhtmltopdf_converter * c;
Wkhtmltopdf_init (false );
Gs = wkhtmltopdf_create_global_settings ();
Wkhtmltopdf_set_global_setting (gs, "out", argv [2]);
OS = wkhtmltopdf_create_object_settings ();
Wkhtmltopdf_set_object_setting (OS, "page", argv [1]);
C = wkhtmltopdf_create_converter (gs );
Wkhtmltopdf_set_progress_changed_callback (c, progress_changed );
Wkhtmltopdf_set_phase_changed_callback (c, phase_changed );
Wkhtmltopdf_set_error_callback (c, error );
Wkhtmltopdf_set_warning_callback (c, warning );
Wkhtmltopdf_add_object (c, OS, NULL );
If (! Wkhtmltopdf_convert (c ))
Fprintf (stderr, "Convertion failed! ");
Printf ("httpErrorCode: % d \ n", wkhtmltopdf_http_error_code (c ));
Wkhtmltopdf_destroy_converter (c );
Wkhtmltopdf_deinit ();
Return 0;
}