<?php

require_once __DIR__ . '/../vendor/autoload.php';

use Smalot\PdfParser\Parser;

class PDFProcessor
{

    private Parser $parser;

    public function __construct()
    {

        $this->parser = new Parser();

    }

    /**
     * Read PDF
     */
    public function load(string $pdf): array
    {

        if (!file_exists($pdf)) {

            return [

                "success" => false,
                "message" => "PDF not found."

            ];

        }

        try {

            $document = $this->parser->parseFile($pdf);

            return [

                "success" => true,
                "document" => $document

            ];

        } catch (Exception $e) {

            return [

                "success" => false,
                "message" => $e->getMessage()

            ];

        }

    }

}