Class PageSetup

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class PageSetup extends GObject

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() to get the defaults, or use Gtk.printRunPageSetupDialog(Window, PageSetup, PrintSettings) 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;
}
  • Constructor Details

    • PageSetup

      public PageSetup(MemorySegment address)
      Create a PageSetup instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • PageSetup

      public PageSetup()
      Create a new PageSetup.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the PageSetup class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected PageSetup asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GObject
      Returns:
      the instance as if it were its parent type
    • fromFile

      public static PageSetup fromFile(String fileName) throws GErrorException

      Reads the page setup from the file fileName.

      Returns a new GtkPageSetup object with the restored page setup, or null if an error occurred. See toFile(String).

      Parameters:
      fileName - the filename to read the page setup from
      Returns:
      the restored GtkPageSetup
      Throws:
      GErrorException - see GError
    • fromGvariant

      public static PageSetup fromGvariant(Variant variant)

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

      The variant must be in the format produced by toGvariant().

      Parameters:
      variant - an a{sv} GVariant
      Returns:
      a new GtkPageSetup object
    • fromKeyFile

      public static PageSetup fromKeyFile(KeyFile keyFile, @Nullable String groupName) throws GErrorException

      Reads the page setup from the group groupName in the key file keyFile.

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

      Parameters:
      keyFile - the GKeyFile to retrieve the page_setup from
      groupName - the name of the group in the key_file to read to use the default name “Page Setup”
      Returns:
      the restored GtkPageSetup
      Throws:
      GErrorException - see GError
    • copy

      public PageSetup copy()
      Copies a GtkPageSetup.
      Returns:
      a copy of this PageSetup
    • getBottomMargin

      public double getBottomMargin(Unit unit)
      Gets the bottom margin in units of unit.
      Parameters:
      unit - the unit for the return value
      Returns:
      the bottom margin
    • getLeftMargin

      public double getLeftMargin(Unit unit)
      Gets the left margin in units of unit.
      Parameters:
      unit - the unit for the return value
      Returns:
      the left margin
    • getOrientation

      public PageOrientation getOrientation()
      Gets the page orientation of the GtkPageSetup.
      Returns:
      the page orientation
    • getPageHeight

      public double getPageHeight(Unit unit)

      Returns the page height in units of unit.

      Note that this function takes orientation and margins into consideration. See getPaperHeight(Unit).

      Parameters:
      unit - the unit for the return value
      Returns:
      the page height.
    • getPageWidth

      public double getPageWidth(Unit unit)

      Returns the page width in units of unit.

      Note that this function takes orientation and margins into consideration. See getPaperWidth(Unit).

      Parameters:
      unit - the unit for the return value
      Returns:
      the page width.
    • getPaperHeight

      public double getPaperHeight(Unit unit)

      Returns the paper height in units of unit.

      Note that this function takes orientation, but not margins into consideration. See getPageHeight(Unit).

      Parameters:
      unit - the unit for the return value
      Returns:
      the paper height.
    • getPaperSize

      public PaperSize getPaperSize()
      Gets the paper size of the GtkPageSetup.
      Returns:
      the paper size
    • getPaperWidth

      public double getPaperWidth(Unit unit)

      Returns the paper width in units of unit.

      Note that this function takes orientation, but not margins into consideration. See getPageWidth(Unit).

      Parameters:
      unit - the unit for the return value
      Returns:
      the paper width.
    • getRightMargin

      public double getRightMargin(Unit unit)
      Gets the right margin in units of unit.
      Parameters:
      unit - the unit for the return value
      Returns:
      the right margin
    • getTopMargin

      public double getTopMargin(Unit unit)
      Gets the top margin in units of unit.
      Parameters:
      unit - the unit for the return value
      Returns:
      the top margin
    • loadFile

      public boolean loadFile(String fileName) throws GErrorException

      Reads the page setup from the file fileName.

      See toFile(String).

      Parameters:
      fileName - the filename to read the page setup from
      Returns:
      true on success
      Throws:
      GErrorException - see GError
    • loadKeyFile

      public boolean loadKeyFile(KeyFile keyFile, @Nullable String groupName) throws GErrorException
      Reads the page setup from the group groupName in the key file keyFile.
      Parameters:
      keyFile - the GKeyFile to retrieve the page_setup from
      groupName - the name of the group in the key_file to read to use the default name “Page Setup”
      Returns:
      true on success
      Throws:
      GErrorException - see GError
    • setBottomMargin

      public void setBottomMargin(double margin, Unit unit)
      Sets the bottom margin of the GtkPageSetup.
      Parameters:
      margin - the new bottom margin in units of unit
      unit - the units for margin
    • setLeftMargin

      public void setLeftMargin(double margin, Unit unit)
      Sets the left margin of the GtkPageSetup.
      Parameters:
      margin - the new left margin in units of unit
      unit - the units for margin
    • setOrientation

      public void setOrientation(PageOrientation orientation)
      Sets the page orientation of the GtkPageSetup.
      Parameters:
      orientation - a GtkPageOrientation value
    • setPaperSize

      public void setPaperSize(PaperSize size)

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

      See setPaperSizeAndDefaultMargins(PaperSize).

      Parameters:
      size - a GtkPaperSize
    • setPaperSizeAndDefaultMargins

      public void setPaperSizeAndDefaultMargins(PaperSize size)
      Sets the paper size of the GtkPageSetup and modifies the margins according to the new paper size.
      Parameters:
      size - a GtkPaperSize
    • setRightMargin

      public void setRightMargin(double margin, Unit unit)
      Sets the right margin of the GtkPageSetup.
      Parameters:
      margin - the new right margin in units of unit
      unit - the units for margin
    • setTopMargin

      public void setTopMargin(double margin, Unit unit)
      Sets the top margin of the GtkPageSetup.
      Parameters:
      margin - the new top margin in units of unit
      unit - the units for margin
    • toFile

      public boolean toFile(String fileName) throws GErrorException
      This function saves the information from this PageSetup to fileName.
      Parameters:
      fileName - the file to save to
      Returns:
      true on success
      Throws:
      GErrorException - see GError
    • toGvariant

      public Variant toGvariant()
      Serialize page setup to an a{sv} variant.
      Returns:
      a new, floating, GVariant
    • toKeyFile

      public void toKeyFile(KeyFile keyFile, @Nullable String groupName)
      This function adds the page setup from this PageSetup to keyFile.
      Parameters:
      keyFile - the GKeyFile to save the page setup to
      groupName - the group to add the settings to in keyFile, or null to use the default name “Page Setup”
    • builder

      public static PageSetup.Builder<? extends PageSetup.Builder> builder()
      A PageSetup.Builder object constructs a PageSetup with the specified properties. Use the various set...() methods to set properties, and finish construction with PageSetup.Builder.build().
      Returns:
      the builder object