function generate_certificate($course_id = false, $user_id = false, $preview = false, $force_download = false)
 {
     global $cp, $pdf;
     if (!$user_id) {
         $user_id = get_current_user_id();
     }
     if ($course_id) {
         $course = new Course($course_id);
     }
     require_once $tc->plugin_dir . 'includes/external/tcpdf/examples/tcpdf_include.php';
     $template_id = get_post_meta($course->details->ID, 'certificate_template', true);
     if ($template_id) {
         $metas = get_post_meta($post_id);
         //cp_get_post_meta_all
     }
     $margin_left = $metas['document_template_left_margin'];
     $margin_top = $metas['document_template_top_margin'];
     $margin_right = $metas['document_template_right_margin'];
     // create new PDF document
     // Use CoursePress_PDF which extends TCPDF
     require_once CoursePress::instance()->plugin_dir . 'includes/classes/class.coursepress-pdf.php';
     $pdf = new CoursePress_PDF($metas['document_template_orientation'], PDF_UNIT, apply_filters('coursepress_additional_template_document_size_output', $metas['document_template_size']), true, apply_filters('coursepress_template_document_encoding', bloginfo('charset')), false);
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     $pdf->SetFont($metas['document_font'], '', 14);
     // set margins
     $pdf->SetMargins($margin_left, $margin_top, $margin_right);
     // set auto page breaks
     $pdf->SetAutoPageBreak(false, PDF_MARGIN_BOTTOM);
     $pdf->AddPage();
     error_reporting(0);
     //Don't show errors in the PDF
     ob_clean();
     //Clear any previous output
     ob_start();
     //Start new output buffer
     if (isset($metas['document_template_background_image']) && $metas['document_template_background_image'] !== '') {
         $pdf->Image($metas['document_template_background_image'], 0, 0, '', '', '', '', '', false, 300, '', false, false, 0);
     }
     $col_1 = 'width: 100%;';
     $col_1_width = '100%';
     $col_2 = 'width: 49.2%; margin-right: 1%;';
     $col_2_width = '49.2%';
     $col_3 = 'width: 32.5%; margin-right: 1%;';
     $col_3_width = '32.5%';
     $col_4 = 'width: 24%; margin-right: 1%;';
     $col_5 = 'width: 19%; margin-right: 1%;';
     $col_6 = 'width: 15.66%; margin-right: 1%;';
     $col_7 = 'width: 13.25%; margin-right: 1%;';
     $col_8 = 'width: 11.43%; margin-right: 1%;';
     $col_9 = 'width: 10%; margin-right: 1%;';
     $col_10 = 'width: 8.94%; margin-right: 1%;';
     $rows = '<table>';
     for ($i = 1; $i <= apply_filters('coursepress_template_template_row_number', 10); $i++) {
         $rows .= '<tr>';
         $rows_elements = get_post_meta($post_id, 'rows_' . $i, true);
         if (isset($rows_elements) && $rows_elements !== '') {
             $element_class_names = explode(',', $rows_elements);
             $rows_count = count($element_class_names);
             foreach ($element_class_names as $element_class_name) {
                 if (class_exists($element_class_name)) {
                     if (isset($post_id)) {
                         $rows .= '<td ' . (isset($metas[$element_class_name . '_cell_alignment']) ? 'align="' . $metas[$element_class_name . '_cell_alignment'] . '"' : 'align="left"') . ' style="' . ${"col_" . $rows_count} . (isset($metas[$element_class_name . '_cell_alignment']) ? 'text-align:' . $metas[$element_class_name . '_cell_alignment'] . ';' : '') . (isset($metas[$element_class_name . '_font_size']) ? 'font-size:' . $metas[$element_class_name . '_font_size'] . ';' : '') . (isset($metas[$element_class_name . '_font_color']) ? 'color:' . $metas[$element_class_name . '_font_color'] . ';' : '') . '">';
                         for ($s = 1; $s <= $metas[$element_class_name . '_top_padding']; $s++) {
                             $rows .= '<br />';
                         }
                         $element = new $element_class_name($post_id);
                         $rows .= $element->template_content($course_id, $user_id, $preview);
                         for ($s = 1; $s <= $metas[$element_class_name . '_bottom_padding']; $s++) {
                             $rows .= '<br />';
                         }
                         $rows .= '</td>';
                     }
                 }
             }
         }
         $rows .= '</tr>';
     }
     $rows .= '</table>';
     echo $rows;
     $page = ob_get_contents();
     ob_clean();
     $page = preg_replace("/\\s\\s+/", '', $page);
     //Strip excess whitespace
     $pdf->writeHTML($page, true, 0, true, 0);
     //Write page
     $pdf->lastPage();
     $pdf->Output((isset($course->details->post_name) ? $course->details->post_name : __('Certificate', 'cp')) . '.pdf', $force_download ? 'D' : 'I');
     exit;
 }
 function pdf_report($report = '', $report_name = '', $report_title = 'Student Report', $preview = false)
 {
     //ob_end_clean();
     ob_start();
     // Use CoursePress_PDF which extends TCPDF
     require_once $this->plugin_dir . 'includes/classes/class.coursepress-pdf.php';
     // create new PDF document
     $pdf = new CoursePress_PDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     // set document information
     $pdf->SetCreator($this->name);
     $pdf->SetTitle($report_title);
     $pdf->SetKeywords('');
     // remove default header/footer
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     // set default monospaced font
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     //set margins
     $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
     $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
     //set auto page breaks
     $pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);
     //set image scale factor
     //$pdf->setImageScale( PDF_IMAGE_SCALE_RATIO );
     //set some language-dependent strings
     //			$pdf->setLanguageArray( $l );
     // ---------------------------------------------------------
     // set font
     $reports_font = get_option('reports_font', 'helvetica');
     $pdf->SetFont($reports_font, '', apply_filters('cp_report_font_size', 12));
     // add a page
     $pdf->AddPage();
     $html = '';
     $html .= make_clickable(wpautop($report));
     // output the HTML content
     $pdf->writeHTML($html, true, false, true, false, '');
     //Close and output PDF document
     ob_get_clean();
     if ($preview) {
         $pdf->Output($report_name, 'I');
     } else {
         $pdf->Output($report_name, 'D');
     }
     exit;
 }
 public static function make_pdf($student, $course, $url = false)
 {
     // Use CoursePress_PDF which extends TCPDF
     require_once CoursePress::instance()->plugin_dir . 'includes/classes/class.coursepress-pdf.php';
     // Get the objects from IDs if passed as IDs.
     if (!is_object($course) && 0 != (int) $course) {
         $course = new Course($course);
     }
     if (!is_object($student) && 0 != (int) $student) {
         $student = new Student($student);
     }
     $course_completed_details = self::_get_fields($student, $course);
     $certificate_title = sprintf(__('Certificate %s', 'cp'), $course_completed_details['certificate_number']);
     // Get the styles and replace fields if they exist
     $top = self::option('padding_top');
     $bototm = self::option('padding_bottom');
     $left = self::option('padding_left');
     $right = self::option('padding_right');
     $style = sprintf(".basic_certificate{ padding: %s %s %s %s; }", $top, $right, $bototm, $left);
     // has to be this order for CSS shortcut
     $style .= self::certificate_styles();
     $style = !empty($style) ? '<style>' . $style . '</style>' : $style;
     $html = '<table class="basic_certificate"><tr><td>' . "\n\n" . stripslashes(self::certificate_content()) . "\n\n" . '</td></tr></table>';
     $html = self::_replace_fields($html, $student, $course, true, $course_completed_details);
     // create new PDF document
     $pdf = new CoursePress_PDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     return $pdf->make_pdf($html, array('title' => $certificate_title, 'style' => $style, 'image' => self::option('background_url'), 'orientation' => self::option('orientation'), 'uid' => $course_completed_details['certificate_number'], 'url' => $url));
 }