title: Fatal error: Class 'setasign\Fpdi\FpdfTpl' not found in C:\xampp\htdocs\pdf\fpdi2\src\Fpdi.php
body: <p>i am currently using this code for the data.php but I get this error </p>
  
  <pre><code>Fatal error: Class 'setasign\Fpdi\FpdfTpl' not found 
  </code></pre>
  
  <p>and it says the problem originates in C:\xampp\htdocs\pdf\fpdi2\src\Fpdi.php` on line 24.</p>
  
  <p>I kept adding <code>the setasign\Fpdi\FpdfTpl</code> to that specific line and tried reloading it but no response and it results in the same error</p>
  
  <p><code>fpdi.php</code></p>
  
  <pre><code>&lt;?php
  /**
   * This file is part of FPDI
   *
   * @package   setasign\Fpdi
   * @copyright Copyright (c) 2018 Setasign - Jan Slabon (https://www.setasign.com)
   * @license   http://opensource.org/licenses/mit-license The MIT License
    */
  
  namespace setasign\Fpdi;
  
  use setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException;
  use setasign\Fpdi\PdfParser\PdfParserException;
  use setasign\Fpdi\PdfParser\Type\PdfIndirectObject;
  use setasign\Fpdi\PdfParser\Type\PdfNull;
  
  /**
   * Class Fpdi
   *
   * This class let you import pages of existing PDF documents into a reusable structure for FPDF.
   *
   * @package setasign\Fpdi
   */
  class Fpdi extends FpdfTpl
  { use \setasign\Fpdi\FpdfTpl;
      use FpdiTrait;
  
      /**
       * FPDI version
       *
       * @string
       */
      const VERSION = '2.1.1';
  
      /**
       * Draws an imported page or a template onto the page or another template.
       *
       * Omit one of the size parameters (width, height) to calculate the other one automatically in view to the aspect
       * ratio.
       *
       * @param mixed $tpl The template id
       * @param float|int|array $x The abscissa of upper-left corner. Alternatively you could use an assoc array
       *                           with the keys "x", "y", "width", "height", "adjustPageSize".
       * @param float|int $y The ordinate of upper-left corner.
       * @param float|int|null $width The width.
       * @param float|int|null $height The height.
       * @param bool $adjustPageSize
       * @return array The size
       * @see Fpdi::getTemplateSize()
       */
      public function useTemplate($tpl, $x = 0, $y = 0, $width = null, $height = null, $adjustPageSize = false)
      {
          if (isset($this-&gt;importedPages[$tpl])) {
              $size = $this-&gt;useImportedPage($tpl, $x, $y, $width, $height, $adjustPageSize);
              if ($this-&gt;currentTemplateId !== null) {
                  $this-&gt;templates[$this-&gt;currentTemplateId]['resources']['templates']['importedPages'][$tpl] = $tpl;
              }
              return $size;
          }
  
          return parent::useTemplate($tpl, $x, $y, $width, $height, $adjustPageSize);
      }
  
      /**
       * Get the size of an imported page or template.
       *
       * Omit one of the size parameters (width, height) to calculate the other one automatically in view to the aspect
       * ratio.
       *
       * @param mixed $tpl The template id
       * @param float|int|null $width The width.
       * @param float|int|null $height The height.
       * @return array|bool An array with following keys: width, height, 0 (=width), 1 (=height), orientation (L or P)
       */
      public function getTemplateSize($tpl, $width = null, $height = null)
      {
          $size = parent::getTemplateSize($tpl, $width, $height);
          if ($size === false) {
              return $this-&gt;getImportedPageSize($tpl, $width, $height);
          }
  
          return $size;
      }
  
      /**
       * @inheritdoc
       * @throws CrossReferenceException
       * @throws PdfParserException
       */
      protected function _putimages()
      {
          $this-&gt;currentReaderId = null;
          parent::_putimages();
  
          foreach ($this-&gt;importedPages as $key =&gt; $pageData) {
              $this-&gt;_newobj();
              $this-&gt;importedPages[$key]['objectNumber'] = $this-&gt;n;
              $this-&gt;currentReaderId = $pageData['readerId'];
              $this-&gt;writePdfType($pageData['stream']);
              $this-&gt;_put('endobj');
          }
  
          foreach (\array_keys($this-&gt;readers) as $readerId) {
              $parser = $this-&gt;getPdfReader($readerId)-&gt;getParser();
              $this-&gt;currentReaderId = $readerId;
  
              while (($objectNumber = \array_pop($this-&gt;objectsToCopy[$readerId])) !== null) {
                  try {
                      $object = $parser-&gt;getIndirectObject($objectNumber);
  
                  } catch (CrossReferenceException $e) {
                      if ($e-&gt;getCode() === CrossReferenceException::OBJECT_NOT_FOUND) {
                          $object = PdfIndirectObject::create($objectNumber, 0, new PdfNull());
                      } else {
                          throw $e;
                      }
                  }
  
                  $this-&gt;writePdfType($object);
              }
          }
  
          $this-&gt;currentReaderId = null;
      }
  
      /**
       * @inheritdoc
       */
      protected function _putxobjectdict()
      {
          foreach ($this-&gt;importedPages as $key =&gt; $pageData) {
              $this-&gt;_put('/' . $pageData['id'] . ' ' . $pageData['objectNumber'] . ' 0 R');
          }
  
          parent::_putxobjectdict();
      }
  
      /**
       * @inheritdoc
       */
      protected function _put($s, $newLine = true)
      {
          if ($newLine) {
              $this-&gt;buffer .= $s . "\n";
          } else {
              $this-&gt;buffer .= $s;
          }
      }
  }
  </code></pre>
  
  <p><code>data.php</code></p>
  
  <pre><code>     &lt;?php  
      use \setasign\Fpdi\Fpdi;
      use \setasign\Fpdi\PdfReader;
      use \setasign\Fpdi\FpdfTpl;
  
      require_once('fpdf\fpdf.php');
      require_once('fpdi2\src\Fpdi.php');
      require_once('fpdi2\src\FpdfTpl.php');
      require_once('fpdi2\src\autoload.php');
  
      // Original file with multiple pages 
      $fullPathToFile = "Grade 11.pdf";
  
      class PDF extends FPDI {
  
          var $_tplIdx;
  
          function Header() {
  
              global $fullPathToFile;
  
              if (is_null($this-&gt;_tplIdx)) {
  
                  // THIS IS WHERE YOU GET THE NUMBER OF PAGES
                  $this-&gt;numPages = $this-&gt;setSourceFile($fullPathToFile);
                  $this-&gt;_tplIdx = $this-&gt;importPage(1);
  
              }
              $this-&gt;useTemplate($this-&gt;_tplIdx, 0, 0,200);
  
          }
  
          function Footer() {}
  
      }
  
      // initiate PDF
      $pdf = new PDF();
  
      // add a page
      $pdf-&gt;AddPage();
  
  
      // The new content
      $pdf-&gt;SetFont("helvetica", "B", 25);
      $pdf-&gt;SetTextColor(255, 0, 0);
      $pdf-&gt;Text(40,120,"Sample Text over overlay");
  
      // THIS PUTS THE REMAINDER OF THE PAGES IN
      if($pdf-&gt;numPages&gt;1) {
          for($i=2;$i&lt;=$pdf-&gt;numPages;$i++) {
              //$pdf-&gt;endPage();
              $pdf-&gt;_tplIdx = $pdf-&gt;importPage($i);
              $pdf-&gt;AddPage();
          }
      }
  
      //show the PDF in page
      //$pdf-&gt;Output();
  
      // or Output the file as forced download
      $pdf-&gt;Output("sampleUpdated.pdf", 'D');
  </code></pre>
  
  <p>If someone could help me out on this, it would be a lifesaver for me.</p>