Help with php_printer.dll

Asked

Viewed 1,290 times

1

Use PHP 5.5.12 and downloaded the compatible dll version and when opening the page nothing happens and also no error appears. I restarted Wamp and added the corresponding lines in php.ini

php.ini

 printer.default_printer=PHP_INI_ALL
 extension=php_printer.dll

print_coupon.php

<?php

 $printer_name = "Daruma D800"; 
 $handle = printer_open($printer_name);
 printer_start_doc($handle, "Cupom Teste");
 printer_start_page($handle);
 $font = printer_create_font("Arial", 100, 100, 400, false, false, false, 0);
 printer_select_font($handle, $font);
 printer_draw_text($handle, 'Teste de Cupom.', 100, 400);
 printer_delete_font($font);
 printer_end_page($handle);
 printer_end_doc($handle);
 printer_close($handle);
 ?>
  • Want to print on Server or browser?

  • @Guilhermenascimento server and client are on the same machine.

  • If they are on the same machine, you could not solve this with a PDF or HTML generator yourself and then window.print on the page? Just out of curiosity I’m asking, anyway I’m trying to download the compatible dll to my machine to test and see if I can detect the error.

  • 1

    @Guilhermenascimento is actually a nontax coupon type PDV system so I found it more productive to print directly on the printer without confirmation. if you know another way to print without confirmation will be welcome

  • Please check this answer https://answall.com/questions/195301/listar-impresras-na-rede-com-php/195376#195376 I believe you can help, it addresses both installation and use.

1 answer

1


The php_printer extension is the standard way to get the printers connected to the server. But it will not identify network printers that are not configured on the server because it does not allow discovery.

If even after installing the extension you could not try to follow these steps:

Getting printers without extension, using command line only in windows:

When PHP alone cannot, we can use some command-line interface, be it a java or python script or even a php script running with an older php. The technique is to use a command line and handle the result string.

<?php
//Função para tratar o retorno 
function getPrinterProperty($key){
    $str = shell_exec('wmic printer get '.$key.' /value');

    $keyname = "$key=";
    $validValues = [];
    $fragments = explode(PHP_EOL,$str);
    foreach($fragments as $fragment){
        if($fragment == ""){
            continue;
        }
        if (preg_match('/('.$keyname.')/i', $fragment)) {
            array_push($validValues,str_replace($keyname,"",$fragment));
        }
    }
    return $validValues;
}
//Esplanação dos commandos:
// wmic /node:SERVER1 printer list status // Lista status das impressoras de um servidor remoto
// wmic printer list status // Lista status das impressoras  do servidor local
// wmic printer get // Obtem todas as propriedades da impressoa
// wmic printer get <propriedade> /value //Lista uma propriedade no formato chave=valor do servidor remoto
// wmic printer get <propriedade> /value //Lista uma propriedade no formato chave=valor do servidor local

//Obtém algumas propriedades, nesse caso vou pegar só algumas
$Name = getPrinterProperty("Name");
$Description =  getPrinterProperty("Description");
$Network = getPrinterProperty("Network");
$Local = getPrinterProperty("Local");
$PortName = getPrinterProperty("PortName");
$Default = getPrinterProperty("Default");
$Comment = getPrinterProperty("Comment");

$Printers = [];
foreach($Name as $i => $n){
    $Printers[$i] = (object)[
        "name" => $n,
        "description" => $Description[$i],
        "Portname" => $PortName[$i],
        "isDefault" =>($Default[$i] == "TRUE")? true : false,
        "isNetwork" => ($Network[$i] == "TRUE")? true : false,
        "isLocal" =>($Local[$i] == "TRUE")? true : false,
        "Comment" => $Comment[$i],
    ];
}

var_dump($Printers);

array(7) {
  [0]=>
  object(stdClass)#1 (7) {
    ["name"]=>
    string(29) "Microsoft XPS Document Writer"
    ["description"]=>
    string(0) ""
    ["Portname"]=>
    string(11) "PORTPROMPT:"
    ["isDefault"]=>
    bool(false)
    ["isNetwork"]=>
    bool(false)
    ["isLocal"]=>
    bool(true)
    ["Comment"]=>
    string(0) ""
  }
  [1]=>
  object(stdClass)#2 (7) {
    ["name"]=>
    string(22) "Microsoft Print to PDF"
    ["description"]=>
    string(0) ""
    ["Portname"]=>
    string(11) "PORTPROMPT:"
    ["isDefault"]=>
    bool(false)
    ["isNetwork"]=>
    bool(false)
    ["isLocal"]=>
    bool(true)
    ["Comment"]=>
    string(0) ""
  }
  [2]=>
  object(stdClass)#3 (7) {
    ["name"]=>
    string(32) "HPC4C962 (HP Officejet Pro 8600)"
    ["description"]=>
    string(0) ""
    ["Portname"]=>
    string(45) "WSD-5277c4df-fd03-46fb-a957-1d8a0fd65b01.003c"
    ["isDefault"]=>
    bool(true)
    ["isNetwork"]=>
    bool(false)
    ["isLocal"]=>
    bool(true)
    ["Comment"]=>
    string(30) "This is a web services printer"
  }
  [3]=>
  object(stdClass)#4 (7) {
    ["name"]=>
    string(29) "HP Officejet Pro L7600 Series"
    ["description"]=>
    string(0) ""
    ["Portname"]=>
    string(12) "192.168.1.22"
    ["isDefault"]=>
    bool(false)
    ["isNetwork"]=>
    bool(false)
    ["isLocal"]=>
    bool(true)
    ["Comment"]=>
    string(0) ""
  }
  [4]=>
  object(stdClass)#5 (7) {
    ["name"]=>
    string(24) "Foxit Reader PDF Printer"
    ["description"]=>
    string(0) ""
    ["Portname"]=>
    string(13) "FOXIT_Reader:"
    ["isDefault"]=>
    bool(false)
    ["isNetwork"]=>
    bool(false)
    ["isLocal"]=>
    bool(true)
    ["Comment"]=>
    string(0) ""
  }
  [5]=>
  object(stdClass)#6 (7) {
    ["name"]=>
    string(3) "Fax"
    ["description"]=>
    string(0) ""
    ["Portname"]=>
    string(7) "SHRFAX:"
    ["isDefault"]=>
    bool(false)
    ["isNetwork"]=>
    bool(false)
    ["isLocal"]=>
    bool(true)
    ["Comment"]=>
    string(0) ""
  }
  [6]=>
  object(stdClass)#7 (7) {
    ["name"]=>
    string(26) "Enviar para o OneNote 2013"
    ["description"]=>
    string(0) ""
    ["Portname"]=>
    string(4) "nul:"
    ["isDefault"]=>
    bool(false)
    ["isNetwork"]=>
    bool(false)
    ["isLocal"]=>
    bool(true)
    ["Comment"]=>
    string(0) ""
  }
}

You will now have the list of printers installed on the system, so you can use an application that allows you to run via command line, such as the Foxit Reader and use the following command:

<?php 

shell_exec('FoxitReader /t C:/Temp/file.txt "'.$Printers[0]->name.'"');

These procedures were removed from the reply List network printers with PHP I believe I can help you.

  • 1

    While this link may answer the question, it is best to include the essential parts of the answer here and provide the link for reference. Replies per link only can be invalidated if the page with the link is changed. - Of Revision

Browser other questions tagged

You are not signed in. Login or sign up in order to post.