コード例 #1
0
ファイル: PdfOutput.php プロジェクト: solofo-ralitera/oron
 /**
 Render the pdf
 */
 public static function renderEvent(\Core\Request $request, $str)
 {
     if (isset($request->outputformat) && strtolower($request->outputformat) == "pdf") {
         // Remove script
         if (isset($request->outputpdfcontent)) {
             $str = urldecode($request->outputpdfcontent);
             $str = preg_replace('#<script(.*?)>(.{0,})</script>#i', '', $str);
             $str = preg_replace('#<form data-temp(.*?)>(.*?)</form>#isU', '', $str);
         }
         // Real path for css/js
         $str = preg_replace_callback("!(href|src)=\"(.{1,})\"!isU", "static::filePathCallback", $str);
         // params
         $params = array();
         if (isset($request->outputpdfparams)) {
             $request->outputpdfparams = urldecode($request->outputpdfparams);
             try {
                 $p = json_decode($request->outputpdfparams, true);
             } catch (Exception $e) {
                 $p = null;
             }
             if (!empty($p) && is_array($p)) {
                 $params = $p;
             }
         }
         $pdf = new \mikehaertl\wkhtmlto\Pdf($params);
         if (file_exists("wkhtmltopdf") && is_executable("wkhtmltopdf")) {
             $pdf->binary = "wkhtmltopdf";
         } elseif (file_exists("wkhtmltopdf.exe") && is_executable("wkhtmltopdf.exe")) {
             $pdf->binary = "wkhtmltopdf.exe";
         } elseif (file_exists("/usr/local/bin/wkhtmltopdf") && is_executable("/usr/local/bin/wkhtmltopdf")) {
             $pdf->binary = "/usr/local/bin/wkhtmltopdf";
         } elseif (file_exists("/usr/local/apache2/bin/wkhtmltopdf") && is_executable("/usr/local/apache2/bin/wkhtmltopdf")) {
             $pdf->binary = "/usr/local/apache2/bin/wkhtmltopdf";
         }
         $pdf->addPage($str);
         $d = $pdf->send("page.pdf", false);
         if (!$d) {
             throw new \Exception('Could not create PDF: ' . $pdf->getError());
         }
         // skip html output
         return "";
     }
     return $str;
 }
コード例 #2
0
 private function toPdf($html)
 {
     $pdf = new \mikehaertl\wkhtmlto\Pdf($html);
     $pdf->binary = '/usr/local/bin/wkhtmltopdf';
     $pdf->setOptions(['ignoreWarnings' => true]);
     if ($html = $pdf->toString()) {
         return $html;
     }
     throw new \exception('Failed To write PDF with message: ' . $pdf->getError());
 }
コード例 #3
0
ファイル: Pendaftar.php プロジェクト: s4if/ppdb-sma
 public function print_kartu()
 {
     $registrant = $this->session->registrant;
     if (!empty($registrant)) {
         $pdf = new mikehaertl\wkhtmlto\Pdf();
         $pdf->setOptions($this->pdfOption());
         $reg_data = $this->load->view('registrant/print', ['registrant' => $registrant], true);
         $pdf->addPage($reg_data);
         $res = $pdf->send('Kartu Pendaftaran ' . $registrant->getId() . ' .pdf');
         if (!$res) {
             echo $pdf->getError();
         }
     } else {
         $this->session->set_flashdata("errors", [0 => "Maaf, Anda tidak boleh melihat halaman ini lagi!"]);
         redirect('login/index');
     }
 }