Hi Guys.
Fighting with PDF creation in FreePascal and failing on encoding unicode letters ("zażółć gęślą jaźń"
) brought me to use
https://wkhtmltopdf.org. Instead of executing external program I've tried making a wrapper for the so/dll.
The wrapper is very simple and based on C function prototypes found in include files bundled with WkHtmlToPDF. Everything is working fine on Linux and Windows 64-bit architecture, however I'm the problem is executing the converter on 32-bit. I assume that I have made a mistake in Pascal external prototypes, but I'm completely clueless where.
Pascal prototypes :
function wkhtmltopdf_init(use_graphics : Integer) : Integer; cdecl; external 'wkhtmltox.dll';
function wkhtmltopdf_deinit : Integer; cdecl; external 'wkhtmltox.dll';
function wkhtmltopdf_extended_qt : Integer; cdecl; external 'wkhtmltox.dll';
function wkhtmltopdf_version : PChar; cdecl; external 'wkhtmltox.dll';
function wkhtmltopdf_create_global_settings : Pointer; cdecl; external 'wkhtmltox.dll';
procedure wkhtmltopdf_destroy_global_settings(settings : Pointer); cdecl; external 'wkhtmltox.dll';
function wkhtmltopdf_create_object_settings : Pointer; cdecl; external 'wkhtmltox.dll';
procedure wkhtmltopdf_destroy_object_settings(settings : Pointer); cdecl; external 'wkhtmltox.dll';
function wkhtmltopdf_set_global_setting(settings : Pointer; name, value : PChar) : Integer; cdecl; external 'wkhtmltox.dll';
function wkhtmltopdf_get_global_setting(settings : Pointer; name, value : PChar; vs : Integer) : Integer; cdecl; external 'wkhtmltox.dll';
function wkhtmltopdf_set_object_setting(settings : Pointer; name, value : PChar) : Integer; cdecl; external 'wkhtmltox.dll';
function wkhtmltopdf_get_object_setting(settings : Pointer; name, value : PChar; vs : Integer) : Integer; cdecl; external 'wkhtmltox.dll';
function wkhtmltopdf_create_converter(settings : Pointer) : Pointer; cdecl; external 'wkhtmltox.dll';
procedure wkhtmltopdf_destroy_converter(converter : Pointer); cdecl; external 'wkhtmltox.dll';
function wkhtmltopdf_convert(converter : Pointer) : Integer; cdecl; external 'wkhtmltox.dll';
procedure wkhtmltopdf_add_object(converter, object_settings : Pointer; data : PChar); cdecl; external 'wkhtmltox.dll';
function wkhtmltopdf_get_output(converter : Pointer; data : Pointer) : Integer; cdecl; external 'wkhtmltox.dll';
CAPI(int) wkhtmltopdf_init(int use_graphics);
CAPI(int) wkhtmltopdf_deinit();
CAPI(int) wkhtmltopdf_extended_qt();
CAPI(const char *) wkhtmltopdf_version();
CAPI(wkhtmltopdf_global_settings *) wkhtmltopdf_create_global_settings();
CAPI(void) wkhtmltopdf_destroy_global_settings(wkhtmltopdf_global_settings *);
CAPI(wkhtmltopdf_object_settings *) wkhtmltopdf_create_object_settings();
CAPI(void) wkhtmltopdf_destroy_object_settings(wkhtmltopdf_object_settings *);
CAPI(int) wkhtmltopdf_set_global_setting(wkhtmltopdf_global_settings * settings, const char * name, const char * value);
CAPI(int) wkhtmltopdf_get_global_setting(wkhtmltopdf_global_settings * settings, const char * name, char * value, int vs);
CAPI(int) wkhtmltopdf_set_object_setting(wkhtmltopdf_object_settings * settings, const char * name, const char * value);
CAPI(int) wkhtmltopdf_get_object_setting(wkhtmltopdf_object_settings * settings, const char * name, char * value, int vs);
CAPI(wkhtmltopdf_converter *) wkhtmltopdf_create_converter(wkhtmltopdf_global_settings * settings);
CAPI(void) wkhtmltopdf_destroy_converter(wkhtmltopdf_converter * converter);
CAPI(int) wkhtmltopdf_convert(wkhtmltopdf_converter * converter);
CAPI(void) wkhtmltopdf_add_object(
wkhtmltopdf_converter * converter, wkhtmltopdf_object_settings * setting, const char * data);
CAPI(long) wkhtmltopdf_get_output(wkhtmltopdf_converter * converter, const unsigned char **);
Where "CAPI" is :
#ifdef __cplusplus
#define CAPI(type) extern "C" DLL_PUBLIC type CALLTYPE
#else
#define CAPI(type) DLL_PUBLIC type CALLTYPE
#endif
To convert a HTML to PDF one has to call :
- create_global_settings,
- create_converter,
- create_object_settings,
- add_object,
- convert,
- get_output,
- destroy_object_settings,
- destroy_converter,
- destroy_global_settings
I'll push 64-bit version to the customer instead of 32-bit, but I cannot stand that I really don't have a clue where my prototype is wrong.
If someone proficient in C and Pascal could give me a hint, that would really be something.