How to use plugin classes in config?

Hey guys!

I’ve tried to implement Asika’s PHP pdf2text class to help me index pdf contents for an algolia search.
This is the class that I’ve tried to make use of:

I’ve simply made a folder for it in the plugins folder and added an index.php with the following:

<?php

include __DIR__ . '/src/Pdf2text.php';

If I use it in the templates like this it works just fine:

<?php
$files = [];
$reader = new \Asika\Pdf2text;
foreach($page->files() as $file){

	$output = "";
	try{
		$output = $reader->decode($file->url());
	} 
	catch (Exception $e) {
		return $e;
	}
	
	if($file->type() == "document"){
		$filetoindex = [
				"url" => $file->url(),
				"title" => $file->filename(),
				"extension" => $file->extension(),
				"content" => $output,
			];
		$files[] = $filetoindex;
		}
}
dump($files);
?>

I get the file contents as I am supposed to.

But when trying to set up the search within the config files, it seems like I can’t use the class.
Indexing goes through without errors but the content attribute for the files turns out to be an empty string.

This is how it is set up in my config/search.php:

"files" => function($page){ 
                        $files = [];
                        $reader = new \Asika\Pdf2text;
                        foreach($page->files() as $file){

                            $output = "";
                            try{
                                $output = $reader->decode($file->url());
                            } 
                            catch (Exception $e) {
                                return $e;
                            }
                            
                            if($file->type() == "document"){
                                $filetoindex = [
                                        "url" => $file->url(),
                                        "title" => $file->filename(),
                                        "extension" => $file->extension(),
                                        "content" => $output,
                                    ];
                                $files[] = $filetoindex;
                                }
                        }
                        return $files;
                },

Everything except for the content is getting indexed fine, so it seems I am doing something wrong with the class / plugin.