Skip to content

Gtk.PrintJob

class — extends GObject.Object

Represents a job that is sent to a printer.

You only need to deal directly with print jobs if you use the non-portable PrintUnixDialog API.

Use PrintJob.get_surface to obtain the cairo surface onto which the pages must be drawn. Use PrintJob.send to send the finished job to the printer. If you don’t use cairo GtkPrintJob also supports printing of manually generated PostScript, via PrintJob.set_source_file.

Constructors

new

@classmethod
def new(cls, title: str, printer: Printer, settings: PrintSettings, page_setup: PageSetup) -> PrintJob

Creates a new GtkPrintJob.

Parameters:

  • title — the job title
  • printer — a GtkPrinter
  • settings — a GtkPrintSettings
  • page_setup — a GtkPageSetup

Methods

get_collate

def get_collate(self) -> bool

Gets whether this job is printed collated.

get_n_up

def get_n_up(self) -> int

Gets the n-up setting for this job.

get_n_up_layout

def get_n_up_layout(self) -> NumberUpLayout

Gets the n-up layout setting for this job.

get_num_copies

def get_num_copies(self) -> int

Gets the number of copies of this job.

get_page_ranges

def get_page_ranges(self) -> list[PageRange]

Gets the page ranges for this job.

get_page_set

def get_page_set(self) -> PageSet

Gets the GtkPageSet setting for this job.

get_pages

def get_pages(self) -> PrintPages

Gets the GtkPrintPages setting for this job.

get_printer

def get_printer(self) -> Printer

Gets the GtkPrinter of the print job.

get_reverse

def get_reverse(self) -> bool

Gets whether this job is printed reversed.

get_rotate

def get_rotate(self) -> bool

Gets whether the job is printed rotated.

get_scale

def get_scale(self) -> float

Gets the scale for this job.

get_settings

def get_settings(self) -> PrintSettings

Gets the GtkPrintSettings of the print job.

get_status

def get_status(self) -> PrintStatus

Gets the status of the print job.

get_surface

def get_surface(self) -> cairo.Surface

Gets a cairo surface onto which the pages of the print job should be rendered.

get_title

def get_title(self) -> str

Gets the job title.

get_track_print_status

def get_track_print_status(self) -> bool

Returns whether jobs will be tracked after printing.

For details, see PrintJob.set_track_print_status.

send

def send(self, callback: PrintJobCompleteFunc) -> None

Sends the print job off to the printer.

Parameters:

  • callback — function to call when the job completes or an error occurs

set_collate

def set_collate(self, collate: bool) -> None

Sets whether this job is printed collated.

Parameters:

  • collate — whether the job is printed collated

set_n_up

def set_n_up(self, n_up: int) -> None

Sets the n-up setting for this job.

Parameters:

  • n_up — the n-up value

set_n_up_layout

def set_n_up_layout(self, layout: NumberUpLayout | int) -> None

Sets the n-up layout setting for this job.

Parameters:

  • layout — the n-up layout setting

set_num_copies

def set_num_copies(self, num_copies: int) -> None

Sets the number of copies for this job.

Parameters:

  • num_copies — the number of copies

set_page_ranges

def set_page_ranges(self, ranges: list[PageRange]) -> None

Sets the page ranges for this job.

Parameters:

  • ranges — pointer to an array of GtkPageRange structs

set_page_set

def set_page_set(self, page_set: PageSet | int) -> None

Sets the GtkPageSet setting for this job.

Parameters:

  • page_set — a GtkPageSet setting

set_pages

def set_pages(self, pages: PrintPages | int) -> None

Sets the GtkPrintPages setting for this job.

Parameters:

  • pages — the GtkPrintPages setting

set_reverse

def set_reverse(self, reverse: bool) -> None

Sets whether this job is printed reversed.

Parameters:

  • reverse — whether the job is printed reversed

set_rotate

def set_rotate(self, rotate: bool) -> None

Sets whether this job is printed rotated.

Parameters:

  • rotate — whether to print rotated

set_scale

def set_scale(self, scale: float) -> None

Sets the scale for this job.

1.0 means unscaled.

Parameters:

  • scale — the scale

set_source_fd

def set_source_fd(self, fd: int) -> bool

Make the GtkPrintJob send an existing document to the printing system.

The file can be in any format understood by the platforms printing system (typically PostScript, but on many platforms PDF may work too). See Printer.accepts_pdf and Printer.accepts_ps.

This is similar to PrintJob.set_source_file, but takes expects an open file descriptor for the file, instead of a filename.

Parameters:

  • fd — a file descriptor

set_source_file

def set_source_file(self, filename: str | bytes | os.PathLike[str] | os.PathLike[bytes]) -> bool

Make the GtkPrintJob send an existing document to the printing system.

The file can be in any format understood by the platforms printing system (typically PostScript, but on many platforms PDF may work too). See Printer.accepts_pdf and Printer.accepts_ps.

Parameters:

  • filename — the file to be printed

set_track_print_status

def set_track_print_status(self, track_status: bool) -> None

If track_status is True, the print job will try to continue report on the status of the print job in the printer queues and printer.

This can allow your application to show things like “out of paper” issues, and when the print job actually reaches the printer.

This function is often implemented using some form of polling, so it should not be enabled unless needed.

Parameters:

  • track_statusTrue to track status after printing

Properties

page_setup

page_setup: PageSetup  # read/write

Page setup.

printer

printer: Printer  # read/write

The printer to send the job to.

settings

settings: PrintSettings  # read/write

Printer settings.

title

title: str  # read/write

The title of the print job.

track_print_status

track_print_status: bool  # read/write

True if the print job will continue to emit status-changed signals after the print data has been setn to the printer.

Signals

status-changed

def on_status_changed(self) -> None: ...

Emitted when the status of a job changes.

The signal handler can use PrintJob.get_status to obtain the new status.