I have encountered problem in using sample code snippet as below which wrap wkhtmltopdf API to convert HTML to PDF in a function:
void convertHTMLtoPDF()
{
wkhtmltopdf_global_settings * gs;
wkhtmltopdf_object_settings * os;
wkhtmltopdf_converter * c;
wkhtmltopdf_init(false);
gs = wkhtmltopdf_create_global_settings();
/* We want the result to be storred in the file called test.pdf */
wkhtmltopdf_set_global_setting(gs, "out", "report.pdf");
os = wkhtmltopdf_create_object_settings();
/* We want to convert to convert the qstring documentation page */
wkhtmltopdf_set_object_setting(os, "page", "report.html");
c = wkhtmltopdf_create_converter(gs);
wkhtmltopdf_add_object(c, os, NULL);
if (!wkhtmltopdf_convert(c))
fprintf(stderr, "Convertion failed!");
/* Output possible http error code encountered */
printf("httpErrorCode: %d\n", wkhtmltopdf_http_error_code(c));
//destroy global settings and object settings
//as well as converter settings wont work
wkhtmltopdf_destroy_global_settings(gs);
wkhtmltopdf_destroy_object_settings(os);
wkhtmltopdf_destroy_converter(c);
}
report.html content is as below:
<!DOCTYPE html>
<html>
<body>
<h2>Sample Report</h2>
<img src="sceneForReport.jpg" alt="scene" style="width:304px;height:228px;">
</body>
</html>
FYI, the image content for sceneForReport.jpg will be changed before every execution of convertHTMLtoPDF() function. However, the pdf generated is the same as the initial generated one even though the image has changed.
Thus, i doubted the wkhtmltopdf_converter is not discarded alongside with object and global settings which still preserve the very first settings. Though, i have tried to destroy it at the end of the function.
Thus, any opinion or help on this or is this library can only be used for only one time once the dll is loaded in and need to be unloaded for second usage?