Пример #1
0
 /**
  *  Print selected file
  *
  * @param   string      $file       file
  * @param   string      $module     module
  * @param   string      $subdir     subdirectory of document like for expedition subdir is sendings
  *
  * @return  int                     0 if OK, >0 if KO
  */
 function print_file($file, $module, $subdir = '')
 {
     global $conf, $user, $db;
     $error = 0;
     include_once DOL_DOCUMENT_ROOT . '/includes/printipp/CupsPrintIPP.php';
     $ipp = new CupsPrintIPP();
     $ipp->setLog(DOL_DATA_ROOT . '/dolibarr_printipp.log', 'file', 3);
     // logging very verbose
     $ipp->setHost($this->host);
     $ipp->setPort($this->port);
     $ipp->setJobName($file, true);
     $ipp->setUserName($this->userid);
     if (!empty($this->user)) {
         $ipp->setAuthentication($this->user, $this->password);
     }
     // select printer uri for module order, propal,...
     $sql = "SELECT rowid,printer_id,copy FROM " . MAIN_DB_PREFIX . "printing WHERE module = '" . $module . "' AND driver = 'printipp' AND userid = " . $user->id;
     $result = $db->query($sql);
     if ($result) {
         $obj = $this->db->fetch_object($result);
         if ($obj) {
             dol_syslog("Found a default printer for user " . $user->id . " = " . $obj->printer_id);
             $ipp->setPrinterURI($obj->printer_id);
         } else {
             if (!empty($conf->global->PRINTIPP_URI_DEFAULT)) {
                 dol_syslog("Will use default printer conf->global->PRINTIPP_URI_DEFAULT = " . $conf->global->PRINTIPP_URI_DEFAULT);
                 $ipp->setPrinterURI($conf->global->PRINTIPP_URI_DEFAULT);
             } else {
                 $this->errors[] = 'NoDefaultPrinterDefined';
                 $error++;
                 return $error;
             }
         }
     } else {
         dol_print_error($db);
     }
     // Set number of copy
     $ipp->setCopies($obj->copy);
     $fileprint = $conf->{$module}->dir_output;
     if ($subdir != '') {
         $fileprint .= '/' . $subdir;
     }
     $fileprint .= '/' . $file;
     $ipp->setData($fileprint);
     try {
         $ipp->printJob();
     } catch (Exception $e) {
         $this->errors[] = $e->getMessage();
         $error++;
     }
     if ($error == 0) {
         $this->errors[] = 'PRINTIPP: Job added';
     }
     return $error;
 }
Пример #2
0
$ipp->setCharset('utf-8');
$ipp->setLanguage($language);
$ipp->setAuthentication($user, $password);
// username & password
$j = 0;
$test = 1;
/* printing a large file */
echo "<br /><br /><br />TEST 1<br />";
echo "OPERATION  " . $j++ . "<br />";
$ipp->setAttribute("printer-resolution", "1440x720dpi");
$ipp->setAttribute("job-billing", "Thomas");
$ipp->setAttribute("print-quality", "high");
$ipp->setAttribute("scaling", 100);
//$ipp->setCopies(2);
$ipp->setData('./photo.jpg');
$ipp->setJobName('photo.jpg', true);
echo "Printing a large file: " . $ipp->PrintJob() . "<br />";
printf('$ipp->status[0] = %s <br /><br />', $ipp->status[0]);
$ipp->unsetAttribute("job-billing");
$ipp->setJobName();
$ipp->setAttribute("scaling", "");
/* getting printer's attributes */
echo "<br /><br /><br />TEST 2<br />";
echo "OPERATION  " . $j++ . "<br />";
echo "Getting Printer's attributes: " . $ipp->getPrinterAttributes() . "<br />";
printf('$ipp->status[%s] = %s <br /><br />', count($ipp->status) - 1, $ipp->status[count($ipp->status) - 1]);
$timestamp = $ipp->printer_attributes->printer_up_time->_value0;
echo "Printer up-time: " . date('Y-m-d H:i:s', $timestamp) . "<br />";
echo "Printer's attributes :<pre>\n";
print_r($ipp->printer_attributes);
echo "</pre>";
Пример #3
0
 /**
  *  Print selected file
  *
  * @param   string      $file       file
  * @param   string      $module     module
  *
  * @return 	string					'' if OK, Error message if KO
  */
 function print_file($file, $module)
 {
     global $conf, $db;
     include_once DOL_DOCUMENT_ROOT . '/includes/printipp/CupsPrintIPP.php';
     $ipp = new CupsPrintIPP();
     $ipp->setLog(DOL_DATA_ROOT . '/dolibarr_printipp.log', 'file', 3);
     // logging very verbose
     $ipp->setHost($this->host);
     $ipp->setPort($this->port);
     $ipp->setJobName($file, true);
     $ipp->setUserName($this->userid);
     if (!empty($this->user)) {
         $ipp->setAuthentication($this->user, $this->password);
     }
     // select printer uri for module order, propal,...
     $sql = 'SELECT rowid,printer_uri,copy FROM ' . MAIN_DB_PREFIX . 'printer_ipp WHERE module="' . $module . '"';
     $result = $this->db->query($sql);
     if ($result) {
         $obj = $this->db->fetch_object($result);
         if ($obj) {
             $ipp->setPrinterURI($obj->printer_uri);
         } else {
             if (!empty($conf->global->PRINTIPP_URI_DEFAULT)) {
                 $ipp->setPrinterURI($conf->global->PRINTIPP_URI_DEFAULT);
             } else {
                 return 'NoDefaultPrinterDefined';
             }
         }
     }
     // Set number of copy
     $ipp->setCopies($obj->copy);
     $ipp->setData(DOL_DATA_ROOT . '/' . $module . '/' . $file);
     $ipp->printJob();
     return '';
 }