Forum > Packages and Libraries
PDF Creation using wkhtmltox
(1/1)
sam_des:
Hi,
I have been trying to use the wkhtmltox.dll (64-BIT) with my program to create PDF from HTML file.
I am declaring wrapper functions as follows,
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function wkhtmltopdf_init(useGraphics: Integer): Integer; stdcall; external 'wkhtmltox.dll';procedure wkhtmltopdf_deinit(); stdcall; external 'wkhtmltox.dll'; function wkhtmltopdf_create_global_settings: Pointer; stdcall; external 'wkhtmltox.dll';procedure wkhtmltopdf_set_global_setting(globalSettings: Pointer; name, value: PChar); stdcall; external 'wkhtmltox.dll';procedure wkhtmltopdf_set_global_setting(globalSettings: Pointer; name, value: PChar; vs: Integer); stdcall; external 'wkhtmltox.dll'; function wkhtmltopdf_create_object_settings: Pointer; stdcall; external 'wkhtmltox.dll';procedure wkhtmltopdf_set_object_setting(objectSettings: Pointer; name, value: PChar); stdcall; external 'wkhtmltox.dll';procedure wkhtmltopdf_set_object_setting(objectSettings: Pointer; name, value: PChar; vs: Integer); stdcall; external 'wkhtmltox.dll'; function wkhtmltopdf_create_converter(globalSettings: Pointer): Pointer; stdcall; external 'wkhtmltox.dll';procedure wkhtmltopdf_destroy_converter(pdfConverter: Pointer); stdcall; external 'wkhtmltox.dll'; procedure wkhtmltopdf_add_object(pdfConverter, objectSettings: Pointer; data: PChar); stdcall; external 'wkhtmltox.dll'; function wkhtmltopdf_convert(pdfConverter: Pointer): Integer; stdcall; external 'wkhtmltox.dll';
Then I am calling following code on button click,
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var globalSettings : Pointer; objectSettings : Pointer; pdfConverter : Pointer;begin if wkhtmltopdf_init(0) <> 0 then begin globalSettings := wkhtmltopdf_create_global_settings(); wkhtmltopdf_set_global_setting(globalSettings, PChar('out'), PChar('test.pdf')); wkhtmltopdf_set_global_setting(globalSettings, PChar('size.PageSize'), PChar('A4')); wkhtmltopdf_set_global_setting(globalSettings, PChar('orientation'), PChar('Landscape')); objectSettings := wkhtmltopdf_create_object_settings(); wkhtmltopdf_set_object_setting(objectSettings, PChar('page'), PChar('rpt.html')); wkhtmltopdf_set_object_setting(objectSettings, PChar('load.blockLocalFileAccess'), PChar('false')); wkhtmltopdf_set_object_setting(objectSettings, PChar('header.fontSize'), PChar('10')); wkhtmltopdf_set_object_setting(objectSettings, PChar('header.fontName'), PChar('Arial')); wkhtmltopdf_set_object_setting(objectSettings, PChar('header.right'), PChar('Header Right')); wkhtmltopdf_set_object_setting(objectSettings, PChar('header.line'), PChar('true')); wkhtmltopdf_set_object_setting(objectSettings, PChar('header.spacing'), PChar('5')); wkhtmltopdf_set_object_setting(objectSettings, PChar('footer.fontSize'), PChar('10')); wkhtmltopdf_set_object_setting(objectSettings, PChar('footer.fontName'), PChar('Arial')); wkhtmltopdf_set_object_setting(objectSettings, PChar('footer.left'), PChar('test-left')); wkhtmltopdf_set_object_setting(objectSettings, PChar('footer.right'), PChar('[page] / [topage]')); wkhtmltopdf_set_object_setting(objectSettings, PChar('footer.line'), PChar('true')); wkhtmltopdf_set_object_setting(objectSettings, PChar('footer.spacing'), PChar('5')); pdfConverter := wkhtmltopdf_create_converter(globalSettings); wkhtmltopdf_add_object(pdfConverter, objectSettings, nil); //<------------ Problem if wkhtmltopdf_convert(pdfConverter) = 0 then begin //<------------ Exception MessageDlg('PDF', 'Conversion Failed', mtInformation, [mbOK], 0); end; wkhtmltopdf_destroy_converter(pdfConverter); wkhtmltopdf_deinit(); end else begin; MessageDlg('PDF', 'Init Failed', mtInformation, [mbOK], 0); end;end;
I am facing problem with line..
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- wkhtmltopdf_add_object(pdfConverter, objectSettings, nil);
Since I want to convert local html file, as per docs, I need to pass nil as 3rd argument.
But I get the exception "FLT INVALID OPERATION' when next line is executed.
If I pass, PChar('somestring') instead of nil then PDF gets generated with 'somestring' & all the header/footer object settings as expected.
Also I have tried the same html file with same dll, only in c++ and I get entire PDF as expected.
Any help would be greatly appreciated.
sam_des
Navigation
[0] Message Index