</div> </div> <?php $content = ob_get_contents(); ob_clean(); ?> <?php $currentFileName = basename($_SERVER['PHP_SELF']); $currentFolder = substr($_SERVER['REQUEST_URI'], 0, strlen($_SERVER['REQUEST_URI']) - strlen($currentFileName)); //echo "Current folder: ".$currentFolder."<br>"; //Specify the ABSOLUTE URL to the php file that will create the ClientPrintJob object echo WebClientPrint::createScript(Utils::getRoot() . $currentFolder . 'DemoPrintFileProcess.php'); ?> <script type="text/javascript"> $("#ddlFileType").change(function () { var s = $("#ddlFileType option:selected").text(); if (s == 'DOC') $("#ifPreview").attr("src", "http://docs.google.com/gview?url=http://webclientprintphp.azurewebsites.net/files/LoremIpsum.doc&embedded=true"); if (s == 'PDF') $("#ifPreview").attr("src", "http://docs.google.com/gview?url=http://webclientprintphp.azurewebsites.net/files/LoremIpsum.pdf&embedded=true"); if (s == 'TXT') $("#ifPreview").attr("src", "http://docs.google.com/gview?url=http://webclientprintphp.azurewebsites.net/files/LoremIpsum.txt&embedded=true"); if (s == 'TIF') $("#ifPreview").attr("src", "http://docs.google.com/gview?url=http://webclientprintphp.azurewebsites.net/files/patent2pages.tif&embedded=true"); if (s == 'XLS')
$urlParts = parse_url($_SERVER['REQUEST_URI']); $rawQuery = $urlParts['query']; if (isset($rawQuery)) { if ($rawQuery[WebClientPrint::CLIENT_PRINT_JOB]) { parse_str($rawQuery, $qs); $useDefaultPrinter = $qs['useDefaultPrinter'] === 'checked'; $printerName = urldecode($qs['printerName']); $pr = new Printer(); $students = $pr->get_print_job(); $students_arr = explode(",", $students); if (count($students_arr) > 0) { foreach ($students_arr as $studentid) { $cert_path = $_SERVER['DOCUMENT_ROOT'] . "/lms/custom/certificates/{$studentid}/certificate.jpg"; $fileName = uniqid() . '.' . $cert_path; $filePath = $cert_path; if (!Utils::isNullOrEmptyString($filePath)) { //Create a ClientPrintJob obj that will be processed at the client side by the WCPP $cpj = new ClientPrintJob(); $cpj->printFile = new PrintFile($filePath, $fileName, null); if ($useDefaultPrinter || $printerName === 'null') { $cpj->clientPrinter = new DefaultPrinter(); } else { $cpj->clientPrinter = new InstalledPrinter($printerName); } // end else //Send ClientPrintJob back to the client ob_clean(); echo $cpj->sendToClient(); } // end if !Utils::isNullOrEmptyString($filePath) }
fwrite($handle, $data); fclose($handle); } } else { if ($_SERVER['REQUEST_METHOD'] === 'GET') { // Generate ClientPrintJob? only if clientPrint param is in the query string $urlParts = parse_url($_SERVER['REQUEST_URI']); $rawQuery = $urlParts['query']; if (isset($rawQuery)) { if ($rawQuery[WebClientPrint::CLIENT_PRINT_JOB]) { //we need the session id to look for the ini file containing printer settings & commands parse_str($rawQuery, $qs); $sid = $qs['sid']; if (isset($sid)) { // try to get ini file from cache $cacheFileName = (Utils::strEndsWith(WebClientPrint::$wcpCacheFolder, '/') ? WebClientPrint::$wcpCacheFolder : WebClientPrint::$wcpCacheFolder . '/') . $sid . '.ini'; if (file_exists($cacheFileName)) { $print_info = parse_ini_file($cacheFileName); //remove file from cache unlink($cacheFileName); // create print job... if (isset($print_info)) { //get printer commands $printerCommands = base64_decode($print_info['printerCommands']); //get printer settings $printerTypeId = base64_decode($print_info['pid']); $clientPrinter = NULL; if ($printerTypeId == '0') { $clientPrinter = new DefaultPrinter(); } else { if ($printerTypeId == '1') {
/** * Sends this ClientPrintJob object to the client for further processing. * The ClientPrintJob object will be processed by the WCPP installed at the client machine. * @return string A string representing a ClientPrintJob object. */ public function sendToClient() { header('Content-type: application/octet-stream'); $cpjHeader = chr(99) . chr(112) . chr(106) . chr(2); $buffer = ''; if (!Utils::isNullOrEmptyString($this->printerCommands)) { if ($this->formatHexValues) { $buffer = Utils::formatHexValues($this->printerCommands); } else { $buffer = $this->printerCommands; } } else { if (isset($this->printFile)) { $buffer = $this->printFile->serialize(); } else { if (isset($this->printFileGroup)) { $buffer = 'wcpPFG:'; $zip = new ZipArchive(); $cacheFileName = (Utils::strEndsWith(WebClientPrint::$wcpCacheFolder, '/') ? WebClientPrint::$wcpCacheFolder : WebClientPrint::$wcpCacheFolder . '/') . 'PFG' . uniqid() . '.zip'; $res = $zip->open($cacheFileName, ZipArchive::CREATE); if ($res === TRUE) { foreach ($this->printFileGroup as $printFile) { $zip->addFromString($printFile->fileName, $printFile->getFileContent()); } $zip->close(); $handle = fopen($cacheFileName, 'rb'); $buffer .= fread($handle, filesize($cacheFileName)); fclose($handle); unlink($cacheFileName); } else { $buffer = 'Creating PrintFileGroup failed. Cannot create zip file.'; } } } } $arrIdx1 = Utils::intToArray(strlen($buffer)); if (!isset($this->clientPrinter)) { $this->clientPrinter = new UserSelectedPrinter(); } $buffer .= $this->clientPrinter->serialize(); $arrIdx2 = Utils::intToArray(strlen($buffer)); $lo = ''; if (Utils::isNullOrEmptyString(WebClientPrint::$licenseOwner)) { $lo = substr(uniqid(), 0, 8); } else { $lo = WebClientPrint::$licenseOwner; } $lk = ''; if (Utils::isNullOrEmptyString(WebClientPrint::$licenseKey)) { $lk = substr(uniqid(), 0, 8); } else { $lk = WebClientPrint::$licenseKey; } $buffer .= $lo . chr(124) . $lk; return $cpjHeader . $arrIdx1 . $arrIdx2 . $buffer; }