function pdfExport($psize = 'Letter', $notes = false, $printAttachments) { global $thisstaff; require_once INCLUDE_DIR . 'class.pdf.php'; if (!is_string($psize)) { if ($_SESSION['PAPER_SIZE']) { $psize = $_SESSION['PAPER_SIZE']; } elseif (!$thisstaff || !($psize = $thisstaff->getDefaultPaperSize())) { $psize = 'Letter'; } } $pdfConverterPath = INCLUDE_DIR . 'pdfConverter/'; $cmd = " find " . $pdfConverterPath . ' -type f -delete'; shell_exec($cmd); $name = 'Ticket.pdf'; $pdf = new Ticket2PDF($this, $psize, $notes); $pdf->Output($pdfConverterPath . $name, 'F'); $cmd = "chmod -R 777 " . $pdfConverterPath . $name; shell_exec($cmd); $pdf = new mPDF('c'); $pdf->allow_charset_conversion = true; // Set by default to TRUE $pdf->charset_in = 'windows-1252'; $pdf->SetImportUse(); $this->importPdfPages($pdf, $pdfConverterPath . $name); $attachmentOrder = 1; foreach ($printAttachments as $attachmentId) { if (!($f = AttachmentFile::lookup(intval($attachmentId)))) { break; } // $this->logErrors($f->getDownloadUrl()); // $this->logErrors("http://mailtest.spitzeco.dk/".$f->getDownloadUrl()); if ($fileData = $f->getData()) { // $this->logErrors(json_encode($file['data'])); $timestamp = date("Y-m-d_H"); $extension = pathinfo($f->getName(), PATHINFO_EXTENSION); // $this->logErrors("fileName ".$f->getName()); $stringName = preg_replace('/\\s+/', '', $f->getName()); // $tempName = $timestamp.basename($stringName, '.'.$extension); // give the file a temp name in case the file name contians some blank space and then the command would take effect $tempName = "tempFile" . $attachmentOrder; file_put_contents($pdfConverterPath . $tempName . "." . $extension, $fileData); $originalFileName = $pdfConverterPath . $tempName . "." . $extension; $formattedFile = $tempName . "formatted.pdf"; $cmd = "chmod -R 777 " . $pdfConverterPath . $tempName . "." . $extension; shell_exec($cmd); // this is a command for changing other format to pdf $cmd = 'export HOME=/tmp && /usr/bin/libreoffice5.0 --headless --convert-to pdf --outdir ' . $pdfConverterPath . " " . $pdfConverterPath . $tempName . "." . $extension; // $this->logErrors("2222222 ".$cmd); system($cmd); $cmd = "chmod -R 777 " . $pdfConverterPath . $tempName . ".pdf"; shell_exec($cmd); // this command is for making unformatted files become formatted $cmd = 'gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=' . $pdfConverterPath . $formattedFile . ' ' . $pdfConverterPath . $tempName . ".pdf"; shell_exec($cmd); $cmd = "chmod -R 777 " . $pdfConverterPath . $formattedFile; shell_exec($cmd); try { $this->importPdfPages($pdf, $pdfConverterPath . $formattedFile); $cmd = "chmod -R 777 " . $pdfConverterPath . $tempName . ".pdf"; shell_exec($cmd); } catch (Exception $e) { logErrors('Caught exception: ', $e->getMessage(), "\n"); break; } $attachmentOrder = $attachmentOrder + 1; } } $name = 'Ticket-' . $this->getNumber() . '.pdf'; $pdf->Output($name, 'I'); //Remember what the user selected - for autoselect on the next print. $_SESSION['PAPER_SIZE'] = $psize; exit; }
function pdfExport($psize = 'Letter', $notes = false) { global $thisstaff; require_once INCLUDE_DIR . 'class.pdf.php'; if (!is_string($psize)) { if ($_SESSION['PAPER_SIZE']) { $psize = $_SESSION['PAPER_SIZE']; } elseif (!$thisstaff || !($psize = $thisstaff->getDefaultPaperSize())) { $psize = 'Letter'; } } $pdf = new Ticket2PDF($this, $psize, $notes); $name = 'Ticket-' . $this->getNumber() . '.pdf'; $pdf->Output($name, 'I'); //Remember what the user selected - for autoselect on the next print. $_SESSION['PAPER_SIZE'] = $psize; exit; }
function pdfExport($psize = 'Letter', $notes = false) { $pdf = new Ticket2PDF($this, $psize, $notes); $name = 'Ticket-' . $this->getExtId() . '.pdf'; $pdf->Output($name, 'I'); //Remember what the user selected - for autoselect on the next print. $_SESSION['PAPER_SIZE'] = $psize; exit; }