UIPrint​Formatter is an abstract base class for print formatters: objects that lay out custom printable content that can cross page boundaries. Given a print formatter, the printing system can automate the printing of the type of content associated with the print formatter.


Examples of such content could be a web view, a mix of images and text, or a long text document. The UIKit framework provides several concrete subclasses of UIPrint​Formatter: UISimple​Text​Print​Formatter, UIMarkup​Text​Print​Formatter, and UIView​Print​Formatter.

You can assign a single print formatter for a print job via the print​Formatter property of the UIPrint​Interaction​Controller shared instance; or you can specify one or more print formatters that are associated with specific pages of a page renderer through the add​Print​Formatter(_:​starting​At​Page​At:​)method of UIPrint​Page​Renderer. A page renderer is an instance of a custom subclass of UIPrint​Page​Renderer that draws content for printing.

UIPrint​Formatter publishes an interface that allows you to specify the starting page for a print job and the margins around the printed content; given that information plus the content, a print formatter computes the number of pages for the print job. Figure 1 depicts the print-formatter properties, along with certain UIPrint​Paper and UIPrint​Page​Renderer properties, that define the layout of a multi-page print job.

Figure 1

Layout of printed content

Third-party subclasses of UIPrint​Formatter are not recommended. If you have custom content to print, use a custom UIPrint​Page​Renderer object.


Laying Out the Content

var content​Insets:​ UIEdge​Insets

The distances the edges of content are inset from the printing rectangle.

var maximum​Content​Height:​ CGFloat

The maximum height of the content area.

var maximum​Content​Width:​ CGFloat

The maximum width of the content area.

Managing Pagination

var start​Page:​ Int

The index of the first page that the print formatter lays out.

var page​Count:​ Int

The number of pages to be printed.

Drawing the Content

func draw(in:​ CGRect, for​Page​At:​ Int)

Draws the portion of a print formatter’s content that goes in the given area for the specified page

func rect​For​Page(at:​ Int)

Returns the area enclosing a specified page of content.

Communicating with the Page Renderer

func remove​From​Print​Page​Renderer()

Removes the print formatter from the page renderer.

var print​Page​Renderer:​ UIPrint​Page​Renderer?

Returns the page renderer with which the receiver is associated.


Inherits From