### Method

# GtkSource PrintCompositor paginate

#### Declaration [src]

    gboolean
    gtk_source_print_compositor_paginate (
      GtkSourcePrintCompositor* compositor,
      GtkPrintContext* context
    )

#### Description [src]

Paginate the document associated with the `compositor`.

In order to support non-blocking pagination, document is paginated in small chunks. Each time `gtk_source_print_compositor_paginate()` is invoked, a chunk of the document is paginated. To paginate the entire document, `gtk_source_print_compositor_paginate()` must be invoked multiple times. It returns `TRUE` if the document has been completely paginated, otherwise it returns `FALSE`.

This method has been designed to be invoked in the handler of the `GtkPrintOperation::paginate` signal, as shown in the following example:

    // Signal handler for the GtkPrintOperation::paginate signal

    static gboolean
    paginate (GtkPrintOperation *operation,
              GtkPrintContext   *context,
              gpointer           user_data)
    {
        GtkSourcePrintCompositor *compositor;

        compositor = GTK_SOURCE_PRINT_COMPOSITOR (user_data);

        if (gtk_source_print_compositor_paginate (compositor, context))
        {
            gint n_pages;

            n_pages = gtk_source_print_compositor_get_n_pages (compositor);
            gtk_print_operation_set_n_pages (operation, n_pages);

            return TRUE;
        }

        return FALSE;
    }

    def on_paginate(
        operation: Gtk.PrintOperation,
        context: Gtk.PrintContext,
        compositor: GtkSource.PrintCompositor,
    ) -> bool:
        if compositor.paginate(context=context):
            n_pages = compositor.get_n_pages()
            operation.set_n_pages(n_pages=n_pages)
            return True
        return False

If you don’t need to do pagination in chunks, you can simply do it all in the `GtkPrintOperation::begin-print` handler, and set the number of pages from there, like in the following example:

    // Signal handler for the GtkPrintOperation::begin-print signal

    static void
    begin_print (GtkPrintOperation *operation,
                 GtkPrintContext   *context,
                 gpointer           user_data)
    {
        GtkSourcePrintCompositor *compositor;
        gint n_pages;

        compositor = GTK_SOURCE_PRINT_COMPOSITOR (user_data);

        while (!gtk_source_print_compositor_paginate (compositor, context));

        n_pages = gtk_source_print_compositor_get_n_pages (compositor);
        gtk_print_operation_set_n_pages (operation, n_pages);
    }

    def on_begin_print(
        operation: Gtk.PrintOperation,
        context: Gtk.PrintContext,
        compositor: GtkSource.PrintCompositor,
    ) -> None:
        # Paginate until complete
        while not compositor.paginate(context=context):
            pass

        n_pages = compositor.get_n_pages()
        operation.set_n_pages(n_pages=n_pages)

#### Parameters

`context`

  Type: `GtkPrintContext`

  The `GtkPrintContext` whose parameters (e.g. paper size, print margins, etc.) are used by the the `compositor` to paginate the document.

  The data is owned by the caller of the method.

#### Return value

Type: `gboolean`

`TRUE` if the document has been completely paginated, `FALSE` otherwise.