3 sudo valac --vapidir=. --thread webkitpdf.vala BrowserWindow.vala --vapidir=./vapi \
4 --pkg glib-2.0 --pkg webkit-1.0 --pkg gtk+-2.0 -o /usr/bin/webkitpdf --target-glib=2.32
6 sudo valac -DGTK3 --vapidir=. --thread webkitpdf.vala BrowserWindow.vala --vapidir=./vapi \
7 --pkg glib-2.0 --pkg webkit2gtk-4.0 --pkg gtk+-3.0 -o /usr/bin/webkitpdf2 --target-glib=2.32
12 public class webkitpdf {
14 public static string? opt_url = null;
15 public static uint opt_delay = 0;
16 public static int opt_width = 0;
17 public static int opt_height = 0;
18 public static string? opt_target_png = null;
19 public static string? opt_target_pdf = null;
20 [CCode (array_length = false, array_null_terminated = true)]
21 public static string[] opt_inject_js;
22 const OptionEntry[] options = {
24 { "width", 0, 0, OptionArg.INT, ref opt_width, "Width (default 1200)", null },
25 { "height", 0, 0, OptionArg.INT, ref opt_height, "Height (PNG only) (default to expand to fit)", null },
26 { "url", 0, 0, OptionArg.STRING, ref opt_url, "Url to grab", null },
27 { "delay", 0, 0, OptionArg.INT, ref opt_delay, "Delay before snapshot in seconds", null },
28 { "png", 0, 0, OptionArg.STRING, ref opt_target_png, "File to write (PNG)", null },
29 { "inject", 0, 0, OptionArg.STRING_ARRAY, ref opt_inject_js, "Inject Javascript file(s)", null },
30 { "pdf", 0, 0, OptionArg.STRING, ref opt_target_pdf, "File to write (PDF)", null },
33 public static int main(string[] args)
39 unowned string proxy = Environment.get_variable ("http_proxy");
40 if (proxy != null && proxy.length > 0) {
41 var sess = WebKit.get_default_session();
42 sess.proxy_uri = new Soup.URI(proxy);
45 // this is a horrific hack from https://bugs.webkit.org/show_bug.cgi?id=128674
46 Environment.unset_variable("GNOME_DESKTOP_SESSION_ID");
47 Environment.unset_variable("DESKTOP_SESSION");
48 // it should now fallb ack to http prox!?
50 var opt_context = new OptionContext ("webkitpdf");
54 opt_context.set_help_enabled (true);
55 opt_context.add_main_entries (options, null);
56 opt_context.parse (ref args);
58 if (webkitpdf.opt_url == null) {
59 throw new OptionError.BAD_VALUE("missing url");
61 if (webkitpdf.opt_target_png == null && webkitpdf.opt_target_pdf == null) {
62 throw new OptionError.BAD_VALUE("missing pdf or png filename");
66 stdout.printf ( """Width: %d
78 opt_target_png == null ? "--empty--" : opt_target_png,
79 opt_inject_js.length < 1? "--empty--" : string.joinv(", ", opt_inject_js),
80 opt_target_pdf == null ? "--empty--" : opt_target_pdf
85 } catch (OptionError e) {
86 stdout.printf ("error: %s\n", e.message);
87 stdout.printf ("Run '%s --help' to see a full list of available command line options.\n %s",
88 args[0], opt_context.get_help(true,null));
92 var browser = new BrowserWindow();
93 browser.el.show_all();
95 var ses = WebKit.get_default_session();
96 ses.request_queued.connect((msg) => {
97 print("queued request %s\n", msg.uri.to_string(false));
98 msg.got_headers.connect(() => {
99 print("got conent type %s\n", msg.response_headers.get_content_type (null));
100 if (msg.response_headers.get_content_type (null) == "image/jpeg") {
101 ses.cancel_message(msg,Soup.KnownStatusCode.CANCELLED);