コード例 #1
0
/**
 * Generate the PDF for the specified customcert and user.
 *
 * @param stdClass $customcert
 * @param bool $preview true if it is a preview, false otherwise
 */
function customcert_generate_pdf($customcert, $preview = false)
{
    global $CFG, $DB;
    require_once $CFG->libdir . '/pdflib.php';
    // Get the pages for the customcert, there should always be at least one page for each customcert.
    if ($pages = $DB->get_records('customcert_pages', array('customcertid' => $customcert->id), 'pagenumber ASC')) {
        // Create the pdf object.
        $pdf = new pdf();
        if (!empty($customcert->protection)) {
            $protection = explode(', ', $customcert->protection);
            $pdf->SetProtection($protection);
        }
        $pdf->setPrintHeader(false);
        $pdf->setPrintFooter(false);
        $pdf->SetTitle($customcert->name);
        $pdf->SetAutoPageBreak(true, 0);
        // Remove full-stop at the end, if it exists, to avoid "..pdf" being created and being filtered by clean_filename.
        $filename = rtrim($customcert->name, '.');
        $filename = clean_filename($filename . '.pdf');
        // Loop through the pages and display their content.
        foreach ($pages as $page) {
            // Add the page to the PDF.
            if ($page->width > $page->height) {
                $orientation = 'L';
            } else {
                $orientation = 'P';
            }
            $pdf->AddPage($orientation, array($page->width, $page->height));
            $pdf->SetMargins(0, 0, $page->margin);
            // Get the elements for the page.
            if ($elements = $DB->get_records('customcert_elements', array('pageid' => $page->id), 'sequence ASC')) {
                // Loop through and display.
                foreach ($elements as $element) {
                    // Get an instance of the element class.
                    if ($e = customcert_get_element_instance($element)) {
                        $e->render($pdf, $preview);
                    }
                }
            }
        }
        $pdf->Output($filename, 'D');
    }
}
コード例 #2
0
 /**
  * Create PDF object using parameters
  * 
  * @return PDF
  */
 protected function create_pdf_object()
 {
     //Default orientation is Landescape
     $orientation = 'L';
     if ($this->get_instance()->height > $this->get_instance()->width) {
         $orientation = 'P';
     }
     // Remove commas to avoid a bug in TCPDF where a string containing a commas will result in two strings.
     $keywords = get_string('keywords', 'simplecertificate') . ',' . format_string($this->get_instance()->coursename, true);
     $keywords = str_replace(",", " ", $keywords);
     // Replace commas with spaces.
     $keywords = str_replace("  ", " ", $keywords);
     // Replace two spaces with one.
     $pdf = new pdf($orientation, 'mm', array($this->get_instance()->width, $this->get_instance()->height), true, 'UTF-8');
     $pdf->SetTitle($this->get_instance()->name);
     $pdf->SetSubject($this->get_instance()->name . ' - ' . $this->get_instance()->coursename);
     $pdf->SetKeywords($keywords);
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     $pdf->SetAutoPageBreak(false, 0);
     $pdf->setFontSubsetting(true);
     $pdf->SetMargins(0, 0, 0, true);
     return $pdf;
 }
コード例 #3
0
ファイル: certificate.php プロジェクト: jamesmcq/elis
/**
 * Refactored code from @see certificate_output_completion()
 * an array of parameters is passed and used by the certificate
 * template file.  It is up to the certificate template file to
 * use whatever parameters are available
 *
 * @param array $params: An array of parameters (example: array('student_name' => 'some value'))
 * Here are a list of values that can be used
 * 'student_name', 'course_name', 'class_idnumber', 'class_enrol_time', 'class_enddate', 'class_grade',
 * 'cert_timeissued', 'cert_code', 'class_instructor_name', 'course_description_name'
 * (there will most likely be more when other entity types are added)
 * @param string $border:               A custom border image to use
 * @param string $seal:                 A custom seal image to use
 * @param string $template:             A custom template to use
 * @return string - pdf output
 */
function certificate_output_entity_completion($params, $border = '', $seal = '', $template = '')
{
    global $CFG;
    // Use the TCPDF library.
    require_once $CFG->libdir . '/pdflib.php';
    // Global settings.
    $borders = 0;
    $font = 'FreeSerif';
    $largefontsize = 30;
    $smallfontsize = 16;
    // Create pdf.
    $pdf = new pdf('L', 'in', 'Letter');
    // Prevent the pdf from printing black bars.
    $pdf->setPrintHeader(false);
    $pdf->setPrintFooter(false);
    $pdf->SetAutoPageBreak(false);
    $pdf->SetMargins(0, 0, 0, false);
    $pdf->AddPage();
    $pagewidth = $pdf->getPageWidth();
    $pageheight = $pdf->getPageHeight();
    // Draw the border.
    cm_certificate_check_data_path('borders');
    if (!empty($border)) {
        if (file_exists($CFG->dirroot . '/local/elisprogram/pix/certificate/borders/' . $border)) {
            $pdf->Image($CFG->dirroot . '/local/elisprogram/pix/certificate/borders/' . $border, 0, 0, $pagewidth, $pageheight);
        } else {
            if (file_exists($CFG->dataroot . '/local/elisprogram/pix/certificate/borders/' . $border)) {
                $pdf->Image($CFG->dataroot . '/local/elisprogram/pix/certificate/borders/' . $border, 0, 0, $pagewidth, $pageheight);
            }
        }
    }
    // Draw the seal.
    cm_certificate_check_data_path('seals');
    if (!empty($seal)) {
        if (file_exists($CFG->dirroot . '/local/elisprogram/pix/certificate/seals/' . $seal)) {
            $pdf->Image($CFG->dirroot . '/local/elisprogram/pix/certificate/seals/' . $seal, 8.0, 5.8);
        } else {
            if (file_exists($CFG->dataroot . '/local/elisprogram/pix/certificate/seals/' . $seal)) {
                $pdf->Image($CFG->dataroot . '/local/elisprogram/pix/certificate/seals/' . $seal, 8.0, 5.8);
            }
        }
    }
    // Include the certificate template.
    cm_certificate_check_data_path('templates');
    if (file_exists($CFG->dirroot . '/local/elisprogram/pix/certificate/templates/' . $template)) {
        include $CFG->dirroot . '/local/elisprogram/pix/certificate/templates/' . $template;
    } else {
        if (file_exists($CFG->dataroot . '/local/elisprogram/pix/certificate/templates/' . $template)) {
            include $CFG->dataroot . '/local/elisprogram/pix/certificate/templates/' . $template;
        }
    }
    $pdf->Output();
}