Printers

Methods

Print

Attempts to print the web page.

await window.deskifier.printers.print({ arguments })

Arguments

  • windowId String (Optional)
    The ID of the window to print. Defaults to the current window.

  • silent Boolean (Optional)
    Don't ask user for print settings. Default is false.

  • printBackground Boolean (Optional)

    Prints the background color and image of the web page. Default is false.

  • deviceName String (Optional)
    Set the printer device name to use. Must be the system-defined name and not the 'friendly' name, e.g 'Brother_QL_820NWB' and not 'Brother QL-820NWB'.

  • color Boolean (Optional)

    Set whether the printed web page will be in color or grayscale. Default is true.

  • margins Object (Optional)

    • marginType String

      Can be default, none, printableArea, or custom. If custom is chosen, you will also need to specify top, bottom, left, and right.

    • top Number
      The top margin of the printed web page, in pixels.

    • bottom Number
      The bottom margin of the printed web page, in pixels.

    • left Number
      The left margin of the printed web page, in pixels.

    • right Number
      The right margin of the printed web page, in pixels.

  • landscape Boolean (Optional)
    Whether the web page should be printed in landscape mode. Default is false.

  • scaleFactor Number (Optional)
    The scale factor of the web page.

  • pagesPerSheet Number (Optional)
    The number of pages to print per page sheet.

  • collate Boolean (Optional)
    Whether the web page should be collated.

  • copies Number (Optional)
    The number of copies of the web page to print.

  • pageRanges Array of Objects (Optional)
    The page range to print. On macOS, only one range is honored.

    • from Number
      Index of the first page to print (0-based).
    • to Number
      Index of the last page to print (inclusive) (0-based).
  • duplexMode String (Optional)
    Set the duplex mode of the printed web page. Can be simplex, shortEdge, or longEdge.

  • dpi Object (Optional)

    • horizontal Number
      The horizontal dpi.
    • vertical Number
      The vertical dpi.
  • header String (Optional)
    string to be printed as page header.

  • footer String (Optional)
    string to be printed as page footer.

  • pageSize String (Optional)
    Specify page size of the printed document. Can be A0, A1, A2, A3, A4, A5, A6, Legal, Letter, Tabloid or an Object containing height and width.

Returns

  • success Boolean
    If the action was successful. If the user cancels the print, this will return false.
  • message String
    Additional confirmation, or error details if action was unsuccessful.

Example

const result = await window.deskifier.printers.print({ windowId: 'main' });

console.log(result.success);  // true

Attempts to create a PDF from the web page.

await window.deskifier.printers.printToPdf({ arguments })

Arguments

  • windowId String

    The ID of the window to print. Defaults to the current window.

  • filePath String (Required)
    The path to save the PDF file to.

  • landscape Boolean (Optional)
    Paper orientation. true for landscape, false for portrait. Defaults to false.

  • displayHeaderFooter Boolean (Optional)
    Whether to display header and footer. Defaults to false.

  • printBackground Boolean (Optional)
    Whether to print background graphics. Defaults to false.

  • scale Number (Optional)
    Scale of the webpage rendering. Defaults to 1.

  • pageSize String (Optional)
    Specify page size of the generated PDF. Can be A0, A1, A2, A3, A4, A5, A6, Legal, Letter, Tabloid, Ledger, or an Object containing height and width in inches. Defaults to Letter.

  • margins Object (Optional)

    • top Number
      Top margin in inches. Defaults to 1cm (~0.4 inches).
    • bottom Number
      Bottom margin in inches. Defaults to 1cm (~0.4 inches).
    • left Number
      Left margin in inches. Defaults to 1cm (~0.4 inches).
    • right Number
      Right margin in inches. Defaults to 1cm (~0.4 inches).
  • pageRanges String (Optional)
    Page ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.

  • headerTemplate String (Optional)
    HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them: date (formatted print date), title (document title), url (document location), pageNumber (current page number) and totalPages (total pages in the document). For example, <span class=title></span> would generate span containing the title.

  • footerTemplate String (Optional)
    HTML template for the print footer. Should use the same format as the headerTemplate.

  • preferCSSPageSize Boolean (Optional)
    Whether or not to prefer page size as defined by css. Defaults to false, in which case the content will be scaled to fit the paper size.

Returns

  • success Boolean
    If the action was successful.
  • message String
    Additional confirmation, or error details if action was unsuccessful.
  • path String
    The file path of the saved PDF.

Properties

Get Printers

Returns all printers connected to the device.

await window.deskifier.printers.getAll()

Returns

  • success Boolean
    If the action was successful.
  • message String
    Additional confirmation, or error details if action was unsuccessful.
  • printers Array of si.Printer