public function Image($file, $x = null, $y = null, $w = 0, $h = 0, $type = '', $link = '') { try { return parent::Image($file, $x, $y, $w, $h, $type, $link); } catch (Exception $e) { } }
/** * Generate and save or stream a PDF file * * @access public * @since 1.0.0 * @param string $path optional absolute path to the directory, if * not supplied the PDF will be streamed as a downloadable file (used * for admin previewing of the PDF) * * @return mixed nothing if a $path is supplied, otherwise a PDF download */ public function generate_pdf($path = '') { global $current_user, $post; // include the pdf library $root_dir = dirname(__FILE__) . DIRECTORY_SEPARATOR; require_once $root_dir . '/../lib/tfpdf/tfpdf.php'; $image = wp_get_attachment_metadata($this->get_image_id()); // determine orientation: landscape or portrait if ($image['width'] > $image['height']) { $orientation = 'L'; } else { $orientation = "P"; } // End If Statement // Create the pdf // TODO: we're assuming a standard DPI here of where 1 point = 1/72 inch = 1 pixel // When writing text to a Cell, the text is vertically-aligned in the middle $fpdf = new tFPDF($orientation, 'pt', array($image['width'], $image['height'])); $fpdf->AddPage(); $fpdf->SetAutoPageBreak(false); // Add custom font $custom_font = apply_filters('sensei_certificates_custom_font', false); if ($custom_font) { if (isset($custom_font['family']) && isset($custom_font['file'])) { $fpdf->AddFont($custom_font['family'], '', $custom_font['file'], true); } } else { // Add multibyte font $fpdf->AddFont('DejaVu', '', 'DejaVuSansCondensed.ttf', true); } // set the certificate image $upload_dir = wp_upload_dir(); $fpdf->Image($upload_dir['basedir'] . '/' . $image['file'], 0, 0, $image['width'], $image['height']); // this is useful for displaying the text cell borders when debugging the PDF layout, // though keep in mind that we translate the box position to align the text to bottom // edge of what the user selected, so if you want to see the originally selected box, // display that prior to the translation $show_border = 0; // Get Student Data get_currentuserinfo(); $fname = $current_user->first_name; $lname = $current_user->last_name; $student_name = $current_user->display_name; if ('' != $fname && '' != $lname) { $student_name = $fname . ' ' . $lname; } // Get Course Data $course = array(); $course['post_title'] = __('Course Title', 'sensei-certificates'); $course_end_date = date('Y-m-d'); // Get the certificate template $certificate_template_custom_fields = get_post_custom($post->ID); // Define the data we're going to load: Key => Default value $load_data = array('certificate_font_style' => array(), 'certificate_font_color' => array(), 'certificate_font_size' => array(), 'certificate_font_family' => array(), 'image_ids' => array(), 'certificate_template_fields' => array()); // Load the data from the custom fields foreach ($load_data as $key => $default) { // set value from db (unserialized if needed) or use default $this->{$key} = isset($certificate_template_custom_fields['_' . $key][0]) && '' !== $certificate_template_custom_fields['_' . $key][0] ? is_array($default) ? maybe_unserialize($certificate_template_custom_fields['_' . $key][0]) : $certificate_template_custom_fields['_' . $key][0] : $default; } // End For Loop // Set default fonts setlocale(LC_TIME, get_locale()); if (false !== strpos(get_locale(), 'en')) { $date_format = apply_filters('sensei_certificate_date_format', 'jS F Y'); $date = date($date_format, strtotime($course_end_date)); } else { $date_format = apply_filters('sensei_certificate_date_format', '%Y %B %e'); $date = strftime($date_format, strtotime($course_end_date)); } $certificate_heading = __('Certificate of Completion', 'sensei-certificates'); // Certificate of Completion if (isset($this->certificate_template_fields['certificate_heading']['text']) && '' != $this->certificate_template_fields['certificate_heading']['text']) { $certificate_heading = $this->certificate_template_fields['certificate_heading']['text']; $certificate_heading = str_replace(array('{{learner}}', '{{course_title}}', '{{completion_date}}', '{{course_place}}'), array($student_name, $course['post_title'], $date, get_bloginfo('name')), $certificate_heading); } // End If Statement $certificate_message = __('This is to certify that', 'sensei-certificates') . " \r\n\r\n" . $student_name . " \r\n\r\n" . __('has completed the course', 'sensei-certificates'); // This is to certify that {{learner}} has completed the course if (isset($this->certificate_template_fields['certificate_message']['text']) && '' != $this->certificate_template_fields['certificate_message']['text']) { $certificate_message = $this->certificate_template_fields['certificate_message']['text']; $certificate_message = str_replace(array('{{learner}}', '{{course_title}}', '{{completion_date}}', '{{course_place}}'), array($student_name, $course['post_title'], $date, get_bloginfo('name')), $certificate_message); } // End If Statement $certificate_course = $course['post_title']; // {{course_title}} if (isset($this->certificate_template_fields['certificate_course']['text']) && '' != $this->certificate_template_fields['certificate_course']['text']) { $certificate_course = $this->certificate_template_fields['certificate_course']['text']; $certificate_course = str_replace(array('{{learner}}', '{{course_title}}', '{{completion_date}}', '{{course_place}}'), array($student_name, $course['post_title'], $date, get_bloginfo('name')), $certificate_course); } // End If Statement $certificate_completion = $date; // {{completion_date}} if (isset($this->certificate_template_fields['certificate_completion']['text']) && '' != $this->certificate_template_fields['certificate_completion']['text']) { $certificate_completion = $this->certificate_template_fields['certificate_completion']['text']; $certificate_completion = str_replace(array('{{learner}}', '{{course_title}}', '{{completion_date}}', '{{course_place}}'), array($student_name, $course['post_title'], $date, get_bloginfo('name')), $certificate_completion); } // End If Statement $certificate_place = sprintf(__('At %s', 'sensei-certificates'), get_bloginfo('name')); // At {{course_place}} if (isset($this->certificate_template_fields['certificate_place']['text']) && '' != $this->certificate_template_fields['certificate_place']['text']) { $certificate_place = $this->certificate_template_fields['certificate_place']['text']; $certificate_place = str_replace(array('{{learner}}', '{{course_title}}', '{{completion_date}}', '{{course_place}}'), array($student_name, $course['post_title'], $date, get_bloginfo('name')), $certificate_place); } // End If Statement $output_fields = array('certificate_heading' => 'text_field', 'certificate_message' => 'textarea_field', 'certificate_course' => 'text_field', 'certificate_completion' => 'text_field', 'certificate_place' => 'text_field'); foreach ($output_fields as $meta_key => $function_name) { // Check if the field has a set position if (isset($this->certificate_template_fields[$meta_key]['position']['x1'])) { $font_settings = $this->get_certificate_font_settings($meta_key); call_user_func_array(array($this, $function_name), array($fpdf, ${$meta_key}, $show_border, array($this->certificate_template_fields[$meta_key]['position']['x1'], $this->certificate_template_fields[$meta_key]['position']['y1'], $this->certificate_template_fields[$meta_key]['position']['width'], $this->certificate_template_fields[$meta_key]['position']['height']), $font_settings)); } // End If Statement } // End For Loop // download file $fpdf->Output('certificate-preview-' . $post->ID . '.pdf', 'I'); }
/** * See FPDF/TCPDF-Documentation ;-) */ function Image($file, $x = null, $y = null, $w = 0, $h = 0, $type = '', $link = '') { if (is_subclass_of($this, 'TCPDF')) { $args = func_get_args(); return call_user_func_array(array($this, 'TCPDF::Image'), $args); } $ret = parent::Image($file, $x, $y, $w, $h, $type, $link); if ($this->_intpl) { $this->_res['tpl'][$this->tpl]['images'][$file] =& $this->images[$file]; } else { $this->_res['page'][$this->page]['images'][$file] =& $this->images[$file]; } return $ret; }
public function create_pdf_oferte($title, $desc, $products) { $CI =& get_instance(); $CI->load->helper('tfpdf'); $CI->load->helper('data_helper'); $CI->load->model('mysql'); $CI->load->library('session'); $pdf = new tFPDF('P', 'mm', 'A4'); $pdf->AddPage(); //titlu oferta // Add a Unicode font (uses UTF-8) $pdf->AddFont('DejaVu', '', 'DejaVuSansCondensed.ttf', true); $pdf->SetFont('DejaVu', '', 14); //$pdf->AddFont('TimesNewRomanPSMT','','times.php'); //$pdf->SetFont('TimesNewRomanPSMT',''); // $pdf->AddFont('TimesNewRomanPSMT','','times.php'); // $pdf->SetFont('TimesNewRomanPSMT','',12); // $pdf->SetFont('Arial','B',16); $pdf->Cell(0, 0, $title); $pdf->Ln(5); // rind nou //descrire oferta $pdf->MultiCell(0, 5, $desc); $pdf->Ln(5); $i = 0; foreach ($products as $item) { $i++; //info suprafata $pdf->SetFont('Arial', 'B', 11); $pdf->Cell(0, 0, 'Info Suprafata publicitara Nr' . $i); $pdf->Ln(8); // rind nou //adresa link $pdf->SetTextColor(0, 136, 204); $pdf->SetFont('Arial', 'B', 11); $pdf->Cell(0, 0, $item['adresa'], '', '', '', false, 'http://www.marplo.net/jocuri'); $pdf->Ln(5); // rind nou //numar de inventar $pdf->SetFont('Arial', '', 10); $pdf->SetTextColor(0, 0, 0); $pdf->Cell(0, 0, 'Numarul de inventar: #' . $item['inv']); $pdf->Ln(8); // rind nou //pret $pdf->SetFont('Arial', 'B', 12); $pdf->Cell(0, 0, 'Pret: ' . $item['price'] . ' euro'); $pdf->Ln(10); // rind nou //dimensiunea $pdf->SetFont('Arial', 'B', 8); $pdf->Cell(0, 0, 'Dimensiuni: ' . $item['format']); $pdf->Ln(5); // rind nou //foto if ($item['image'] and file_exists($_SERVER['DOCUMENT_ROOT'] . $item['image'])) { $pdf->Cell(0, 0, 'Foto'); $pdf->Ln(2); // rind nou $pdf->Image('.' . $item['image']); $pdf->Ln(20); // rind nou } else { $pdf->Ln(20); } // rind nou } //footer $pdf->SetFont('Arial', 'B', 6); $pdf->Cell(0, 0, 'Trendseter Copyright 2011', '', '', 'C'); $pdf->Ln(5); // rind nou // Tilte pdf $page_title = 'Oferta_' . date('d_m_Y_H:i:s'); $pdf->output('./uploads/offerts/' . $page_title . '.pdf', 'F'); $CI->mysql->insert('offerts_pdf', array('uid' => $CI->session->userdata('uid'), 'pdf' => './uploads/offerts/' . $page_title . '.pdf')); return './uploads/offerts/' . $page_title . '.pdf'; }
/** * Generate and save or stream a PDF file for this certificate * * @access public * @since 1.0.0 * @param string $path optional absolute path to the certificate directory, if * not supplied the PDF will be streamed as a downloadable file * * @return mixed nothing if a $path is supplied, otherwise a PDF download */ public function generate_pdf($path = '') { // include the pdf library $root_dir = dirname(__FILE__) . DIRECTORY_SEPARATOR; require_once $root_dir . '../lib/tfpdf/tfpdf.php'; do_action('sensei_certificates_set_background_image', $this); if (isset($this->bg_image_src) && '' != $this->bg_image_src) { $image = $this->bg_image_src; } else { $image = apply_filters('woothemes_sensei_certificates_background', $GLOBALS['woothemes_sensei_certificates']->plugin_path . 'assets/images/certificate_template.png'); } // End If Statement $image_attr = getimagesize($image); if ($image_attr[0] > $image_attr[1]) { $orientation = 'L'; } else { $orientation = 'P'; } // End If Statement // Create the pdf // TODO: we're assuming a standard DPI here of where 1 point = 1/72 inch = 1 pixel // When writing text to a Cell, the text is vertically-aligned in the middle $fpdf = new tFPDF($orientation, 'pt', array($image_attr[0], $image_attr[1])); $fpdf->AddPage(); $fpdf->SetAutoPageBreak(false); // Add custom font $custom_font = apply_filters('sensei_certificates_custom_font', false); if ($custom_font) { if (isset($custom_font['family']) && isset($custom_font['file'])) { $fpdf->AddFont($custom_font['family'], '', $custom_font['file'], true); } } else { // Add multibyte font $fpdf->AddFont('DejaVu', '', 'DejaVuSansCondensed.ttf', true); } // Set the border image as the background $fpdf->Image($image, 0, 0, $image_attr[0], $image_attr[1]); do_action('sensei_certificates_before_pdf_output', $this, $fpdf); if ($path) { // save the pdf as a file $fpdf->Output($path . '/' . $this->get_certificate_template_path() . '/' . $this->get_certificate_filename(), 'F'); } else { // download file $fpdf->Output('certificate-preview-' . $this->hash . '.pdf', 'I'); } // End If Statement }
if ($scoreTempQuestion < $scoreQuestions) { $scoreTempQuestion = $scoreQuestions; } } $scoreMax += $scoreTempQuestion; $scoreTempQuestion = 0; } } $classe = $recupform->getClasse($answerClasse); //$scorePencen = round(($score*100)/$scoreMax); $pdf->Write(5, 'ton score ' . $score . ' score max :' . $scoreMax); //$pdf->Write(5,'Vous etes protege a '.$scorePencen.'% de la capacite de votre site'); $pdf->Ln(); if ($classScore == 2) { if ($score < $scoreMax * 0.2) { $pdf->Image('img/NoteA.png'); } elseif ($score < $scoreMax * 0.4 && $score > $scoreMax * 0.2) { $pdf->Image('img/NoteB.png'); } elseif ($score < $scoreMax * 0.6 && $score > $scoreMax * 0.4) { $pdf->Image('img/NoteC.png'); } elseif ($score < $scoreMax * 0.8 && $score > $scoreMax * 0.6) { $pdf->Image('img/NoteD.png'); } else { $pdf->Image('img/NoteE.png'); } } elseif ($classScore == 3) { if ($score < $scoreMax * 0.4) { $pdf->Image('img/NoteA.png'); } elseif ($score < $scoreMax * 0.5 && $score > $scoreMax * 0.4) { $pdf->Image('img/NoteB.png'); } elseif ($score < $scoreMax * 0.7 && $score > $scoreMax * 0.5) {