FPDF/FPDI Error: Fatal error: Class 'setasign\Fpdi\FpdfTpl' not found in

FPDF/FPDI Error: Fatal error: Class 'setasign\Fpdi\FpdfTpl' not found in

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

FPDF/FPDI Error: Fatal error: Class 'setasign\Fpdi\FpdfTpl' not found in

You are encountering a classic autoloading failure when integrating FPDI with legacy FPDF classes. The error message Fatal error: Class 'setasign\Fpdi\FpdfTpl' not found indicates that the PHP runtime cannot locate the FpdfTpl class definition when your script attempts to instantiate Fpdi.

Looking at the code snippet provided, the issue lies in how you are loading the FPDI library. You have placed the FPDI source files in a directory structure (fpdi/src/) and attempted to load them using explicit require_once statements:

require_once('fpdi/src/fpdi.php');
require_once('fpdi/src/FpdfTpl.php');

The error occurs because the file Fpdi.php (line 27) attempts to extend FpdfTpl. However, standard PHP does not automatically know where to find the class if it is not referenced via an autoloader or if the specific include path is incorrect. In the provided snippet, you are including fpdi/src/FpdfTpl.php directly after fpdi/src/fpdi.php. This order of operations suggests a misunderstanding of how FPDI's namespace structure maps to your file system.

In modern versions of FPDI (version 2.0 and above), the library utilizes the PSR-4 autoloading standard. The source code you pasted shows:

namespace setasign\Fpdi;

// ...
class Fpdi extends FpdfTpl { }

This class definition resides within a specific file structure relative to the namespace. If you are manually including files, the path fpdi/src/FpdfTpl.php likely does not correspond to the actual physical location of the file inside the FPDI package you downloaded. The src directory usually contains the main entry point (fpdi.php), but the class FpdfTpl might be defined in a subdirectory like src/fpdf_tpl.php (lowercase) or within a specific subfolder structure depending on the version of the library you have extracted.

The most robust solution is to stop manually requiring individual files and instead rely on an autoloader. If you are not using Composer, you must ensure that your require_once statement points to the correct file path where the class is actually defined. Check the directory listing of your fpdi/src/ folder. The file containing the FpdfTpl class definition might be named fpdf_tpl.php rather than FpdfTpl.php. PHP class names are case-sensitive in some contexts, and file names must match exactly if you are using direct includes without an autoloader.

If you switch to using Composer, which is the recommended approach for FPDI, you can resolve this by running:

composer require setasign/fpdi

Once installed, your PHP files will automatically load the setasign\Fpdi namespace and its dependencies without needing explicit require_once statements for every file. This eliminates path ambiguity entirely. You would then simply instantiate the class as usual:

use setasign\Fpdi\TcpdfFpdi; // or Fpdi depending on your driver choice

$pdf = new TcpdfFpdi();

However, if you must stick with the legacy manual loading approach shown in your script, verify that fpdi/src/FpdfTpl.php actually exists. If it does not exist at that path, the file containing the class definition is likely named differently or located in a subdirectory. The error occurs because the PHP engine executes fpdi/src/fpdi.php, which references FpdfTpl, but the subsequent line require_once('fpdi/src/FpdfTpl.php') fails to find the file or the file does not contain the expected class definition due to a namespace mismatch.

Additionally, note that your code mixes legacy FPDF syntax (e.g., $this->SetFont) with FPDI extensions. Ensure that the parent class FpdfTpl is correctly instantiated and that any custom rotation logic you added in PDF_Rotate does not interfere with the initialization sequence required by FPDI. The use setasign\Fpdi\FpdfTpl; line commented out in your first snippet suggests that perhaps an autoloader was disabled or ignored, forcing a manual include that turned out to be incorrect.

To fix this without Composer, locate the exact file path where the FpdfTpl class is defined in your FPDI source directory and update your require_once statement to match that exact path. Ensure the namespace used in the file matches the usage in your script (setasign\Fpdi). If the file structure has changed since you downloaded the library, updating to the latest stable version via Composer is the most reliable way to ensure compatibility between FPDF and FPDI.

Our network