Page
in package
Level 1 Page — spatial drawing surface with explicit coordinates.
Collects drawing operations and emits them to a ContentStream. Each draw method wraps its operators in a graphics state save/restore so drawings are isolated from each other.
Escape hatches: $page->contentStream() — raw ContentStream (Level 0 operators) $page->corePage() — raw Core\Document\Page (Level 0 dict)
Table of Contents
Methods
- __construct() : mixed
- contentStream() : ContentStream
- Access the raw ContentStream for Level 0 operator control.
- corePage() : Page
- Access the raw Core\Document\Page for Level 0 dict manipulation.
- drawArrow() : self
- Draw an arrow from (x1,y1) to (x2,y2) with a triangular arrowhead.
- drawBarcode() : self
- Render a barcode at `(x, y)` (lower-left of the quiet zone).
- drawCallout() : float
- Draw a callout panel at `(x, y)` with the given total `$width`.
- drawCircle() : self
- Draw a circle.
- drawEllipse() : self
- Draw an ellipse.
- drawImage() : self
- Draw an image at a specific position.
- drawLine() : self
- Draw a straight line.
- drawList() : self
- Draw a {@see ListBlock} at `(x, y)`. The marker for the first item sits at `$x`; wrapped text starts one indent further right.
- drawPath() : self
- Draw a custom path using a PathBuilder closure.
- drawPolygon() : self
- Draw a polygon from a list of points.
- drawQuote() : self
- Draw a blockquote at `(x, y)`: indented body text with a coloured vertical bar down the left edge. The top of the quote sits at `$y`; text and bar grow downward.
- drawRectangle() : self
- Draw a rectangle.
- drawRoundedRectangle() : self
- Draw a rectangle with rounded corners.
- drawStar() : self
- Draw a star shape.
- drawTable() : self
- Draw a {@see Table} at `(x, y)`. The top of the table sits at `y`; rows render downward.
- drawTemplate() : self
- Place a Form XObject template on this page at `(x, y)`. The template's intrinsic dimensions come from its BBox; pass `$w` and / or `$h` to scale it (`null` keeps the BBox dimension).
- drawText() : self
- Draw text at a specific position.
- ensureOpacityState() : string
- Lazily build (or reuse) an ExtGState resource for this page that sets CA + ca and returns its resource name. The cache key is derived from the alpha values so identical opacity calls reuse the same registered ExtGState. Public so consumers writing to additional content streams (e.g. the html-to-pdf painter) can grab the resource name and emit `gs` themselves without going through `setOpacity()`'s stream side effect.
- inLayer() : self
- Wrap a closure's drawing operations as marked content belonging to the given optional-content group (layer). The closure runs between `/OC /<name> BDC` and `EMC`, and the OCG reference is added to this page's `/Properties` resource under a unique name.
- raw() : self
- Execute raw ContentStream operations via a closure.
- rotate() : self
- Concatenate a rotation onto the current transformation matrix.
- scale() : self
- Concatenate a non-uniform scale onto the CTM.
- setArtBox() : self
- Set /ArtBox — the page's meaningful content extent.
- setBleedBox() : self
- Set /BleedBox — the area to be clipped when output is produced for production presses.
- setCropBox() : self
- Set /CropBox — the visible region when the page is displayed.
- setOpacity() : self
- Set the stroke / fill opacity for subsequent drawing. Registers a fresh ExtGState resource keyed by the alpha values so opacity can vary across the page without re-registering on every call.
- setRotation() : self
- Set the page rotation, in degrees clockwise. Only multiples of 90 are valid per ISO 32000-2 § 7.7.3.3 — anything else throws.
- setTrimBox() : self
- Set /TrimBox — the intended dimensions of the finished page.
- skew() : self
- Concatenate a skew transform onto the CTM. `$alphaDeg` shears along the X axis, `$betaDeg` along the Y axis.
- translate() : self
- Concatenate a translation onto the CTM.
- useGradient() : string
- Register a {@see ShadingPattern} as a pattern resource on this page and return the resource name to use with {@see ContentStream::setFillColorSpace}() / `setFillColor()`.
- useSpotColor() : string
- Attach a registered spot color to this page's resources and return the resource name to use in content-stream `cs` / `CS` operators (via {@see ContentStream::setFillColorSpace()} / {@see ContentStream::setStrokeColorSpace()}).
- withTransform() : self
- Scope a closure's drawing within a `q ... Q` (save/restore) pair. Any transforms or graphics-state changes made inside the closure are reverted on exit.
Methods
__construct()
public
__construct(Page $corePage, PdfWriter $writer) : mixed
Parameters
contentStream()
Access the raw ContentStream for Level 0 operator control.
public
contentStream() : ContentStream
Return values
ContentStreamcorePage()
Access the raw Core\Document\Page for Level 0 dict manipulation.
public
corePage() : Page
Return values
PagedrawArrow()
Draw an arrow from (x1,y1) to (x2,y2) with a triangular arrowhead.
public
drawArrow(float $x1, float $y1, float $x2, float $y2[, float $headSize = 8 ][, ColorInterface|null $color = null ][, float $width = 1.0 ]) : self
Parameters
- $x1 : float
- $y1 : float
- $x2 : float
- $y2 : float
- $headSize : float = 8
- $color : ColorInterface|null = null
- $width : float = 1.0
Return values
selfdrawBarcode()
Render a barcode at `(x, y)` (lower-left of the quiet zone).
public
drawBarcode(Symbology $symbology, string $data, float $x, float $y[, BarcodeOptions|null $options = null ]) : self
The bitmap is produced by BarcodeRenderer::render() and drawn inline — for documents that emit the same barcode many times, prefer PdfDoc::createBarcode() + drawTemplate().
Parameters
- $symbology : Symbology
- $data : string
- $x : float
- $y : float
- $options : BarcodeOptions|null = null
Return values
selfdrawCallout()
Draw a callout panel at `(x, y)` with the given total `$width`.
public
drawCallout(string $text, float $x, float $y, float $width, CalloutType $type, Font $bodyFont[, Font|null $titleFont = null ][, float $size = 11.0 ][, float $lineHeight = 1.2 ][, CalloutStyle|null $style = null ]) : float
The top of the panel sits at $y; body grows downward and the
returned float is the height consumed.
The caller supplies the body and (optionally) title font handles. Standard 14 fonts only — wrap-aware widths come from StandardFontMetrics.
Parameters
- $text : string
- $x : float
- $y : float
- $width : float
- $type : CalloutType
- $bodyFont : Font
- $titleFont : Font|null = null
- $size : float = 11.0
- $lineHeight : float = 1.2
- $style : CalloutStyle|null = null
Return values
floatdrawCircle()
Draw a circle.
public
drawCircle(float $cx, float $cy, float $radius[, ColorInterface|null $fill = null ][, ColorInterface|null $stroke = null ][, float $strokeWidth = 1.0 ]) : self
Parameters
- $cx : float
- $cy : float
- $radius : float
- $fill : ColorInterface|null = null
- $stroke : ColorInterface|null = null
- $strokeWidth : float = 1.0
Return values
selfdrawEllipse()
Draw an ellipse.
public
drawEllipse(float $cx, float $cy, float $rx, float $ry[, ColorInterface|null $fill = null ][, ColorInterface|null $stroke = null ][, float $strokeWidth = 1.0 ]) : self
Parameters
- $cx : float
- $cy : float
- $rx : float
- $ry : float
- $fill : ColorInterface|null = null
- $stroke : ColorInterface|null = null
- $strokeWidth : float = 1.0
Return values
selfdrawImage()
Draw an image at a specific position.
public
drawImage(string $path, float $x, float $y[, float|null $width = null ][, float|null $height = null ]) : self
Parameters
- $path : string
-
File path to the image
- $x : float
-
Left edge x coordinate
- $y : float
-
Bottom edge y coordinate
- $width : float|null = null
-
Display width (null = natural size in points at 72 DPI)
- $height : float|null = null
-
Display height (null = proportional to width)
Return values
selfdrawLine()
Draw a straight line.
public
drawLine(float $x1, float $y1, float $x2, float $y2[, ColorInterface|null $color = null ][, float $width = 1.0 ][, DashPattern|null $dash = null ]) : self
Parameters
- $x1 : float
- $y1 : float
- $x2 : float
- $y2 : float
- $color : ColorInterface|null = null
- $width : float = 1.0
- $dash : DashPattern|null = null
Return values
selfdrawList()
Draw a {@see ListBlock} at `(x, y)`. The marker for the first item sits at `$x`; wrapped text starts one indent further right.
public
drawList(ListBlock $list, float $x, float $y, Font $font[, float $fontSize = 11.0 ][, float $maxWidth = 468.0 ][, float $lineHeight = 1.2 ][, ListStyle|null $style = null ]) : self
Standard 14 fonts only — pass a custom font's metrics by going through ListRenderer::drawBlock() directly.
Parameters
- $list : ListBlock
- $x : float
- $y : float
- $font : Font
- $fontSize : float = 11.0
- $maxWidth : float = 468.0
- $lineHeight : float = 1.2
- $style : ListStyle|null = null
Return values
selfdrawPath()
Draw a custom path using a PathBuilder closure.
public
drawPath(callable(PathBuilder): void $builder[, ColorInterface|null $fill = null ][, ColorInterface|null $stroke = null ][, float $strokeWidth = 1.0 ]) : self
Parameters
- $builder : callable(PathBuilder): void
- $fill : ColorInterface|null = null
- $stroke : ColorInterface|null = null
- $strokeWidth : float = 1.0
Return values
selfdrawPolygon()
Draw a polygon from a list of points.
public
drawPolygon(array<string|int, array{0: float, 1: float}> $points[, ColorInterface|null $fill = null ][, ColorInterface|null $stroke = null ][, float $strokeWidth = 1.0 ]) : self
Parameters
- $points : array<string|int, array{0: float, 1: float}>
-
[[x,y], [x,y], ...]
- $fill : ColorInterface|null = null
- $stroke : ColorInterface|null = null
- $strokeWidth : float = 1.0
Return values
selfdrawQuote()
Draw a blockquote at `(x, y)`: indented body text with a coloured vertical bar down the left edge. The top of the quote sits at `$y`; text and bar grow downward.
public
drawQuote(string $text, float $x, float $y, Font $font[, float $size = 11.0 ][, float $maxWidth = 468.0 ][, float $lineHeight = 1.2 ][, float $indent = 18.0 ][, float $barWidth = 2.0 ][, ColorInterface|null $barColor = null ][, ColorInterface|null $textColor = null ]) : self
The caller selects the font (typically the italic variant) and the desired bar colour. Returns the height consumed.
Parameters
- $text : string
- $x : float
- $y : float
- $font : Font
- $size : float = 11.0
- $maxWidth : float = 468.0
- $lineHeight : float = 1.2
- $indent : float = 18.0
- $barWidth : float = 2.0
- $barColor : ColorInterface|null = null
- $textColor : ColorInterface|null = null
Return values
selfdrawRectangle()
Draw a rectangle.
public
drawRectangle(float $x, float $y, float $width, float $height[, ColorInterface|null $fill = null ][, ColorInterface|null $stroke = null ][, float $strokeWidth = 1.0 ]) : self
Parameters
- $x : float
- $y : float
- $width : float
- $height : float
- $fill : ColorInterface|null = null
- $stroke : ColorInterface|null = null
- $strokeWidth : float = 1.0
Return values
selfdrawRoundedRectangle()
Draw a rectangle with rounded corners.
public
drawRoundedRectangle(float $x, float $y, float $width, float $height, float $radius[, ColorInterface|null $fill = null ][, ColorInterface|null $stroke = null ][, float $strokeWidth = 1.0 ]) : self
Parameters
- $x : float
- $y : float
- $width : float
- $height : float
- $radius : float
- $fill : ColorInterface|null = null
- $stroke : ColorInterface|null = null
- $strokeWidth : float = 1.0
Return values
selfdrawStar()
Draw a star shape.
public
drawStar(float $cx, float $cy, float $outerRadius, float $innerRadius[, int $points = 5 ][, ColorInterface|null $fill = null ][, ColorInterface|null $stroke = null ][, float $strokeWidth = 1.0 ]) : self
Parameters
- $cx : float
- $cy : float
- $outerRadius : float
- $innerRadius : float
- $points : int = 5
-
Number of points (5 = classic star)
- $fill : ColorInterface|null = null
- $stroke : ColorInterface|null = null
- $strokeWidth : float = 1.0
Return values
selfdrawTable()
Draw a {@see Table} at `(x, y)`. The top of the table sits at `y`; rows render downward.
public
drawTable(Table $table, float $x, float $y, Font $bodyFont[, Font|null $headerFont = null ][, float $fontSize = 11.0 ][, float $lineHeight = 1.2 ][, TableStyle|null $style = null ]) : self
$table->columnWidths must be set — Writer\Page is the
positioned API and does not know the surrounding content column.
For the auto-equal-columns convenience, use Pdf::addTable().
Only the standard 14 fonts are supported by this signature; for custom fonts, construct a TableRenderContext manually and call TableRenderer directly.
Parameters
- $table : Table
- $x : float
- $y : float
- $bodyFont : Font
- $headerFont : Font|null = null
- $fontSize : float = 11.0
- $lineHeight : float = 1.2
- $style : TableStyle|null = null
Return values
selfdrawTemplate()
Place a Form XObject template on this page at `(x, y)`. The template's intrinsic dimensions come from its BBox; pass `$w` and / or `$h` to scale it (`null` keeps the BBox dimension).
public
drawTemplate(FormXObject $template, float $x, float $y[, float|null $w = null ][, float|null $h = null ]) : self
The template's XObject reference is added to the page's
resource dict under a stable name (Tpl<objNum>) so repeated
draws of the same template reuse the same entry.
Parameters
- $template : FormXObject
- $x : float
- $y : float
- $w : float|null = null
- $h : float|null = null
Return values
selfdrawText()
Draw text at a specific position.
public
drawText(string $text, float $x, float $y, Font $font[, float $size = 12 ][, ColorInterface|null $color = null ][, bool $underline = false ][, bool $strikethrough = false ]) : self
Parameters
- $text : string
- $x : float
- $y : float
- $font : Font
- $size : float = 12
- $color : ColorInterface|null = null
- $underline : bool = false
- $strikethrough : bool = false
Return values
selfensureOpacityState()
Lazily build (or reuse) an ExtGState resource for this page that sets CA + ca and returns its resource name. The cache key is derived from the alpha values so identical opacity calls reuse the same registered ExtGState. Public so consumers writing to additional content streams (e.g. the html-to-pdf painter) can grab the resource name and emit `gs` themselves without going through `setOpacity()`'s stream side effect.
public
ensureOpacityState(float $stroke, float $fill) : string
Parameters
- $stroke : float
- $fill : float
Return values
stringinLayer()
Wrap a closure's drawing operations as marked content belonging to the given optional-content group (layer). The closure runs between `/OC /<name> BDC` and `EMC`, and the OCG reference is added to this page's `/Properties` resource under a unique name.
public
inLayer(OCG $layer, callable(self): void $body) : self
Viewers that support optional content (Acrobat, Foxit, etc.) will toggle the wrapped drawing on / off when the layer is shown / hidden.
Parameters
- $layer : OCG
- $body : callable(self): void
Return values
selfraw()
Execute raw ContentStream operations via a closure.
public
raw(callable(ContentStream): void $fn) : self
Parameters
- $fn : callable(ContentStream): void
Return values
selfrotate()
Concatenate a rotation onto the current transformation matrix.
public
rotate(float $degrees[, float|null $cx = null ][, float|null $cy = null ]) : self
If $cx / $cy are given, rotation is around that point;
otherwise around the origin (0, 0).
Subsequent drawing inherits this rotation until the next graphics
state restore. Wrap calls in withTransform() for scoped effects.
Parameters
- $degrees : float
- $cx : float|null = null
- $cy : float|null = null
Return values
selfscale()
Concatenate a non-uniform scale onto the CTM.
public
scale(float $sx, float $sy) : self
Parameters
- $sx : float
- $sy : float
Return values
selfsetArtBox()
Set /ArtBox — the page's meaningful content extent.
public
setArtBox(Rectangle $rect) : self
Parameters
- $rect : Rectangle
Return values
selfsetBleedBox()
Set /BleedBox — the area to be clipped when output is produced for production presses.
public
setBleedBox(Rectangle $rect) : self
Parameters
- $rect : Rectangle
Return values
selfsetCropBox()
Set /CropBox — the visible region when the page is displayed.
public
setCropBox(Rectangle $rect) : self
Defaults to MediaBox if unset.
Parameters
- $rect : Rectangle
Return values
selfsetOpacity()
Set the stroke / fill opacity for subsequent drawing. Registers a fresh ExtGState resource keyed by the alpha values so opacity can vary across the page without re-registering on every call.
public
setOpacity(float $stroke[, float|null $fill = null ]) : self
Stroke and fill default to the same value when only one argument is provided.
Parameters
- $stroke : float
- $fill : float|null = null
Return values
selfsetRotation()
Set the page rotation, in degrees clockwise. Only multiples of 90 are valid per ISO 32000-2 § 7.7.3.3 — anything else throws.
public
setRotation(int $degrees) : self
Parameters
- $degrees : int
Return values
selfsetTrimBox()
Set /TrimBox — the intended dimensions of the finished page.
public
setTrimBox(Rectangle $rect) : self
Parameters
- $rect : Rectangle
Return values
selfskew()
Concatenate a skew transform onto the CTM. `$alphaDeg` shears along the X axis, `$betaDeg` along the Y axis.
public
skew(float $alphaDeg, float $betaDeg) : self
Parameters
- $alphaDeg : float
- $betaDeg : float
Return values
selftranslate()
Concatenate a translation onto the CTM.
public
translate(float $tx, float $ty) : self
Parameters
- $tx : float
- $ty : float
Return values
selfuseGradient()
Register a {@see ShadingPattern} as a pattern resource on this page and return the resource name to use with {@see ContentStream::setFillColorSpace}() / `setFillColor()`.
public
useGradient(ShadingPattern $pattern) : string
Typical use: $g = $doc->addLinearGradient(new Point(0,0), new Point(200,0), [1,0,0], [0,0,1]); $name = $page->useGradient($g); $page->contentStream() ->setFillColorSpace('Pattern') ->setFillColor("/{$name}") // tinted patterns: setFillColor('1.0 /Name scn') ->rectangle(72, 600, 200, 80) ->fill();
Parameters
- $pattern : ShadingPattern
Return values
stringuseSpotColor()
Attach a registered spot color to this page's resources and return the resource name to use in content-stream `cs` / `CS` operators (via {@see ContentStream::setFillColorSpace()} / {@see ContentStream::setStrokeColorSpace()}).
public
useSpotColor(SpotColor $spot) : string
Parameters
- $spot : SpotColor
Return values
stringwithTransform()
Scope a closure's drawing within a `q ... Q` (save/restore) pair. Any transforms or graphics-state changes made inside the closure are reverted on exit.
public
withTransform(callable(self): void $body) : self
Parameters
- $body : callable(self): void