gtk_webkit_pdf 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +6 -2
- data/ext/gtk_webkit_pdf/printer.c +37 -0
- data/ext/gtk_webkit_pdf/printer.h +4 -0
- data/ext/gtk_webkit_pdf/printer_utility.c +26 -0
- data/ext/gtk_webkit_pdf/printer_utility.h +32 -0
- data/ext/gtk_webkit_pdf/utility.c +24 -39
- data/ext/gtk_webkit_pdf/utility.h +28 -14
- data/ext/gtk_webkit_pdf/webkit.c +12 -13
- data/ext/gtk_webkit_pdf/webkit.h +3 -2
- data/gtk_webkit_pdf.gemspec +2 -2
- data/lib/gtk_webkit_pdf/gtk_webkit_pdf.rb +2 -3
- metadata +6 -2
data/README
CHANGED
@@ -2,9 +2,13 @@ Creating The PDF from HTML using GTK WEBKIT Tool.
|
|
2
2
|
|
3
3
|
EXAMPLE:
|
4
4
|
|
5
|
-
webkit = GTK::Webkit.new(
|
6
|
-
webkit.convert_to_pdf #creates the pdf specified in the initialization parameter(in our case gtk.pdf) in current directory
|
5
|
+
webkit = GTK::Webkit.new(url) #creates the webkit object
|
6
|
+
webkit.convert_to_pdf(path, pdf_name) #creates the pdf specified in the initialization parameter(in our case gtk.pdf) in current directory
|
7
7
|
|
8
|
+
Parameters Description:
|
9
|
+
1 . url => Actual webkit URL. Ex http://www.gtk.org/, http://www.google.com
|
10
|
+
2 . path => System path, where the pdf will be saved. Ex: /home/user/Documents/
|
11
|
+
3 . pdf_name => Actual name to PDF file. Ex: gtk.pdf, google.pdf
|
8
12
|
|
9
13
|
|
10
14
|
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#include<ruby.h>
|
2
|
+
#include <gtk/gtk.h>
|
3
|
+
#include <webkit/webkit.h>
|
4
|
+
#include<printer.h>
|
5
|
+
|
6
|
+
VALUE cPrinter = Qnil;
|
7
|
+
|
8
|
+
static VALUE c_printer_new(VALUE self) {
|
9
|
+
printer_wrapper *printer;
|
10
|
+
VALUE data_object = Data_Make_Struct(self, printer_wrapper, 0, free_printer, printer);
|
11
|
+
gtk_init(NULL, NULL);
|
12
|
+
init_printer_configurations(data_object);
|
13
|
+
return data_object;
|
14
|
+
}
|
15
|
+
|
16
|
+
static VALUE c_export_to_pdf(VALUE self, VALUE source, VALUE directory_path, VALUE file_name) {
|
17
|
+
char *pdf_path;
|
18
|
+
WEBKIT_PRINTER_PTR(self, source);
|
19
|
+
STR_CON_CAT(directory_path, file_name);
|
20
|
+
gtk_print_operation_set_export_filename(printer -> gtk_print_operation, pdf_path);
|
21
|
+
printer -> gtk_print_operation_result = webkit_web_frame_print_full(webkit -> webkit_webframe,
|
22
|
+
printer -> gtk_print_operation, GTK_PRINT_OPERATION_ACTION_EXPORT, NULL);
|
23
|
+
|
24
|
+
if(printer -> gtk_print_operation_result == GTK_PRINT_OPERATION_RESULT_APPLY) {
|
25
|
+
g_object_unref(printer -> gtk_print_settings);
|
26
|
+
printer -> gtk_print_settings = g_object_ref(gtk_print_operation_get_print_settings(printer -> gtk_print_operation));
|
27
|
+
printer -> print_status = Qtrue;
|
28
|
+
}
|
29
|
+
g_object_unref(printer -> gtk_print_operation);
|
30
|
+
return printer -> print_status;
|
31
|
+
}
|
32
|
+
|
33
|
+
void init_printer() {
|
34
|
+
cPrinter = rb_define_class_under(cGTK, "Printer", rb_cObject);
|
35
|
+
rb_define_singleton_method(cPrinter, "new", c_printer_new, 0);
|
36
|
+
rb_define_private_method(cPrinter, "export_to_pdf", c_export_to_pdf, 3);
|
37
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#include <printer_utility.h>
|
2
|
+
|
3
|
+
void free_printer(void *void_printer) {
|
4
|
+
printer_wrapper *printer = void_printer;
|
5
|
+
free(printer);
|
6
|
+
}
|
7
|
+
|
8
|
+
void init_printer_configurations(VALUE self) {
|
9
|
+
PRINTER_PTR(self);
|
10
|
+
printer -> gtk_print_settings = NULL;
|
11
|
+
printer -> gtk_print_operation = gtk_print_operation_new();
|
12
|
+
|
13
|
+
if(printer -> gtk_print_settings != NULL)
|
14
|
+
gtk_print_operation_set_print_settings(printer -> gtk_print_operation, printer -> gtk_print_settings);
|
15
|
+
|
16
|
+
g_signal_connect(printer -> gtk_print_operation, "begin_print", G_CALLBACK(begin_print), NULL);
|
17
|
+
g_signal_connect(printer -> gtk_print_operation, "draw_page", G_CALLBACK(draw_page), NULL);
|
18
|
+
}
|
19
|
+
|
20
|
+
void begin_print() {
|
21
|
+
//begin print callback
|
22
|
+
}
|
23
|
+
|
24
|
+
void draw_page() {
|
25
|
+
//draw page callback
|
26
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#ifndef printer_utility_h__
|
2
|
+
#define printer_utility_h__
|
3
|
+
|
4
|
+
#include <ruby.h>
|
5
|
+
#include <gtk/gtk.h>
|
6
|
+
#include <webkit/webkit.h>
|
7
|
+
#include <stdlib.h>
|
8
|
+
#include <utility.h>
|
9
|
+
|
10
|
+
typedef struct {
|
11
|
+
GtkPrintSettings *gtk_print_settings;
|
12
|
+
GtkPrintOperation *gtk_print_operation;
|
13
|
+
GtkPrintOperationResult gtk_print_operation_result;
|
14
|
+
VALUE print_status;
|
15
|
+
} printer_wrapper;
|
16
|
+
|
17
|
+
extern void free_printer(void *void_printer);
|
18
|
+
extern void init_printer_configurations(VALUE self);
|
19
|
+
extern void begin_print();
|
20
|
+
extern void draw_page();
|
21
|
+
|
22
|
+
extern VALUE cGTK;
|
23
|
+
|
24
|
+
#define PRINTER_PTR(self) printer_wrapper *printer; \
|
25
|
+
Data_Get_Struct(self, printer_wrapper, printer);
|
26
|
+
|
27
|
+
#define WEBKIT_PRINTER_PTR(printer_self, webkit_self) webkit_wrapper *webkit; \
|
28
|
+
printer_wrapper *printer; \
|
29
|
+
Data_Get_Struct(webkit_self, webkit_wrapper, webkit); \
|
30
|
+
Data_Get_Struct(printer_self, printer_wrapper, printer);
|
31
|
+
|
32
|
+
#endif
|
@@ -5,52 +5,37 @@ void free_webkit(void *void_webkit) {
|
|
5
5
|
free(webkit);
|
6
6
|
}
|
7
7
|
|
8
|
-
void
|
9
|
-
webkit
|
10
|
-
webkit
|
11
|
-
|
8
|
+
void mark_webkit_printer(void *void_webkit) {
|
9
|
+
webkit_wrapper *webkit = void_webkit;
|
10
|
+
if(webkit) {
|
11
|
+
rb_gc_mark(webkit -> data_printer);
|
12
|
+
rb_gc_mark(webkit -> print_status);
|
13
|
+
}
|
12
14
|
}
|
13
15
|
|
14
|
-
void
|
16
|
+
void activate_gtk_webkit(VALUE self) {
|
17
|
+
WEBKIT_PTR(self);
|
18
|
+
webkit -> data_printer = Qnil;
|
19
|
+
webkit -> webkit_webview = WEBKIT_WEB_VIEW(webkit_web_view_new());
|
15
20
|
webkit_web_view_load_uri(webkit -> webkit_webview, webkit -> webkit_url);
|
16
|
-
g_signal_connect(webkit -> webkit_webview, "load-finished", G_CALLBACK(webkit_load_finished),
|
21
|
+
g_signal_connect(webkit -> webkit_webview, "load-finished", G_CALLBACK(webkit_load_finished), (void *)self);
|
17
22
|
}
|
18
23
|
|
19
|
-
void webkit_load_finished(WebKitWebView *webView, WebKitWebFrame *webkitwebframe,
|
20
|
-
|
21
|
-
|
22
|
-
webkit -> gtk_print_operation_result = webkit_web_frame_print_full(webkit -> webkit_webframe,
|
23
|
-
webkit -> gtk_print_operation, GTK_PRINT_OPERATION_ACTION_EXPORT, NULL);
|
24
|
-
actual_print_operation(webkit);
|
25
|
-
}
|
26
|
-
|
27
|
-
void activate_printer(webkit_wrapper *webkit) {
|
24
|
+
void webkit_load_finished(WebKitWebView *webView, WebKitWebFrame *webkitwebframe, void *self) {
|
25
|
+
VALUE argv[3];
|
26
|
+
WEBKIT_PTR(CAST_TO_VALUE(self));
|
28
27
|
webkit -> webkit_webframe = webkit_web_view_get_main_frame(webkit -> webkit_webview);
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
webkit ->
|
34
|
-
|
35
|
-
gtk_print_operation_set_print_settings(webkit -> gtk_print_operation, webkit -> gtk_print_settings);
|
36
|
-
g_signal_connect(webkit -> gtk_print_operation, "begin_print", G_CALLBACK(begin_print), NULL);
|
37
|
-
g_signal_connect(webkit -> gtk_print_operation, "draw_page", G_CALLBACK(draw_page), NULL);
|
38
|
-
}
|
39
|
-
|
40
|
-
void actual_print_operation(webkit_wrapper *webkit) {
|
41
|
-
if(webkit -> gtk_print_operation_result == GTK_PRINT_OPERATION_RESULT_APPLY) {
|
42
|
-
g_object_unref(webkit -> gtk_print_settings);
|
43
|
-
webkit -> gtk_print_settings = g_object_ref(gtk_print_operation_get_print_settings(webkit -> gtk_print_operation));
|
44
|
-
webkit -> print_status = Qtrue;
|
45
|
-
}
|
46
|
-
g_object_unref(webkit -> gtk_print_operation);
|
28
|
+
|
29
|
+
webkit -> data_printer = rb_funcall(cPrinter, rb_intern("new"), 0);
|
30
|
+
argv[0] = CAST_TO_VALUE(self);
|
31
|
+
argv[1] = C_TO_RUBY_STR(webkit -> dir_path);
|
32
|
+
argv[2] = C_TO_RUBY_STR(webkit -> pdf_filename);
|
33
|
+
webkit -> print_status = rb_funcall2(webkit -> data_printer, rb_intern("export_to_pdf"), 3, argv);
|
47
34
|
gtk_main_quit();
|
48
35
|
}
|
49
36
|
|
50
|
-
void
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
void draw_page() {
|
55
|
-
//draw page callback
|
37
|
+
void set_pdf_configurations(VALUE self, VALUE dir_path, VALUE pdf_filename) {
|
38
|
+
WEBKIT_PTR(self);
|
39
|
+
webkit -> dir_path = StringValuePtr(dir_path);
|
40
|
+
webkit -> pdf_filename = StringValuePtr(pdf_filename);
|
56
41
|
}
|
@@ -7,24 +7,38 @@
|
|
7
7
|
|
8
8
|
typedef struct {
|
9
9
|
WebKitWebView *webkit_webview;
|
10
|
-
char *export_filename;
|
11
|
-
char *webkit_url;
|
12
|
-
|
13
10
|
WebKitWebFrame *webkit_webframe;
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
|
12
|
+
char *webkit_url;
|
13
|
+
char *dir_path;
|
14
|
+
char *pdf_filename;
|
17
15
|
VALUE print_status;
|
16
|
+
VALUE data_printer;
|
18
17
|
} webkit_wrapper;
|
19
18
|
|
20
|
-
extern void webkit_load_finished(WebKitWebView *webView, WebKitWebFrame *webkitwebframe,
|
21
|
-
extern void begin_print();
|
22
|
-
extern void draw_page();
|
19
|
+
extern void webkit_load_finished(WebKitWebView *webView, WebKitWebFrame *webkitwebframe, void *self);
|
23
20
|
|
24
|
-
extern void initialize_webkit(webkit_wrapper *webkit);
|
25
21
|
extern void free_webkit(void *void_webkit);
|
26
|
-
extern void
|
27
|
-
extern void
|
28
|
-
extern void
|
29
|
-
|
22
|
+
extern void mark_webkit_printer(void *void_webkit);
|
23
|
+
extern void activate_gtk_webkit(VALUE self);
|
24
|
+
extern void set_pdf_configurations(VALUE self, VALUE dir_path, VALUE pdf_filename);
|
25
|
+
|
26
|
+
extern void init_printer();
|
27
|
+
extern VALUE cPrinter;
|
28
|
+
|
29
|
+
#define WEBKIT_PTR(self) webkit_wrapper *webkit; \
|
30
|
+
Data_Get_Struct(self, webkit_wrapper, webkit);
|
31
|
+
|
32
|
+
#define C_TO_RUBY_STR(str) rb_str_new2(str)
|
33
|
+
|
34
|
+
#define RUBY_TO_C_STR(str) StringValuePtr(str)
|
35
|
+
|
36
|
+
#define CAST_TO_VALUE(value) (VALUE)value
|
37
|
+
|
38
|
+
#define STR_CON_CAT(dir, name) pdf_path = malloc(strlen(RUBY_TO_C_STR(dir)) + strlen(RUBY_TO_C_STR(name)) + 1); \
|
39
|
+
if(pdf_path != NULL) { \
|
40
|
+
strcpy(pdf_path, RUBY_TO_C_STR(dir)); \
|
41
|
+
strcpy(&pdf_path[strlen(RUBY_TO_C_STR(dir))], RUBY_TO_C_STR(name)); \
|
42
|
+
} \
|
43
|
+
|
30
44
|
#endif
|
data/ext/gtk_webkit_pdf/webkit.c
CHANGED
@@ -6,25 +6,22 @@
|
|
6
6
|
VALUE cGTK = Qnil;
|
7
7
|
VALUE cWebkit = Qnil;
|
8
8
|
|
9
|
-
static VALUE c_new(VALUE self, VALUE webkit_url
|
9
|
+
static VALUE c_new(VALUE self, VALUE webkit_url) {
|
10
10
|
webkit_wrapper *webkit;
|
11
|
-
VALUE argv[
|
12
|
-
VALUE data_object = Data_Make_Struct(self, webkit_wrapper,
|
11
|
+
VALUE argv[1];
|
12
|
+
VALUE data_object = Data_Make_Struct(self, webkit_wrapper, mark_webkit_printer, free_webkit, webkit);
|
13
13
|
webkit -> webkit_url = StringValuePtr(webkit_url);
|
14
|
-
webkit -> export_filename = StringValuePtr(export_filename);
|
15
14
|
|
16
15
|
argv[0] = webkit_url;
|
17
|
-
|
18
|
-
rb_obj_call_init(data_object, 2, argv);
|
16
|
+
rb_obj_call_init(data_object, 1, argv);
|
19
17
|
return data_object;
|
20
18
|
}
|
21
19
|
|
22
|
-
static VALUE c_convert_to_pdf(VALUE self) {
|
23
|
-
|
20
|
+
static VALUE c_convert_to_pdf(VALUE self, VALUE dir_path, VALUE pdf_filename) {
|
21
|
+
WEBKIT_PTR(self);
|
24
22
|
gtk_init(NULL, NULL);
|
25
|
-
|
26
|
-
|
27
|
-
activate_webkit(webkit);
|
23
|
+
set_pdf_configurations(self, dir_path, pdf_filename);
|
24
|
+
activate_gtk_webkit(self);
|
28
25
|
gtk_main();
|
29
26
|
return webkit -> print_status;
|
30
27
|
}
|
@@ -32,6 +29,8 @@ static VALUE c_convert_to_pdf(VALUE self) {
|
|
32
29
|
void Init_webkit(void) {
|
33
30
|
cGTK = rb_define_module("GTK");
|
34
31
|
cWebkit = rb_define_class_under(cGTK, "Webkit", rb_cObject);
|
35
|
-
rb_define_singleton_method(cWebkit, "new", c_new,
|
36
|
-
rb_define_method(cWebkit, "convert_to_pdf", c_convert_to_pdf,
|
32
|
+
rb_define_singleton_method(cWebkit, "new", c_new, 1);
|
33
|
+
rb_define_method(cWebkit, "convert_to_pdf", c_convert_to_pdf, 2);
|
34
|
+
|
35
|
+
init_printer();
|
37
36
|
}
|
data/ext/gtk_webkit_pdf/webkit.h
CHANGED
data/gtk_webkit_pdf.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'gtk_webkit_pdf'
|
3
|
-
s.version = '0.0.
|
4
|
-
s.date = '2013-01-
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.date = '2013-01-04'
|
5
5
|
s.summary = "GTK WEBKIT"
|
6
6
|
s.description = "Generates the PDF from the HTML using GTK WEBKIT"
|
7
7
|
s.authors = ["Mohanraj Ramanujam"]
|
@@ -1,10 +1,9 @@
|
|
1
1
|
module GTK
|
2
2
|
class Webkit
|
3
|
-
attr_accessor :webkit_url
|
3
|
+
attr_accessor :webkit_url
|
4
4
|
|
5
|
-
def initialize(webkit_url
|
5
|
+
def initialize(webkit_url)
|
6
6
|
@webkit_url = webkit_url
|
7
|
-
@export_filename = export_filename
|
8
7
|
end
|
9
8
|
end
|
10
9
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gtk_webkit_pdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-04 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Generates the PDF from the HTML using GTK WEBKIT
|
15
15
|
email: mohanraj.ramanujam@gmail.com
|
@@ -21,8 +21,12 @@ files:
|
|
21
21
|
- lib/gtk_webkit_pdf/gtk_webkit_pdf.rb
|
22
22
|
- ext/gtk_webkit_pdf/utility.c
|
23
23
|
- ext/gtk_webkit_pdf/webkit.c
|
24
|
+
- ext/gtk_webkit_pdf/printer_utility.c
|
25
|
+
- ext/gtk_webkit_pdf/printer.c
|
26
|
+
- ext/gtk_webkit_pdf/printer.h
|
24
27
|
- ext/gtk_webkit_pdf/utility.h
|
25
28
|
- ext/gtk_webkit_pdf/webkit.h
|
29
|
+
- ext/gtk_webkit_pdf/printer_utility.h
|
26
30
|
- README
|
27
31
|
- gtk_webkit_pdf.gemspec
|
28
32
|
- ext/gtk_webkit_pdf/extconf.rb
|