Class: GTK::Printer

Inherits:
Object
  • Object
show all
Defined in:
lib/gtk_webkit_pdf/gtk_printer_pdf.rb,
ext/gtk_webkit_pdf/printer.c

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePrinter

Returns a new instance of Printer.



5
6
7
# File 'lib/gtk_webkit_pdf/gtk_printer_pdf.rb', line 5

def initialize
  @tempfile = Tempfile.new(Time.now.to_s)
end

Instance Attribute Details

#tempfileObject

Returns the value of attribute tempfile.



3
4
5
# File 'lib/gtk_webkit_pdf/gtk_printer_pdf.rb', line 3

def tempfile
  @tempfile
end

Instance Method Details

#delete_pdfObject



17
# File 'lib/gtk_webkit_pdf/gtk_printer_pdf.rb', line 17

def delete_pdf; tempfile.delete; end

#export(base_url, name) ⇒ Object



11
12
13
# File 'lib/gtk_webkit_pdf/gtk_printer_pdf.rb', line 11

def export(base_url, name)
  File.open(File.join(base_url, name), 'w+'){ |f| f.write pdf_content }
end

#pdf_contentObject



9
# File 'lib/gtk_webkit_pdf/gtk_printer_pdf.rb', line 9

def pdf_content; File.read(tempfile); end

#temp_pathObject



15
# File 'lib/gtk_webkit_pdf/gtk_printer_pdf.rb', line 15

def temp_path; tempfile.path; end

#webkit_webframe_to_pdf(source) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'ext/gtk_webkit_pdf/printer.c', line 14

static VALUE c_webkit_webframe_to_pdf(VALUE self, VALUE source) {
  VALUE temp_path;
  WEBKIT_PRINTER_PTR(self, source);

  //PRINTER CONFIGURATIONS
  set_printer_configurations(self);

  //EXPORT PDF FROM WEBKIT WEBFRAME
  temp_path = rb_funcall(self, rb_intern("temp_path"), 0, 0);
  gtk_print_operation_set_export_filename(printer -> gtk_print_operation, StringValuePtr(temp_path));
  printer -> gtk_print_operation_result = webkit_web_frame_print_full(webkit -> webkit_webframe,
                                         printer -> gtk_print_operation, GTK_PRINT_OPERATION_ACTION_EXPORT, NULL);

  if(printer -> gtk_print_operation_result == GTK_PRINT_OPERATION_RESULT_APPLY) {
    g_object_unref(printer -> gtk_print_settings);
    printer -> gtk_print_settings = g_object_ref(gtk_print_operation_get_print_settings(printer -> gtk_print_operation));
    printer -> print_status = Qtrue;
  }
  g_object_unref(printer -> gtk_print_operation);
  return printer -> print_status == Qtrue ? self : Qnil;
}