Package org.eclipse.draw2d

# Class PrintOperation

java.lang.Object
org.eclipse.draw2d.PrintOperation

Direct Known Subclasses:
  `PrintFigureOperation`

public abstract class PrintOperation extends Object
Implementation of draw2d's printing capabilities.

## Constructor Summary

Constructors
Constructor
Description
`PrintOperation()`
Creates a new PrintOperation
`PrintOperation(Printer p)`
Creates a new PrintOperation on Printer p

## Method Summary

Modifier and Type
Method
Description
`protected void`
`cleanup()`
Disposes the PrinterGraphics and GC objects associated with this PrintOperation.
`protected Graphics`
`createGraphics(SWTGraphics g, Printer p)`
Creates a new `PrinterGraphics` with Graphics `g`, using Printer `p`.
`protected Graphics`
`getFreshGraphics()`
Returns a new Graphics setup for the Printer associated with this PrintOperation.
`protected PrinterGraphics`
`getFreshPrinterGraphics()`
Deprecated, for removal: This API element is subject to removal in a future version.
Use `getFreshGraphics()` instead.
`Printer`
`getPrinter()`
Returns the printer.
`Rectangle`
`getPrintRegion()`
Returns a Rectangle that represents the region that can be printed to.
`protected void`
`preparePrintSource()`
This method contains all operations performed to sourceFigure prior to being printed.
`protected abstract void`
`printPages()`
This method is responsible for printing pages.
`protected void`
`restorePrintSource()`
This method contains all operations performed to sourceFigure after being printed.
`void`
`run(String jobName)`
Sets the print job into motion.
`void`
`setPrinter(Printer printer)`
Sets the printer.
`void`
`setPrintMargin(Insets margin)`
Sets the page margin in pels (logical pixels) to the passed Insets.(72 pels == 1 inch)
`protected void`
`setupGraphicsForPage(Graphics g)`
Manipulates the PrinterGraphics to position it to paint in the desired region of the page.
`protected void`
`setupGraphicsForPage(PrinterGraphics pg)`
Deprecated, for removal: This API element is subject to removal in a future version.
Use `setupGraphicsForPage(Graphics)` instead.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### PrintOperation

public PrintOperation()
Creates a new PrintOperation

### PrintOperation

public PrintOperation(Printer p)
Creates a new PrintOperation on Printer p

Parameters:
  `p` - The printer to print on

## Method Details

### cleanup

protected void cleanup()
Disposes the PrinterGraphics and GC objects associated with this PrintOperation.

### getFreshPrinterGraphics

@Deprecated(forRemoval=true, since="2025-06") protected PrinterGraphics getFreshPrinterGraphics()
Deprecated, for removal: This API element is subject to removal in a future version.
Use `getFreshGraphics()` instead. This method will be removed after the 2027-06 release.
Returns a new PrinterGraphics setup for the Printer associated with this PrintOperation. This method will be removed after the 2027-06 release. Important: This method should not be called if `createGraphics(SWTGraphics, Printer)` has been subclasses.

Returns:
  PrinterGraphics The new PrinterGraphics

### getFreshGraphics

protected Graphics getFreshGraphics()
Returns a new Graphics setup for the Printer associated with this PrintOperation.

Returns:
  Graphics The new Graphics
Since:
  3.20

### createGraphics

protected Graphics createGraphics(SWTGraphics g, Printer p)
Creates a new `PrinterGraphics` with Graphics `g`, using Printer `p`. May be overridden by subclasses if a different `Graphics` object is required.

Parameters:
  `g` - Graphics object to draw with
  `p` - Printer to print to
Returns:
  A new `PrinterGraphics` object.
Since:
  3.20

### getPrinter

public Printer getPrinter()
Returns the printer.

Returns:
  Printer

### getPrintRegion

public Rectangle getPrintRegion()
Returns a Rectangle that represents the region that can be printed to. The x, y, height, and width values are using the printers coordinates.

Returns:
  the print region

### preparePrintSource

protected void preparePrintSource()
This method contains all operations performed to sourceFigure prior to being printed.

### printPages

protected abstract void printPages()
This method is responsible for printing pages. (A page is printed by calling Printer.startPage(), followed by painting to the PrinterGraphics object, and then calling Printer.endPage()).

### restorePrintSource

protected void restorePrintSource()
This method contains all operations performed to sourceFigure after being printed.

### run

public void run(String jobName)
Sets the print job into motion.

Parameters:
  `jobName` - A String representing the name of the print job

### setPrinter

public void setPrinter(Printer printer)
Sets the printer.

Parameters:
  `printer` - The printer to set

### setPrintMargin

public void setPrintMargin(Insets margin)
Sets the page margin in pels (logical pixels) to the passed Insets.(72 pels == 1 inch)

Parameters:
  `margin` - The margin to set on the page

### setupGraphicsForPage

@Deprecated(forRemoval=true, since="2025-06") protected void setupGraphicsForPage(PrinterGraphics pg)
Deprecated, for removal: This API element is subject to removal in a future version.
Use `setupGraphicsForPage(Graphics)` instead. This method will be removed after the 2027-06 release.
Manipulates the PrinterGraphics to position it to paint in the desired region of the page. (Default is the top left corner of the page).

Parameters:
  `pg` - The PrinterGraphics to setup

### setupGraphicsForPage

protected void setupGraphicsForPage(Graphics g)
Manipulates the PrinterGraphics to position it to paint in the desired region of the page. (Default is the top left corner of the page).

Parameters:
  `g` - The Graphics to setup
Since:
  3.20