Format

Format API reference

Namespace: Com\Tecnick\Pdf\Page

abstract class Format

Source: src/Format.php:34

Constants

FORMAT

Array of page formats (width, height).

Measures are calculated in this way: (inches * 72) or (millimeters * 72 / 25.4)

public const FORMAT = [
    // ISO 216 A Series + 2 SIS 014711 extensions
    'A0' => [2383.937, 3370.394],
    // = (  841 x 1189 ) mm  = ( 33.11 x 46.81 ) in
    'A1' => [1683.78, 2383.937],
    // = (  594 x 841  ) mm  = ( 23.39 x 33.11 ) in
    'A2' => [1190.551, 1683.78],
    // = (  420 x 594  ) mm  = ( 16.54 x 23.39 ) in
    'A3' => [841.89, 1190.551],
    // = (  297 x 420  ) mm  = ( 11.69 x 16.54 ) in
// … truncated, see source

Source: src/Format.php:61

UNITRATIO

Array of conversion ratios relative to points.

72 is the default DPI (Dot Per Inch) document resolution.

public const UNITRATIO = [
    '' => 1.0,
    // default to points
    'px' => 1.0,
    'pt' => 1.0,
    'points' => 1.0,
    'millimeters' => 2.83464566929134,
    // (72 / 25.4)
    'mm' => 2.83464566929134,
    // (72 / 25.4)
    'centimeters' => 28.3464566929134,
    // (72 / 2.54)
// … truncated, see source

Source: src/Format.php:42

Methods

convertPoints()

Convert Points to another unit.

public convertPoints(float $points, string|Unit $unit, int $dec = 6): float

Parameters:

  • $points (float): Value to convert.
  • $unit (string|Unit): Name of the unit to convert to, or a Unit enum case.
  • $dec (int): Number of decimals to return.

Returns: float

Throws:

Source: src/Format.php:585

getPageFormatSize()

Get page dimensions.

public getPageFormatSize(
    string $format,
    string|Orientation $orientation = '',
    string|Unit $unit = '',
    int $dec = 6
): array{0: float, 1: float, 2: string}

Parameters:

  • $format (string): The page format name.
  • $orientation (string|Orientation): Page orientation (‘P’ portrait; ‘L’ landscape; ’’ default) or enum case.
  • $unit (string|Unit): Unit name (default points) or Unit enum case.
  • $dec (int): Number of decimals to return.

Returns: array{0: float, 1: float, 2: string}: Page width, height and orientation in specified unit.

Throws:

Source: src/Format.php:492

getPageOrientation()

Returns the page orientation.

public getPageOrientation(float $width, float $height): string

Parameters:

  • $width (float): Page width.
  • $height (float): Page height.

Returns: string: page orientation ‘P’ or ‘L’.

Source: src/Format.php:545

getPageOrientedSize()

Returns the page dimensions oriented as specified.

public getPageOrientedSize(
    float $width,
    float $height,
    string|Orientation $orientation = ''
): array{0: float, 1: float, 2: string}

Parameters:

  • $width (float): Page width.
  • $height (float): Page height.
  • $orientation (string|Orientation): Page orientation (‘P’ portrait; ‘L’ landscape; ’’ default) or enum case.

Returns: array{0: float, 1: float, 2: string}: Page width, height in points and orientation.

Source: src/Format.php:519

getUnitRatio()

Get the unit ratio for the specified unit of measure.

public getUnitRatio(string|Unit $unit): float

Parameters:

  • $unit (string|Unit): Name of the unit of measure, or a Unit enum case.

Returns: float

Throws:

Source: src/Format.php:561