Class

UIPrintFormatter

An abstract base class for print formatters, which are objects that lay out custom printable content that can cross page boundaries.

Overview

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 UIPrintFormatter: UISimpleTextPrintFormatter, UIMarkupTextPrintFormatter, and UIViewPrintFormatter.

You can assign a single print formatter for a print job via the printFormatter property of the UIPrintInteractionController shared instance; or you can specify one or more print formatters that are associated with specific pages of a page renderer through the addPrintFormatter(_:startingAtPageAt:)method of UIPrintPageRenderer. A page renderer is an instance of a custom subclass of UIPrintPageRenderer that draws content for printing.

UIPrintFormatter 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 UIPrintPaper and UIPrintPageRenderer properties, that define the layout of a multi-page print job.

Figure 1

Layout of printed content

Third-party subclasses of UIPrintFormatter are not recommended. If you have custom content to print, use a custom UIPrintPageRenderer object.

Topics

Laying Out the Content

var contentInsets: UIEdgeInsets

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

Deprecated
var perPageContentInsets: UIEdgeInsets

The margins for each printed page.

var maximumContentHeight: CGFloat

The maximum height of the content area.

var maximumContentWidth: CGFloat

The maximum width of the content area.

Managing Pagination

var startPage: Int

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

var pageCount: Int

The number of pages to be printed.

Drawing the Content

func draw(in: CGRect, forPageAt: Int)

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

func rectForPage(at: Int)

Returns the area enclosing a specified page of content.

Communicating with the Page Renderer

func removeFromPrintPageRenderer()

Removes the print formatter from the page renderer.

var printPageRenderer: UIPrintPageRenderer?

Returns the page renderer with which the receiver is associated.

Relationships

Inherits From

See Also

Formatters

class UIViewPrintFormatter

An object that lays out the drawn content (which can span multiple pages) of a view for printing.

class UISimpleTextPrintFormatter

An object that lays out plain text for printing, possibly over multiple pages.

class UIMarkupTextPrintFormatter

An object that lays out HTML markup text for a multipage print job.