$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>"; /* printing a string */ echo "<br /><br /><br /> TEST 3<br />"; echo "OPERATION " . $j++ . "<br />"; $ipp->setCopies(2); $ipp->setJobName("PHP Test: Text String", true); // default is false: number is automagically appended $ipp->setData("This is a text string"); echo "Print String: " . $ipp->printJob() . "</br />"; echo "Job Attributes:<pre>\n"; print_r($ipp->job_attributes); echo "\n</pre>\n"; // for restart job operation (later) $first_job = $ipp->last_job; /* printing a text file */ echo "<br /><br /><br /> TEST 4<br />"; // HINT: you _must_ supply a charset or set output as raw text // note that mimeMediaType is resetted to octet-stream after each call of printJob (this is a feature). echo "OPERATION " . $j++ . "<br />"; $ipp->setCharset('us-ascii');
/** * 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; }
/** * 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 ''; }