Package limn.backend

Class Printer

java.lang.Object
limn.backend.Printer

public final class Printer extends Object
What prints a PDF through the system's own print dialog, owned by a window: reached from NativeWindow.printer().

 window.printer().print(invoice, "Invoice 0091")
         .thenAccept(result -> status.setText(result.toString()));
 

The dialog is the system's: it chooses the printer, the copies, the pages and the paper, and it may save the job as PDF where the system offers that. While it is open the window waits and the UI thread does not. A document Limn lays out is printed by limn.print.Document#print, which writes its PDF and comes here; a PDF the application already has (one it received, one it saved earlier) is printed by the calls below without a document.

The system scales a page to the printer's paper when the two differ, and never up; it does not lay the document out again.

Each call returns at once and completes on the UI thread. It throws for a null, a blank title and off the UI thread, as the rest of the window's API does, at the call and before anything is read, and never for what the PDF holds: a file that cannot be read, or a system that refuses the bytes, completes with PrintResult.FAILED and a WARNING saying why.

  • Field Details

  • Constructor Details

    • Printer

      public Printer(PrinterPeer peer)
      Parameters:
      peer - what the window's backend asks the system through
  • Method Details

    • isAvailable

      public boolean isAvailable()
      Whether a print can be asked under this window, answered without asking anything: an application greys out its "Print…" when it is false. Saving a document as PDF never depends on it.
      Returns:
      false for a window with no desktop under it, and for a Linux desktop with no print portal
    • print

      public CompletionStage<PrintResult> print(Path pdf, String title)
      Prints a PDF file through the system's dialog.
      Parameters:
      pdf - the file; read on a thread of its own
      title - the job's name in the system's queue; never blank
      Returns:
      what became of it, completed on the UI thread
      Throws:
      IllegalArgumentException - if title is blank, here, before the file is read
    • print

      public CompletionStage<PrintResult> print(byte[] pdf, String title)
      Prints a PDF held in memory through the system's dialog.
      Parameters:
      pdf - a complete PDF file; not copied, and not to be changed until the stage completes
      title - the job's name in the system's queue; never blank
      Returns:
      what became of it, completed on the UI thread
      Throws:
      IllegalArgumentException - if title is blank
    • print

      public CompletionStage<PrintResult> print(PrintJob job)
      Prints a job, the form a document laid out by Limn uses: it knows its paper, which the system's dialog then starts from.
      Parameters:
      job - what to print
      Returns:
      what became of it, completed on the UI thread