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 -D GTK3 --vapidir=. --thread webkitpdf.vala BrowserWindow.vala --vapidir=./vapi \
7 --pkg glib-2.0 --pkg webkit2gtk-4.0 --pkg gtk+-3.0 --pkg gio-2.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 public static string? opt_cookies = null;
24 const OptionEntry[] options = {
26 { "width", 0, 0, OptionArg.INT, ref opt_width, "Width (default 1200)", null },
27 { "height", 0, 0, OptionArg.INT, ref opt_height, "Height (PNG only) (default to expand to fit)", null },
28 { "url", 0, 0, OptionArg.STRING, ref opt_url, "Url to grab", null },
29 { "delay", 0, 0, OptionArg.INT, ref opt_delay, "Delay before snapshot in seconds", null },
30 { "png", 0, 0, OptionArg.STRING, ref opt_target_png, "File to write (PNG)", null },
31 { "inject", 0, 0, OptionArg.STRING_ARRAY, ref opt_inject_js, "Inject Javascript file(s)", null },
32 { "pdf", 0, 0, OptionArg.STRING, ref opt_target_pdf, "File to write (PDF)", null },
33 { "cookies", 0, 0, OptionArg.STRING, ref opt_cookies, "Inject Cookie string", null },
36 public static int main(string[] args)
42 // this is a horrific hack from https://bugs.webkit.org/show_bug.cgi?id=128674
43 Environment.unset_variable("GNOME_DESKTOP_SESSION_ID");
44 Environment.unset_variable("DESKTOP_SESSION");
45 // it should now fallb ack to http prox!?
49 unowned string proxy = Environment.get_variable ("http_proxy");
50 if (proxy != null && proxy.length > 0) {
51 var sess = WebKit.get_default_session();
52 sess.proxy_uri = new Soup.URI(proxy);
55 var opt_context = new OptionContext ("webkitpdf");
59 opt_context.set_help_enabled (true);
60 opt_context.add_main_entries (options, null);
61 opt_context.parse (ref args);
63 if (webkitpdf.opt_url == null) {
64 throw new OptionError.BAD_VALUE("missing url");
66 if (webkitpdf.opt_target_png == null && webkitpdf.opt_target_pdf == null) {
67 throw new OptionError.BAD_VALUE("missing pdf or png filename");
71 stdout.printf ( """Width: %d
84 opt_target_png == null ? "--empty--" : opt_target_png,
85 opt_inject_js.length < 1? "--empty--" : string.joinv(", ", opt_inject_js),
86 opt_target_pdf == null ? "--empty--" : opt_target_pdf,
87 opt_cookies == null ? "--empty--" : opt_cookies
93 } catch (OptionError e) {
94 stdout.printf ("error: %s\n", e.message);
95 stdout.printf ("Run '%s --help' to see a full list of available command line options.\n %s",
96 args[0], opt_context.get_help(true,null));
100 var browser = new BrowserWindow();
101 browser.el.show_all();
103 var ses = WebKit.get_default_session();
104 ses.request_queued.connect((msg) => {
105 print("queued request %s\n", msg.uri.to_string(false));
106 msg.got_headers.connect(() => {
107 print("got conent type %s\n", msg.response_headers.get_content_type (null));
108 if (msg.response_headers.get_content_type (null) == "image/jpeg") {
109 ses.cancel_message(msg,Soup.KnownStatusCode.CANCELLED);