Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

   1  <?php
   2  /**
   3   * This file is part of FPDI
   4   *
   5   * @package   setasign\Fpdi
   6   * @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
   7   * @license   http://opensource.org/licenses/mit-license The MIT License
   8   */
   9  
  10  namespace setasign\Fpdi\Tfpdf;
  11  
  12  use setasign\Fpdi\FpdfTplTrait;
  13  
  14  /**
  15   * Class FpdfTpl
  16   *
  17   * We need to change some access levels and implement the setPageFormat() method to bring back compatibility to tFPDF.
  18   *
  19   * @package setasign\Fpdi\Tfpdf
  20   */
  21  class FpdfTpl extends \tFPDF
  22  {
  23      use FpdfTplTrait {
  24          _putimages as _protectedPutimages;
  25          _putxobjectdict as _protectedPutxobjectdict;
  26      }
  27  
  28      /**
  29       * Make the method public as in tFPDF.
  30       */
  31      public function _putimages()
  32      {
  33          $this->_protectedPutimages();
  34      }
  35  
  36      /**
  37       * Make the method public as in tFPDF.
  38       */
  39      public function _putxobjectdict()
  40      {
  41          $this->_protectedPutxobjectdict();
  42      }
  43  
  44      /**
  45       * Set the page format of the current page.
  46       *
  47       * @param array $size An array with two values defining the size.
  48       * @param string $orientation "L" for landscape, "P" for portrait.
  49       * @throws \BadMethodCallException
  50       */
  51      public function setPageFormat($size, $orientation)
  52      {
  53          if ($this->currentTemplateId !== null) {
  54              throw new \BadMethodCallException('The page format cannot be changed when writing to a template.');
  55          }
  56  
  57          if (!\in_array($orientation, ['P', 'L'], true)) {
  58              throw new \InvalidArgumentException(\sprintf(
  59                  'Invalid page orientation "%s"! Only "P" and "L" are allowed!',
  60                  $orientation
  61              ));
  62          }
  63  
  64          $size = $this->_getpagesize($size);
  65  
  66          if ($orientation != $this->CurOrientation
  67              || $size[0] != $this->CurPageSize[0]
  68              || $size[1] != $this->CurPageSize[1]
  69          ) {
  70              // New size or orientation
  71              if ($orientation === 'P') {
  72                  $this->w = $size[0];
  73                  $this->h = $size[1];
  74              } else {
  75                  $this->w = $size[1];
  76                  $this->h = $size[0];
  77              }
  78              $this->wPt = $this->w * $this->k;
  79              $this->hPt = $this->h * $this->k;
  80              $this->PageBreakTrigger = $this->h - $this->bMargin;
  81              $this->CurOrientation = $orientation;
  82              $this->CurPageSize = $size;
  83  
  84              $this->PageSizes[$this->page] = array($this->wPt, $this->hPt);
  85          }
  86      }
  87  
  88      /**
  89       * @inheritdoc
  90       */
  91      protected function _put($s, $newLine = true)
  92      {
  93          if ($newLine) {
  94              $this->buffer .= $s . "\n";
  95          } else {
  96              $this->buffer .= $s;
  97          }
  98      }
  99  }