mike42 / escpos-php

PHP library for printing to ESC/POS-compatible thermal and impact printers
Other
2.55k stars 863 forks source link

Error when using loadPDF function with WindowsPrintConnector #1351

Open brunogambeta opened 1 month ago

brunogambeta commented 1 month ago

Good morning everyone. I'm trying to use the ImagickEscposImage::loadPdf function, but it's returning an Exception: Below is my code snippet and the error it's presenting.

$item = Nfce::findOrFail($id); $empresa = $item->empresa; $nomeImpressora = "POS-80-Series"; $connector = new WindowsPrintConnector($nomeImpressora); $printer = new Printer($connector); $saveDirectory = 'danfce/' . $empresa->cpf_cnpj;

   $nomeArquivo = $item->id;
    if ($item->chave) {
        $nomeArquivo = $item->chave;
    }

    $pdf = public_path($saveDirectory . '/'. $nomeArquivo . '.pdf');
    try {
        $pages = ImagickEscposImage::loadPdf($pdf,260);
        foreach ($pages as $page) {
            $printer -> graphics($page);
        }
        $printer -> cut();
    } catch (Exception $e) {
        /*
         * loadPdf() throws exceptions if files or not found, or you don't have the
         * imagick extension to read PDF's
         */
        echo $e -> getMessage() . "\n";
    } finally {
        $printer -> close();
    }

Error: FailedToExecuteCommand `"gs" -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r2x2" -dPrinted=false "-sOutputFile=C:/Windows/TEMP/magick-xk9qK0jkSZxZhpPP60nDfPUHc1JHqjKv%d" "-fC:/Windows/TEMP/magick-f_4PYAkoQKYWA4qgbZhJaqdPCnhJo9dy" "-fC:/Windows/TEMP/magick-hTXMzE5m8BJhdQZdixl3kQmLz6PuqNlD"' (O sistema n�o pode encontrar o arquivo especificado. ) @ error/delegate.c/ExternalDelegateCommand/516

I'm using php 8.2.12.

If anyone can help me, I would appreciate it; Thank you