Created
October 28, 2012 02:54
-
-
Save cjpartridgeb/3967266 to your computer and use it in GitHub Desktop.
First foray into c++ land - getting node: malloc(): memory corruptio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"targets": [ | |
{ | |
"target_name": "wkhtmltox", | |
"sources": [ "wkhtmltox-google.cpp" ], | |
"include_dirs": ["/include"], | |
"libraries": ["-lwkhtmltox"] | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <node.h> | |
#include <wkhtmltox/pdf.h> | |
using namespace v8; | |
Handle<Value> Pdf(const Arguments& args) { | |
HandleScope scope; | |
Local<Function> callback = Local<Function>::Cast(args[0]); | |
wkhtmltopdf_init(0); | |
wkhtmltopdf_global_settings *global_settings = wkhtmltopdf_create_global_settings(); | |
wkhtmltopdf_set_global_setting(global_settings, "out", "google.pdf"); | |
wkhtmltopdf_converter *c = wkhtmltopdf_create_converter(global_settings); | |
wkhtmltopdf_object_settings *object_settings = wkhtmltopdf_create_object_settings(); | |
wkhtmltopdf_set_object_setting(object_settings, "page", "www.google.com"); | |
wkhtmltopdf_add_object(c, object_settings, NULL); | |
wkhtmltopdf_convert(c); | |
const unsigned argc = 3; | |
Local<Value> argv[argc] = { | |
Local<Value>::New(Null()), | |
Local<Value>::New(Integer::New(0)), | |
Local<Value>::New(String::New(wkhtmltopdf_version())) | |
}; | |
callback->Call(Context::GetCurrent()->Global(), argc, argv); | |
return Undefined(); | |
} | |
void RegisterModule(Handle<Object> target) { | |
target->Set(String::NewSymbol("pdf"), | |
FunctionTemplate::New(Pdf)->GetFunction()); | |
} | |
NODE_MODULE(wkhtmltox, RegisterModule); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment