Skip to content

Gtk.PageSetup

class — extends GObject.Object

Stores page size, orientation and margins for printing.

The idea is that you can get one of these from the page setup dialog and then pass it to the GtkPrintOperation when printing. The benefit of splitting this out of the GtkPrintSettings is that these affect the actual layout of the page, and thus need to be set long before user prints.

Margins

The margins specified in this object are the “print margins”, i.e. the parts of the page that the printer cannot print on. These are different from the layout margins that a word processor uses; they are typically used to determine the minimal size for the layout margins.

To obtain a GtkPageSetup use PageSetup.new to get the defaults, or use print_run_page_setup_dialog to show the page setup dialog and receive the resulting page setup.

A page setup dialog

static GtkPrintSettings *settings = NULL;
static GtkPageSetup *page_setup = NULL;

static void
do_page_setup (void)
{
  GtkPageSetup *new_page_setup;

  if (settings == NULL)
    settings = gtk_print_settings_new ();

  new_page_setup = gtk_print_run_page_setup_dialog (GTK_WINDOW (main_window),
                                                    page_setup, settings);

  if (page_setup)
    g_object_unref (page_setup);

  page_setup = new_page_setup;
}

Constructors

new

@classmethod
def new(cls) -> PageSetup

Creates a new GtkPageSetup.

new_from_file

@classmethod
def new_from_file(cls, file_name: str | bytes | os.PathLike[str] | os.PathLike[bytes]) -> PageSetup

Reads the page setup from the file file_name.

Returns a new GtkPageSetup object with the restored page setup, or None if an error occurred. See PageSetup.to_file.

Parameters:

  • file_name — the filename to read the page setup from

new_from_gvariant

@classmethod
def new_from_gvariant(cls, variant: GLib.Variant) -> PageSetup

Desrialize a page setup from an a{sv} variant.

The variant must be in the format produced by PageSetup.to_gvariant.

Parameters:

  • variant — an a{sv} GVariant

new_from_key_file

@classmethod
def new_from_key_file(cls, key_file: GLib.KeyFile, group_name: str | None = ...) -> PageSetup

Reads the page setup from the group group_name in the key file key_file.

Returns a new GtkPageSetup object with the restored page setup, or None if an error occurred.

Parameters:

  • key_file — the GKeyFile to retrieve the page_setup from
  • group_name — the name of the group in the key_file to read to use the default name “Page Setup”

Methods

copy

def copy(self) -> PageSetup

Copies a GtkPageSetup.

get_bottom_margin

def get_bottom_margin(self, unit: Unit | int) -> float

Gets the bottom margin in units of unit.

Parameters:

  • unit — the unit for the return value

get_left_margin

def get_left_margin(self, unit: Unit | int) -> float

Gets the left margin in units of unit.

Parameters:

  • unit — the unit for the return value

get_orientation

def get_orientation(self) -> PageOrientation

Gets the page orientation of the GtkPageSetup.

get_page_height

def get_page_height(self, unit: Unit | int) -> float

Returns the page height in units of unit.

Note that this function takes orientation and margins into consideration. See PageSetup.get_paper_height.

Parameters:

  • unit — the unit for the return value

get_page_width

def get_page_width(self, unit: Unit | int) -> float

Returns the page width in units of unit.

Note that this function takes orientation and margins into consideration. See PageSetup.get_paper_width.

Parameters:

  • unit — the unit for the return value

get_paper_height

def get_paper_height(self, unit: Unit | int) -> float

Returns the paper height in units of unit.

Note that this function takes orientation, but not margins into consideration. See PageSetup.get_page_height.

Parameters:

  • unit — the unit for the return value

get_paper_size

def get_paper_size(self) -> PaperSize

Gets the paper size of the GtkPageSetup.

get_paper_width

def get_paper_width(self, unit: Unit | int) -> float

Returns the paper width in units of unit.

Note that this function takes orientation, but not margins into consideration. See PageSetup.get_page_width.

Parameters:

  • unit — the unit for the return value

get_right_margin

def get_right_margin(self, unit: Unit | int) -> float

Gets the right margin in units of unit.

Parameters:

  • unit — the unit for the return value

get_top_margin

def get_top_margin(self, unit: Unit | int) -> float

Gets the top margin in units of unit.

Parameters:

  • unit — the unit for the return value

load_file

def load_file(self, file_name: str | bytes | os.PathLike[str] | os.PathLike[bytes]) -> bool

Reads the page setup from the file file_name.

See PageSetup.to_file.

Parameters:

  • file_name — the filename to read the page setup from

load_key_file

def load_key_file(self, key_file: GLib.KeyFile, group_name: str | None = ...) -> bool

Reads the page setup from the group group_name in the key file key_file.

Parameters:

  • key_file — the GKeyFile to retrieve the page_setup from
  • group_name — the name of the group in the key_file to read to use the default name “Page Setup”

set_bottom_margin

def set_bottom_margin(self, margin: float, unit: Unit | int) -> None

Sets the bottom margin of the GtkPageSetup.

Parameters:

  • margin — the new bottom margin in units of unit
  • unit — the units for margin

set_left_margin

def set_left_margin(self, margin: float, unit: Unit | int) -> None

Sets the left margin of the GtkPageSetup.

Parameters:

  • margin — the new left margin in units of unit
  • unit — the units for margin

set_orientation

def set_orientation(self, orientation: PageOrientation | int) -> None

Sets the page orientation of the GtkPageSetup.

Parameters:

  • orientation — a GtkPageOrientation value

set_paper_size

def set_paper_size(self, size: PaperSize) -> None

Sets the paper size of the GtkPageSetup without changing the margins.

See PageSetup.set_paper_size_and_default_margins.

Parameters:

  • size — a GtkPaperSize

set_paper_size_and_default_margins

def set_paper_size_and_default_margins(self, size: PaperSize) -> None

Sets the paper size of the GtkPageSetup and modifies the margins according to the new paper size.

Parameters:

  • size — a GtkPaperSize

set_right_margin

def set_right_margin(self, margin: float, unit: Unit | int) -> None

Sets the right margin of the GtkPageSetup.

Parameters:

  • margin — the new right margin in units of unit
  • unit — the units for margin

set_top_margin

def set_top_margin(self, margin: float, unit: Unit | int) -> None

Sets the top margin of the GtkPageSetup.

Parameters:

  • margin — the new top margin in units of unit
  • unit — the units for margin

to_file

def to_file(self, file_name: str | bytes | os.PathLike[str] | os.PathLike[bytes]) -> bool

This function saves the information from setup to file_name.

Parameters:

  • file_name — the file to save to

to_gvariant

def to_gvariant(self) -> GLib.Variant

Serialize page setup to an a{sv} variant.

to_key_file

def to_key_file(self, key_file: GLib.KeyFile, group_name: str | None = ...) -> None

This function adds the page setup from setup to key_file.

Parameters:

  • key_file — the GKeyFile to save the page setup to
  • group_name — the group to add the settings to in key_file, or None to use the default name “Page Setup”