diff --git a/src/Exceptions/BinaryNotFoundException.php b/src/Exceptions/BinaryNotFoundException.php new file mode 100644 index 0000000..999feab --- /dev/null +++ b/src/Exceptions/BinaryNotFoundException.php @@ -0,0 +1,9 @@ +binPath = $binPath ?? '/usr/bin/pdftotext'; + $this->binPath = $binPath ?? $this->findPdfToText(); + } + + protected function findPdfToText(): string + { + $commonPaths = [ + '/usr/bin/pdftotext', // Common on Linux + '/usr/local/bin/pdftotext', // Common on Linux + '/opt/homebrew/bin/pdftotext', // Homebrew on macOS (Apple Silicon) + '/opt/local/bin/pdftotext', // MacPorts on macOS + '/usr/local/bin/pdftotext', // Homebrew on macOS (Intel) + ]; + + foreach ($commonPaths as $path) { + if (is_executable($path)) { + return $path; + } + } + + throw new BinaryNotFoundException("The required binary was not found or is not executable."); } public function setPdf(string $pdf): self