Example #1
0
 private function pdf($params)
 {
     try {
         $condition = array();
         $data = array();
         if (!empty($params['a']) && !empty($params['z']) && !empty($params['cdate'])) {
             $col_date = $params['cdate'];
             $query = sprintf("%s BETWEEN '%s' and '%s' ", $params['cdate'], $params['a'], $params['z']);
             $condition['conditions'] = $query;
         }
         $sales = SalesApotik::all($condition);
         $data["rows"] = $sales;
         $data["title"] = $this->template_header;
         $data["posting_range"] = sprintf(" %s sampai %s", $params['a'], $params['z']);
         $data["params"] = sprintf("a=%s&z=%s&cdate=%s", $params['a'], $params['z'], "posting_date");
         $data["source_url"] = APP::urlFor('selling.export');
     } catch (Exception $e) {
         App::flash('error', $e);
     }
     $paper = array("a4", "portrait");
     $dompdf = APP::print_render('selling/print_laporan_harian', $data, $paper);
     $pdf = $dompdf->get_canvas();
     $fontMetrics = $dompdf->getFontMetrics();
     // $font = $fontMetrics->getSystemFonts();
     $font = $fontMetrics->getFont('helvetica');
     // If verdana isn't available, we'll use sans-serif.
     // if (!isset($font)) { $fontMetrics->getFont("sans-serif"); }
     $size = 6;
     $color = array(0, 0, 0);
     $text_height = $fontMetrics->getFontHeight($font, $size);
     $foot = $pdf->open_object();
     $w = $pdf->get_width();
     $h = $pdf->get_height();
     $y = $h - 2 * $text_height - 24;
     $pdf->line(16, $y, $w - 16, $y, $color, 1);
     $y += $text_height;
     $text = sprintf("# %s", $id);
     $pdf->page_text(16, $y, $text, $font, $size, $color);
     $text = "Page {PAGE_NUM} of {PAGE_COUNT}";
     // Center the text
     $width = $fontMetrics->getTextWidth("Page 1 of 2", $font, $size);
     $pdf->page_text($w / 2 - $width / 2, $y, $text, $font, $size, $color);
     $pdf->close_object();
     $pdf->add_object($foot, "all");
     // $watermark = $pdf->open_object();
     // $pdf->set_opacity(0.87);
     // $width = Font_Metrics::get_text_width("COPY", Font_Metrics::get_font("verdana", "bold"), 110);
     // $pdf->text(($w / 2 - $width / 2) + 10, $h / 2, "COPY", Font_Metrics::get_font("verdana", "bold"),
     //   110, array(0.98, 0.98, 0.98), 0, 13.9, -37);
     // $pdf->close_object();
     // $pdf->add_object($watermark, "all");
     $dompdf->stream(sprintf("%s.pdf", $id), array("Attachment" => 0));
 }