Note that there are some explanatory texts on larger screens.

plurals
  1. POPrint complete WebKitWebView (not only visible part) into PDF with gtk3 and cairo
    primarykey
    data
    text
    <p>I want to save a webpage using webkit, gtk3 and cairo into a pdf. <hr/> What works: The visible part (visible in window) gets correctly printed into the pdf<hr/> What doesn't work, but should work: The invisible part (the part when you scroll down) should be printed into that pdf, too. Any ideas? <hr/> That's my code:</p> <pre><code>#include &lt;gtk/gtk.h&gt; #include &lt;webkit/webkit.h&gt; #include &lt;cairo-pdf.h&gt; static void save_as_pdf (GtkWidget *widget, const char *filename) { GtkAllocation allocation; printf("Saving PDF to file %s\n", filename); gtk_widget_get_allocation(GTK_WIDGET(widget), &amp;allocation); printf("height: %d width: %d\n", allocation.height, allocation.width); cairo_surface_t *surface = cairo_pdf_surface_create( filename, allocation.width, allocation.height); cairo_t *cr = cairo_create(surface); gtk_widget_draw(widget, cr); cairo_destroy(cr); cairo_surface_destroy(surface); } static void notifyProgressCb(WebKitWebView* webView, GParamSpec* pspec, GtkWidget* window) { float progress = webkit_web_view_get_progress(webView); printf("\x1b[1G\t\x1b[1G%f", progress * 100); fflush(stdout); if (progress == 1.0) save_as_pdf(window, "test.pdf"); } int main (int argc, char *argv[]) { GtkWidget *window; WebKitWebView *webView; gtk_init (&amp;argc, &amp;argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size(GTK_WINDOW(window), 1024, 768); webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); gtk_container_set_resize_mode(GTK_CONTAINER(webView), GTK_RESIZE_PARENT); gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(webView)); g_signal_connect(webView, "notify::progress", G_CALLBACK(notifyProgressCb), webView); webkit_web_view_load_uri(webView, "http://www.heise.de"); g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); gtk_widget_show_all (window); gtk_main(); return 0; } </code></pre> <p>compile with: </p> <blockquote> <p>gcc <code>pkg-config --cflags --libs gtk+-3.0</code> <code>pkg-config --libs --cflags webkitgtk-3.0</code> yourfile.c</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload