Hi, 

as there was no responded so far I tried to track the problem deeper and did a 
short test
client in C/C++ to verify if I can call WKHTMLTOPDF there and generate a PDF 
and to 
compare to the Pharo/NativeBoost client. 

Attached is the according CPP file which works and results in a PDF with the 
google 
homepage. 

I also additionally implemented the callback functions in the Pharo wrapper and 
using the error handling I noticed that the component returns "Failed loading 
page http:// ..."


With that info I compared the C/C++ calls to the Pharo/NativeBoost calls more 
deeply and 
found out that in C/C++ the following call for an object setting works (by 
returning 1):


        // this returns 1 in C/C++ which is OK
        int a = wkhtmltopdf_set_object_setting(os, "page", 
"http://www.google.de";);
        printf("object set %i",a);


while in Pharo the same call fails (by returning 0):

        "The following call failed and returns 0 instead of 1"
        self setObjectSetting: 'page' to: 'http://www.google.de' in: os.

I checked how I wrapped this API call again and again - it is fine from my side:

    setObjectSetting: aName to: value in: settings

        <primitive: #primitiveNativeCall module: #NativeBoostPlugin>

         ^NBFFICallout stdcall: #(int 
wkhtmltopdf_set_object_setting(wkhtmltopdf_object_settings* settings, char* 
aName, char* value)) module: 'wkhtmltox.dll'  

and I still have no idea why it fails. 

Especially because "wkhtmltopdf_set_object_setting" function is not different 
from "wkhtmltopdf_set_global_setting" which is exactly the same way wrapped, 
works 
and returns 1 in exactly the same example.

I would really appreciate if someone could have a second look...

To reproduce on Windows:

 1. Download the 32 bit version of WKHTML from http://wkhtmltopdf.org and 
install it
 2. Copy the "wkhtmltox.dll" to either the folder of the VM executable
    or the Windows directory so it can be found
 3. Load the package WKHTML2PDF-Core-TorstenBergmann.7 
    from http://smalltalkhub.com/#!/~TorstenBergmann/WKHTML2PDF into Pharo 
3.0#30848
 4. Check the Transcript while evaluating:

        WKPDFLibrary example

    One can see that within this code #setObjectSetting:to:in: fails while 
#setGlobalSetting:to:in:
    works.

Maybe I just do not see the obvious. Help is appreciated. Thanks in advance!

bye
T.
 

/* 
 * File:   main.cpp
 * Author: TB
 *
 * Created on 22. Mai 2014, 22:40
 */

#include <stdio.h>
#include <stdlib.h>

#include <stdbool.h>

extern "C" {
#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) {
         
        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", "c:\\temp\\test.pdf");
        
        os = wkhtmltopdf_create_object_settings();

        // this returns 1 in C/C++ which is OK
        int a = wkhtmltopdf_set_object_setting(os, "page", 
"http://www.google.de";);
        printf("object set %i",a);
         
        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;
}

Reply via email to