Horde_Pdf_Writer::__construct PHP Method

__construct() public method

It allows to set up the page format, the orientation and the units of measurement used in all the methods (except for the font sizes). Example: $pdf = new Horde_Pdf_Writer(array('orientation' => 'P', 'unit' => 'mm', 'format' => 'A4'));
public __construct ( array $params = [] )
$params array A hash with parameters for the created PDF object. Possible parameters are: - orientation - Default page orientation. Possible values are (case insensitive): - P or Portrait (default) - L or Landscape - unit - User measure units. Possible values values are: - pt: point - mm: millimeter (default) - cm: centimeter - in: inch A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit. - format - The format used for pages. It can be either one of the following values (case insensitive): - A3 - A4 (default) - A5 - Letter - Legal or a custom format in the form of a two-element array containing the width and the height (expressed in the unit given by the unit parameter).
    public function __construct($params = array())
    {
        /* Default parameters. */
        $defaults = array('orientation' => 'P', 'unit' => 'mm', 'format' => 'A4');
        $params = array_merge($defaults, $params);
        /* Scale factor. */
        if ($params['unit'] == 'pt') {
            $this->_scale = 1;
        } elseif ($params['unit'] == 'mm') {
            $this->_scale = 72 / 25.4;
        } elseif ($params['unit'] == 'cm') {
            $this->_scale = 72 / 2.54;
        } elseif ($params['unit'] == 'in') {
            $this->_scale = 72;
        } else {
            throw new Horde_Pdf_Exception(sprintf('Incorrect units: %s', $params['unit']));
        }
        /* Page format. */
        if (is_string($params['format'])) {
            $params['format'] = Horde_String::lower($params['format']);
            if ($params['format'] == 'a3') {
                $params['format'] = array(841.89, 1190.55);
            } elseif ($params['format'] == 'a4') {
                $params['format'] = array(595.28, 841.89);
            } elseif ($params['format'] == 'a5') {
                $params['format'] = array(420.94, 595.28);
            } elseif ($params['format'] == 'letter') {
                $params['format'] = array(612, 792);
            } elseif ($params['format'] == 'legal') {
                $params['format'] = array(612, 1008);
            } else {
                throw new Horde_Pdf_Exception(sprintf('Unknown page format: %s', $params['format']));
            }
            $this->fwPt = $params['format'][0];
            $this->fhPt = $params['format'][1];
        } else {
            $this->fwPt = $params['format'][0] * $this->_scale;
            $this->fhPt = $params['format'][1] * $this->_scale;
        }
        $this->fw = $this->fwPt / $this->_scale;
        $this->fh = $this->fhPt / $this->_scale;
        /* Page orientation. */
        $params['orientation'] = Horde_String::lower($params['orientation']);
        if ($params['orientation'] == 'p' || $params['orientation'] == 'portrait') {
            $this->_default_orientation = 'P';
            $this->wPt = $this->fwPt;
            $this->hPt = $this->fhPt;
        } elseif ($params['orientation'] == 'l' || $params['orientation'] == 'landscape') {
            $this->_default_orientation = 'L';
            $this->wPt = $this->fhPt;
            $this->hPt = $this->fwPt;
        } else {
            throw new Horde_Pdf_Exception(sprintf('Incorrect orientation: %s', $params['orientation']));
        }
        $this->_current_orientation = $this->_default_orientation;
        $this->w = $this->wPt / $this->_scale;
        $this->h = $this->hPt / $this->_scale;
        /* Page margins (1 cm) */
        $margin = 28.35 / $this->_scale;
        $this->setMargins($margin, $margin);
        /* Interior cell margin (1 mm) */
        $this->_cell_margin = $margin / 10;
        /* Line width (0.2 mm) */
        $this->_line_width = 0.5669999999999999 / $this->_scale;
        /* Automatic page break */
        $this->setAutoPageBreak(true, 2 * $margin);
        /* Full width display mode */
        $this->setDisplayMode('fullwidth');
        /* Compression */
        $this->setCompression(true);
    }