Class PrintSettings

All Implemented Interfaces:
PointerInterface

public class PrintSettings extends Object
A `GtkPrintSettings` object represents the settings of a print dialog in
a system-independent way.

The main use for this object is that once you’ve printed you can get a
settings object that represents the settings the user chose, and the next
time you print you can pass that object in so that the user doesn’t have
to re-set all his settings.

Its also possible to enumerate the settings so that you can easily save
the settings for the next time your app runs, or even store them in a
document. The predefined keys try to use shared values as much as possible
so that moving such a document between systems still works.

https://docs.gtk.org/gtk4/class.PrintSettings.html

  • Constructor Details

    • PrintSettings

      public PrintSettings(PointerContainer pointer)
    • PrintSettings

      public PrintSettings()
      Creates a new `GtkPrintSettings` object.
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • newFromFilePrintSettings

      public static PrintSettings newFromFilePrintSettings(@Nonnull Str file_name) throws AllocationError
      Reads the print settings from @file_name.

      Returns a new `GtkPrintSettings` object with the restored settings,
      or %NULL if an error occurred. If the file could not be loaded then
      error is set to either a `GFileError` or `GKeyFileError`.

      See [method@Gtk.PrintSettings.to_file].
      Parameters:
      file_name - the filename to read the settings from
      Returns:
      the restored `GtkPrintSettings`
      Throws:
      AllocationError
    • newFromFilePrintSettings

      public static PrintSettings newFromFilePrintSettings(String file_name) throws AllocationError
      Reads the print settings from @file_name.

      Returns a new `GtkPrintSettings` object with the restored settings,
      or %NULL if an error occurred. If the file could not be loaded then
      error is set to either a `GFileError` or `GKeyFileError`.

      See [method@Gtk.PrintSettings.to_file].
      Parameters:
      file_name - the filename to read the settings from
      Returns:
      the restored `GtkPrintSettings`
      Throws:
      AllocationError
    • newFromGvariantPrintSettings

      public static PrintSettings newFromGvariantPrintSettings(@Nonnull Variant variant)
      Deserialize print settings from an a{sv} variant.

      The variant must be in the format produced by
      [method@Gtk.PrintSettings.to_gvariant].
      Parameters:
      variant - an a{sv} `GVariant`
      Returns:
      a new `GtkPrintSettings` object
    • newFromKeyFilePrintSettings

      public static PrintSettings newFromKeyFilePrintSettings(@Nonnull KeyFile key_file, @Nullable Str group_name) throws AllocationError
      Reads the print settings from the group @group_name in @key_file.

      Returns a new `GtkPrintSettings` object with the restored settings,
      or %NULL if an error occurred. If the file could not be loaded then
      error is set to either `GFileError` or `GKeyFileError`.
      Parameters:
      key_file - the `GKeyFile` to retrieve the settings from
      group_name - the name of the group to use, or %NULL to use the default “Print Settings”
      Returns:
      the restored `GtkPrintSettings`
      Throws:
      AllocationError
    • newFromKeyFilePrintSettings

      public static PrintSettings newFromKeyFilePrintSettings(@Nonnull KeyFile key_file, String group_name) throws AllocationError
      Reads the print settings from the group @group_name in @key_file.

      Returns a new `GtkPrintSettings` object with the restored settings,
      or %NULL if an error occurred. If the file could not be loaded then
      error is set to either `GFileError` or `GKeyFileError`.
      Parameters:
      key_file - the `GKeyFile` to retrieve the settings from
      group_name - the name of the group to use, or %NULL to use the default “Print Settings”
      Returns:
      the restored `GtkPrintSettings`
      Throws:
      AllocationError
    • copy

      public PrintSettings copy()
      Copies a `GtkPrintSettings` object.
      Returns:
      a newly allocated copy of @other
    • foreach

      public void foreach(PrintSettings.OnPrintSettingsFunc func, @Nullable Pointer user_data)
      Calls @func for each key-value pair of @settings.
      Parameters:
      func - the function to call
      user_data - user data for @func
    • get

      public Str get(@Nonnull Str key)
      Looks up the string value associated with @key.
      Parameters:
      key - a key
      Returns:
      the string value for @key
    • get

      public Str get(String key)
      Looks up the string value associated with @key.
      Parameters:
      key - a key
      Returns:
      the string value for @key
    • getBool

      public boolean getBool(@Nonnull Str key)
      Returns the boolean represented by the value
      that is associated with @key.

      The string “true” represents %TRUE, any other
      string %FALSE.
      Parameters:
      key - a key
      Returns:
      %TRUE, if @key maps to a true value.
    • getBool

      public boolean getBool(String key)
      Returns the boolean represented by the value
      that is associated with @key.

      The string “true” represents %TRUE, any other
      string %FALSE.
      Parameters:
      key - a key
      Returns:
      %TRUE, if @key maps to a true value.
    • getCollate

      public boolean getCollate()
      Gets the value of %GTK_PRINT_SETTINGS_COLLATE.
      Returns:
      whether to collate the printed pages
    • getDefaultSource

      public Str getDefaultSource()
      Gets the value of %GTK_PRINT_SETTINGS_DEFAULT_SOURCE.
      Returns:
      the default source
    • getDither

      public Str getDither()
      Gets the value of %GTK_PRINT_SETTINGS_DITHER.
      Returns:
      the dithering that is used
    • getDouble

      public double getDouble(@Nonnull Str key)
      Returns the double value associated with @key, or 0.
      Parameters:
      key - a key
      Returns:
      the double value of @key
    • getDouble

      public double getDouble(String key)
      Returns the double value associated with @key, or 0.
      Parameters:
      key - a key
      Returns:
      the double value of @key
    • getDoubleWithDefault

      public double getDoubleWithDefault(@Nonnull Str key, double def)
      Returns the floating point number represented by
      the value that is associated with @key, or @default_val
      if the value does not represent a floating point number.

      Floating point numbers are parsed with g_ascii_strtod().
      Parameters:
      key - a key
      def - the default value
      Returns:
      the floating point number associated with @key
    • getDoubleWithDefault

      public double getDoubleWithDefault(String key, double def)
      Returns the floating point number represented by
      the value that is associated with @key, or @default_val
      if the value does not represent a floating point number.

      Floating point numbers are parsed with g_ascii_strtod().
      Parameters:
      key - a key
      def - the default value
      Returns:
      the floating point number associated with @key
    • getDuplex

      public int getDuplex()
      Gets the value of %GTK_PRINT_SETTINGS_DUPLEX.
      Returns:
      whether to print the output in duplex.
    • getFinishings

      public Str getFinishings()
      Gets the value of %GTK_PRINT_SETTINGS_FINISHINGS.
      Returns:
      the finishings
    • getInt

      public int getInt(@Nonnull Str key)
      Returns the integer value of @key, or 0.
      Parameters:
      key - a key
      Returns:
      the integer value of @key
    • getInt

      public int getInt(String key)
      Returns the integer value of @key, or 0.
      Parameters:
      key - a key
      Returns:
      the integer value of @key
    • getIntWithDefault

      public int getIntWithDefault(@Nonnull Str key, int def)
      Returns the value of @key, interpreted as
      an integer, or the default value.
      Parameters:
      key - a key
      def - the default value
      Returns:
      the integer value of @key
    • getIntWithDefault

      public int getIntWithDefault(String key, int def)
      Returns the value of @key, interpreted as
      an integer, or the default value.
      Parameters:
      key - a key
      def - the default value
      Returns:
      the integer value of @key
    • getLength

      public double getLength(@Nonnull Str key, int unit)
      Returns the value associated with @key, interpreted
      as a length.

      The returned value is converted to @units.
      Parameters:
      key - a key
      unit - the unit of the return value
      Returns:
      the length value of @key, converted to @unit
    • getLength

      public double getLength(String key, int unit)
      Returns the value associated with @key, interpreted
      as a length.

      The returned value is converted to @units.
      Parameters:
      key - a key
      unit - the unit of the return value
      Returns:
      the length value of @key, converted to @unit
    • getMediaType

      public Str getMediaType()
      Gets the value of %GTK_PRINT_SETTINGS_MEDIA_TYPE.

      The set of media types is defined in PWG 5101.1-2002 PWG.
      Returns:
      the media type
    • getNCopies

      public int getNCopies()
      Gets the value of %GTK_PRINT_SETTINGS_N_COPIES.
      Returns:
      the number of copies to print
    • getNumberUp

      public int getNumberUp()
      Gets the value of %GTK_PRINT_SETTINGS_NUMBER_UP.
      Returns:
      the number of pages per sheet
    • getNumberUpLayout

      public int getNumberUpLayout()
      Gets the value of %GTK_PRINT_SETTINGS_NUMBER_UP_LAYOUT.
      Returns:
      layout of page in number-up mode
    • getOrientation

      public int getOrientation()
      Get the value of %GTK_PRINT_SETTINGS_ORIENTATION,
      converted to a `GtkPageOrientation`.
      Returns:
      the orientation
    • getOutputBin

      public Str getOutputBin()
      Gets the value of %GTK_PRINT_SETTINGS_OUTPUT_BIN.
      Returns:
      the output bin
    • getPageSet

      public int getPageSet()
      Gets the value of %GTK_PRINT_SETTINGS_PAGE_SET.
      Returns:
      the set of pages to print
    • getPaperHeight

      public double getPaperHeight(int unit)
      Gets the value of %GTK_PRINT_SETTINGS_PAPER_HEIGHT,
      converted to @unit.
      Parameters:
      unit - the unit for the return value
      Returns:
      the paper height, in units of @unit
    • getPaperSize

      public PaperSize getPaperSize()
      Gets the value of %GTK_PRINT_SETTINGS_PAPER_FORMAT,
      converted to a `GtkPaperSize`.
      Returns:
      the paper size
    • getPaperWidth

      public double getPaperWidth(int unit)
      Gets the value of %GTK_PRINT_SETTINGS_PAPER_WIDTH,
      converted to @unit.
      Parameters:
      unit - the unit for the return value
      Returns:
      the paper width, in units of @unit
    • getPrintPages

      public int getPrintPages()
      Gets the value of %GTK_PRINT_SETTINGS_PRINT_PAGES.
      Returns:
      which pages to print
    • getPrinter

      public Str getPrinter()
      Convenience function to obtain the value of
      %GTK_PRINT_SETTINGS_PRINTER.
      Returns:
      the printer name
    • getPrinterLpi

      public double getPrinterLpi()
      Gets the value of %GTK_PRINT_SETTINGS_PRINTER_LPI.
      Returns:
      the resolution in lpi (lines per inch)
    • getQuality

      public int getQuality()
      Gets the value of %GTK_PRINT_SETTINGS_QUALITY.
      Returns:
      the print quality
    • getResolution

      public int getResolution()
      Gets the value of %GTK_PRINT_SETTINGS_RESOLUTION.
      Returns:
      the resolution in dpi
    • getResolutionX

      public int getResolutionX()
      Gets the value of %GTK_PRINT_SETTINGS_RESOLUTION_X.
      Returns:
      the horizontal resolution in dpi
    • getResolutionY

      public int getResolutionY()
      Gets the value of %GTK_PRINT_SETTINGS_RESOLUTION_Y.
      Returns:
      the vertical resolution in dpi
    • getReverse

      public boolean getReverse()
      Gets the value of %GTK_PRINT_SETTINGS_REVERSE.
      Returns:
      whether to reverse the order of the printed pages
    • getScale

      public double getScale()
      Gets the value of %GTK_PRINT_SETTINGS_SCALE.
      Returns:
      the scale in percent
    • getUseColor

      public boolean getUseColor()
      Gets the value of %GTK_PRINT_SETTINGS_USE_COLOR.
      Returns:
      whether to use color
    • hasKey

      public boolean hasKey(@Nonnull Str key)
      Returns %TRUE, if a value is associated with @key.
      Parameters:
      key - a key
      Returns:
      %TRUE, if @key has a value
    • hasKey

      public boolean hasKey(String key)
      Returns %TRUE, if a value is associated with @key.
      Parameters:
      key - a key
      Returns:
      %TRUE, if @key has a value
    • loadFile

      public boolean loadFile(@Nonnull Str file_name) throws AllocationError
      Reads the print settings from @file_name.

      If the file could not be loaded then error is set to either
      a `GFileError` or `GKeyFileError`.

      See [method@Gtk.PrintSettings.to_file].
      Parameters:
      file_name - the filename to read the settings from
      Returns:
      %TRUE on success
      Throws:
      AllocationError
    • loadFile

      public boolean loadFile(String file_name) throws AllocationError
      Reads the print settings from @file_name.

      If the file could not be loaded then error is set to either
      a `GFileError` or `GKeyFileError`.

      See [method@Gtk.PrintSettings.to_file].
      Parameters:
      file_name - the filename to read the settings from
      Returns:
      %TRUE on success
      Throws:
      AllocationError
    • loadKeyFile

      public boolean loadKeyFile(@Nonnull KeyFile key_file, @Nullable Str group_name) throws AllocationError
      Reads the print settings from the group @group_name in @key_file.

      If the file could not be loaded then error is set to either a
      `GFileError` or `GKeyFileError`.
      Parameters:
      key_file - the `GKeyFile` to retrieve the settings from
      group_name - the name of the group to use, or %NULL to use the default “Print Settings”
      Returns:
      %TRUE on success
      Throws:
      AllocationError
    • loadKeyFile

      public boolean loadKeyFile(@Nonnull KeyFile key_file, String group_name) throws AllocationError
      Reads the print settings from the group @group_name in @key_file.

      If the file could not be loaded then error is set to either a
      `GFileError` or `GKeyFileError`.
      Parameters:
      key_file - the `GKeyFile` to retrieve the settings from
      group_name - the name of the group to use, or %NULL to use the default “Print Settings”
      Returns:
      %TRUE on success
      Throws:
      AllocationError
    • set

      public void set(@Nonnull Str key, @Nullable Str value)
      Associates @value with @key.
      Parameters:
      key - a key
      value - a string value
    • set

      public void set(String key, String value)
      Associates @value with @key.
      Parameters:
      key - a key
      value - a string value
    • setBool

      public void setBool(@Nonnull Str key, boolean value)
      Sets @key to a boolean value.
      Parameters:
      key - a key
      value - a boolean
    • setBool

      public void setBool(String key, boolean value)
      Sets @key to a boolean value.
      Parameters:
      key - a key
      value - a boolean
    • setCollate

      public void setCollate(boolean collate)
      Sets the value of %GTK_PRINT_SETTINGS_COLLATE.
      Parameters:
      collate - whether to collate the output
    • setDefaultSource

      public void setDefaultSource(@Nonnull Str default_source)
      Sets the value of %GTK_PRINT_SETTINGS_DEFAULT_SOURCE.
      Parameters:
      default_source - the default source
    • setDefaultSource

      public void setDefaultSource(String default_source)
      Sets the value of %GTK_PRINT_SETTINGS_DEFAULT_SOURCE.
      Parameters:
      default_source - the default source
    • setDither

      public void setDither(@Nonnull Str dither)
      Sets the value of %GTK_PRINT_SETTINGS_DITHER.
      Parameters:
      dither - the dithering that is used
    • setDither

      public void setDither(String dither)
      Sets the value of %GTK_PRINT_SETTINGS_DITHER.
      Parameters:
      dither - the dithering that is used
    • setDouble

      public void setDouble(@Nonnull Str key, double value)
      Sets @key to a double value.
      Parameters:
      key - a key
      value - a double value
    • setDouble

      public void setDouble(String key, double value)
      Sets @key to a double value.
      Parameters:
      key - a key
      value - a double value
    • setDuplex

      public void setDuplex(int duplex)
      Sets the value of %GTK_PRINT_SETTINGS_DUPLEX.
      Parameters:
      duplex - a `GtkPrintDuplex` value
    • setFinishings

      public void setFinishings(@Nonnull Str finishings)
      Sets the value of %GTK_PRINT_SETTINGS_FINISHINGS.
      Parameters:
      finishings - the finishings
    • setFinishings

      public void setFinishings(String finishings)
      Sets the value of %GTK_PRINT_SETTINGS_FINISHINGS.
      Parameters:
      finishings - the finishings
    • setInt

      public void setInt(@Nonnull Str key, int value)
      Sets @key to an integer value.
      Parameters:
      key - a key
      value - an integer
    • setInt

      public void setInt(String key, int value)
      Sets @key to an integer value.
      Parameters:
      key - a key
      value - an integer
    • setLength

      public void setLength(@Nonnull Str key, double value, int unit)
      Associates a length in units of @unit with @key.
      Parameters:
      key - a key
      value - a length
      unit - the unit of @length
    • setLength

      public void setLength(String key, double value, int unit)
      Associates a length in units of @unit with @key.
      Parameters:
      key - a key
      value - a length
      unit - the unit of @length
    • setMediaType

      public void setMediaType(@Nonnull Str media_type)
      Sets the value of %GTK_PRINT_SETTINGS_MEDIA_TYPE.

      The set of media types is defined in PWG 5101.1-2002 PWG.
      Parameters:
      media_type - the media type
    • setMediaType

      public void setMediaType(String media_type)
      Sets the value of %GTK_PRINT_SETTINGS_MEDIA_TYPE.

      The set of media types is defined in PWG 5101.1-2002 PWG.
      Parameters:
      media_type - the media type
    • setNCopies

      public void setNCopies(int num_copies)
      Sets the value of %GTK_PRINT_SETTINGS_N_COPIES.
      Parameters:
      num_copies - the number of copies
    • setNumberUp

      public void setNumberUp(int number_up)
      Sets the value of %GTK_PRINT_SETTINGS_NUMBER_UP.
      Parameters:
      number_up - the number of pages per sheet
    • setNumberUpLayout

      public void setNumberUpLayout(int number_up_layout)
      Sets the value of %GTK_PRINT_SETTINGS_NUMBER_UP_LAYOUT.
      Parameters:
      number_up_layout - a `GtkNumberUpLayout` value
    • setOrientation

      public void setOrientation(int orientation)
      Sets the value of %GTK_PRINT_SETTINGS_ORIENTATION.
      Parameters:
      orientation - a page orientation
    • setOutputBin

      public void setOutputBin(@Nonnull Str output_bin)
      Sets the value of %GTK_PRINT_SETTINGS_OUTPUT_BIN.
      Parameters:
      output_bin - the output bin
    • setOutputBin

      public void setOutputBin(String output_bin)
      Sets the value of %GTK_PRINT_SETTINGS_OUTPUT_BIN.
      Parameters:
      output_bin - the output bin
    • setPageSet

      public void setPageSet(int page_set)
      Sets the value of %GTK_PRINT_SETTINGS_PAGE_SET.
      Parameters:
      page_set - a `GtkPageSet` value
    • setPaperHeight

      public void setPaperHeight(double height, int unit)
      Sets the value of %GTK_PRINT_SETTINGS_PAPER_HEIGHT.
      Parameters:
      height - the paper height
      unit - the units of @height
    • setPaperSize

      public void setPaperSize(@Nonnull PaperSize paper_size)
      Sets the value of %GTK_PRINT_SETTINGS_PAPER_FORMAT,
      %GTK_PRINT_SETTINGS_PAPER_WIDTH and
      %GTK_PRINT_SETTINGS_PAPER_HEIGHT.
      Parameters:
      paper_size - a paper size
    • setPaperWidth

      public void setPaperWidth(double width, int unit)
      Sets the value of %GTK_PRINT_SETTINGS_PAPER_WIDTH.
      Parameters:
      width - the paper width
      unit - the units of @width
    • setPrintPages

      public void setPrintPages(int pages)
      Sets the value of %GTK_PRINT_SETTINGS_PRINT_PAGES.
      Parameters:
      pages - a `GtkPrintPages` value
    • setPrinter

      public void setPrinter(@Nonnull Str printer)
      Convenience function to set %GTK_PRINT_SETTINGS_PRINTER
      to @printer.
      Parameters:
      printer - the printer name
    • setPrinter

      public void setPrinter(String printer)
      Convenience function to set %GTK_PRINT_SETTINGS_PRINTER
      to @printer.
      Parameters:
      printer - the printer name
    • setPrinterLpi

      public void setPrinterLpi(double lpi)
      Sets the value of %GTK_PRINT_SETTINGS_PRINTER_LPI.
      Parameters:
      lpi - the resolution in lpi (lines per inch)
    • setQuality

      public void setQuality(int quality)
      Sets the value of %GTK_PRINT_SETTINGS_QUALITY.
      Parameters:
      quality - a `GtkPrintQuality` value
    • setResolution

      public void setResolution(int resolution)
      Sets the values of %GTK_PRINT_SETTINGS_RESOLUTION,
      %GTK_PRINT_SETTINGS_RESOLUTION_X and
      %GTK_PRINT_SETTINGS_RESOLUTION_Y.
      Parameters:
      resolution - the resolution in dpi
    • setResolutionXy

      public void setResolutionXy(int resolution_x, int resolution_y)
      Sets the values of %GTK_PRINT_SETTINGS_RESOLUTION,
      %GTK_PRINT_SETTINGS_RESOLUTION_X and
      %GTK_PRINT_SETTINGS_RESOLUTION_Y.
      Parameters:
      resolution_x - the horizontal resolution in dpi
      resolution_y - the vertical resolution in dpi
    • setReverse

      public void setReverse(boolean reverse)
      Sets the value of %GTK_PRINT_SETTINGS_REVERSE.
      Parameters:
      reverse - whether to reverse the output
    • setScale

      public void setScale(double scale)
      Sets the value of %GTK_PRINT_SETTINGS_SCALE.
      Parameters:
      scale - the scale in percent
    • setUseColor

      public void setUseColor(boolean use_color)
      Sets the value of %GTK_PRINT_SETTINGS_USE_COLOR.
      Parameters:
      use_color - whether to use color
    • toFile

      public boolean toFile(@Nonnull Str file_name) throws AllocationError
      This function saves the print settings from @settings to @file_name.

      If the file could not be written then error is set to either a
      `GFileError` or `GKeyFileError`.
      Parameters:
      file_name - the file to save to
      Returns:
      %TRUE on success
      Throws:
      AllocationError
    • toFile

      public boolean toFile(String file_name) throws AllocationError
      This function saves the print settings from @settings to @file_name.

      If the file could not be written then error is set to either a
      `GFileError` or `GKeyFileError`.
      Parameters:
      file_name - the file to save to
      Returns:
      %TRUE on success
      Throws:
      AllocationError
    • toGvariant

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

      public void toKeyFile(@Nonnull KeyFile key_file, @Nullable Str group_name)
      This function adds the print settings from @settings to @key_file.
      Parameters:
      key_file - the `GKeyFile` to save the print settings to
      group_name - the group to add the settings to in @key_file, or %NULL to use the default “Print Settings”
    • toKeyFile

      public void toKeyFile(@Nonnull KeyFile key_file, String group_name)
      This function adds the print settings from @settings to @key_file.
      Parameters:
      key_file - the `GKeyFile` to save the print settings to
      group_name - the group to add the settings to in @key_file, or %NULL to use the default “Print Settings”
    • unset

      public void unset(@Nonnull Str key)
      Removes any value associated with @key.

      This has the same effect as setting the value to %NULL.
      Parameters:
      key - a key
    • unset

      public void unset(String key)
      Removes any value associated with @key.

      This has the same effect as setting the value to %NULL.
      Parameters:
      key - a key
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()