Skip to content
Advertisement

I want to convert pdf to text. but it gives me error. why spatie/pdf-to-text is showing error?

my code

<?php 
require_once 'vendor/autoload.php';

use SpatiePdfToTextPdf;

echo Pdf::getText('simple.pdf');

error message

Fatal error: Uncaught SpatiePdfToTextExceptionsCouldNotExtractText: The command “”/usr/bin/pdftotext” simple.pdf -” failed. Exit Code: 1(General error) Working directory: C:xampphtdocspdf Output: ================ Error Output: ================ The system cannot find the path specified. in C:xampphtdocspdfvendorspatiepdf-to-textsrcPdf.php:73 Stack trace: #0 C:xampphtdocspdfvendorspatiepdf-to-textsrcPdf.php(84): SpatiePdfToTextPdf->text() #1 C:xampphtdocspdfindex.php(7): SpatiePdfToTextPdf::getText(‘simple.pdf’) #2 {main} thrown in C:xampphtdocspdfvendorspatiepdf-to-textsrcPdf.php on line 73

Advertisement

Answer

pdftext is a .exe file located in your system. Find the path of this file and
then put path like this and pass it to getText method like this

$path = 'c:/Program Files/Git/mingw64/bin/pdftotext';
echo Pdf::getText('simple.pdf', $path);

I hope it’ll help you

Note: $path this should be your path of pdftext.exe file

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement