Interface PrinterSettings


public interface PrinterSettings
The printer settings used when printing comparisons: the printer, number of copies, page range, duplex mode and printing to a file. Obtained with App.getSettings().getPrinter().

 const printer = App.getSettings().getPrinter();
 console.log('Installed printers: ' + printer.getInstalledPrinters().length);

 // Print to a PDF file (macOS only)
 printer.setPrintToFile(true);
 printer.setFilePath(App.getProperty('user.home') + '/comparison.pdf');
 await comp.print();
 
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Answers whether printed copies are collated.
    int
    Returns the number of copies to print.
    Returns the duplex mode - single-sided or double-sided printing - for printers that support it.
    int
    Returns the last page to print when printing a range of pages (PrintScope.PAGE_RANGE).
    Returns the full path of the file to print to.
    Returns the names of all printers installed on this computer.
    Returns the printer driver.
    Returns the name of the printer used for printing.
    boolean
    Answers whether printing goes to a file instead of a printer.
    Returns which pages are printed: all pages or a range of pages.
    int
    Returns the first page to print when printing a range of pages (PrintScope.PAGE_RANGE).
    void
    setCollate(boolean collate)
    Sets whether printed copies are collated.
    void
    setCopyCount(int copyCount)
    Sets the number of copies to print.
    void
    Sets the duplex mode, for printers that support it.
    void
    setEndPage(int endPage)
    Sets the last page to print when printing a range of pages (PrintScope.PAGE_RANGE).
    void
    Sets the full path of the PDF file to print to.
    void
    Sets the printer driver to use for printing: On macOS, the destination type ("Printer", "Fax", "File", or "Preview"). On Windows, the name of the driver (often "winspool"). On Linux (GTK), the backend type name, for example "GtkPrintBackendCups".
    void
    Sets the name of the printer to use for printing: the printer name on macOS and Linux, the device name on Windows.
    void
    setPrintToFile(boolean printToFile)
    Sets whether printing goes to a PDF file, set with setFilePath(String), instead of a printer.
    void
    Sets which pages are printed: all pages or a range of pages.
    void
    setStartPage(int startPage)
    Sets the first page to print when printing a range of pages (PrintScope.PAGE_RANGE).
  • Method Details

    • getCollate

      boolean getCollate()
      Answers whether printed copies are collated.
      Returns:
      true if copies are collated, false otherwise
      Since:
      2.0
      See Also:
    • getCopyCount

      int getCopyCount()
      Returns the number of copies to print.
      Returns:
      the number of copies
      Since:
      2.0
      See Also:
    • getDuplexMode

      DuplexMode getDuplexMode()
      Returns the duplex mode - single-sided or double-sided printing - for printers that support it.
      Returns:
      the duplex mode; never null
      Since:
      2.0
      See Also:
    • getEndPage

      int getEndPage()
      Returns the last page to print when printing a range of pages (PrintScope.PAGE_RANGE).
      Returns:
      the 1-based number of the last page
      Since:
      2.0
    • getFilePath

      String getFilePath()
      Returns the full path of the file to print to. Used only when getPrintToFile() returns true.
      Returns:
      the path of the file to print to
      Since:
      2.0
    • getInstalledPrinters

      String[] getInstalledPrinters()
      Returns the names of all printers installed on this computer.
      Returns:
      an array with the names of the installed printers; empty when there are none
      Since:
      2.0
    • getPrinterDriver

      String getPrinterDriver()
      Returns the printer driver.
      Returns:
      the printer driver
      Since:
      2.0
      See Also:
    • getPrinterName

      String getPrinterName()
      Returns the name of the printer used for printing.
      Returns:
      the printer name
      Since:
      2.0
    • getPrintToFile

      boolean getPrintToFile()
      Answers whether printing goes to a file instead of a printer.
      Returns:
      true to print to a file, false otherwise
      Since:
      2.0
    • getScope

      PrintScope getScope()
      Returns which pages are printed: all pages or a range of pages.
      Returns:
      the print scope; never null
      Since:
      2.0
      See Also:
    • getStartPage

      int getStartPage()
      Returns the first page to print when printing a range of pages (PrintScope.PAGE_RANGE).
      Returns:
      the 1-based number of the first page
      Since:
      2.0
    • setCollate

      void setCollate(boolean collate)
      Sets whether printed copies are collated.

      This setting may be controlled by the printer driver: if the printer collates by itself, the value of this setting may always be false.

      Parameters:
      collate - true to collate copies, false not to
      Since:
      2.0
    • setCopyCount

      void setCopyCount(int copyCount)
      Sets the number of copies to print.

      This setting may be controlled by the printer driver: if the printer prints multiple copies by itself, the value of this setting may always be 1.

      Parameters:
      copyCount - the number of copies; at least 1
      Throws:
      IllegalArgumentException - if copyCount is less than 1.
      Since:
      2.0
      See Also:
    • setDuplexMode

      void setDuplexMode(DuplexMode duplexMode)
      Sets the duplex mode, for printers that support it.
      Parameters:
      duplexMode - the duplex mode; cannot be null
      Throws:
      NullPointerException - if duplexMode is null
      Since:
      2.0
      See Also:
    • setEndPage

      void setEndPage(int endPage)
      Sets the last page to print when printing a range of pages (PrintScope.PAGE_RANGE).
      Parameters:
      endPage - the 1-based number of the last page
      Throws:
      IllegalArgumentException - if endPage is less than 1
      Since:
      2.0
    • setFilePath

      void setFilePath(String name) throws UnsupportedOperationException
      Sets the full path of the PDF file to print to. Used only when getPrintToFile() returns true.

      Printing to a PDF file is available on macOS only.

      Parameters:
      name - the full path of the PDF file; cannot be null or empty
      Throws:
      UnsupportedOperationException - when called on an operating system other than macOS
      NullPointerException - if name is null
      IllegalArgumentException - if name is empty
      Since:
      2.0
    • setPrinterDriver

      void setPrinterDriver(String driver)
      Sets the printer driver to use for printing:
      • On macOS, the destination type ("Printer", "Fax", "File", or "Preview").
      • On Windows, the name of the driver (often "winspool").
      • On Linux (GTK), the backend type name, for example "GtkPrintBackendCups".
      Parameters:
      driver - the printer driver; cannot be null or empty
      Throws:
      NullPointerException - if driver is null
      IllegalArgumentException - if driver is empty
      Since:
      2.0
    • setPrinterName

      void setPrinterName(String name)
      Sets the name of the printer to use for printing: the printer name on macOS and Linux, the device name on Windows. The names of the installed printers are returned by getInstalledPrinters().
      Parameters:
      name - the printer name; cannot be null or empty
      Throws:
      NullPointerException - if name is null
      IllegalArgumentException - if name is empty
      Since:
      2.0
    • setPrintToFile

      void setPrintToFile(boolean printToFile) throws UnsupportedOperationException
      Sets whether printing goes to a PDF file, set with setFilePath(String), instead of a printer.

      Printing to a PDF file is available on macOS only.

      Parameters:
      printToFile - true to print to a file, false to print to a printer
      Throws:
      UnsupportedOperationException - when called on an operating system other than macOS
      Since:
      2.0
    • setScope

      void setScope(PrintScope scope)
      Sets which pages are printed: all pages or a range of pages.
      Parameters:
      scope - the pages to print; cannot be null
      Throws:
      NullPointerException - if scope is null
      Since:
      2.0
      See Also:
    • setStartPage

      void setStartPage(int startPage)
      Sets the first page to print when printing a range of pages (PrintScope.PAGE_RANGE).
      Parameters:
      startPage - the 1-based number of the first page
      Throws:
      IllegalArgumentException - if startPage is less than 1
      Since:
      2.0