. /** * Pruduces a sample PDF using lib/pdflib.php * * @package tool * @subpackage unittest * @copyright 2009 David Mudrak * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require(dirname(__FILE__) . '/../../../../config.php'); require_once($CFG->libdir . '/pdflib.php'); require_login(); $context = get_context_instance(CONTEXT_SYSTEM); require_capability('tool/unittest:execute', $context); $getpdf = optional_param('getpdf', 0, PARAM_INT); $fontfamily = optional_param('fontfamily', PDF_DEFAULT_FONT, PARAM_ALPHA); // to be configurable /** * Extend the standard PDF class to get access to some protected values we want to display * at the test page. * * @copyright 2009 David Mudrak * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class testable_pdf extends pdf { public function returnFontsList() { return $this->fontlist; } public function _getfontpath() { return parent::_getfontpath(); } } if ($getpdf) { $doc = new testable_pdf(); $doc->SetTitle('Moodle PDF library test'); $doc->SetAuthor('Moodle ' . $CFG->release); $doc->SetCreator('admin/tool/unittest/pdflibtestpage.php'); $doc->SetKeywords('Moodle, PDF'); $doc->SetSubject('This has been generated by Moodle as its PDF library test page'); $doc->SetMargins(15, 30); $doc->setPrintHeader(true); $doc->setHeaderMargin(10); $doc->setHeaderFont(array($fontfamily, 'b', 10)); $doc->setHeaderData('pix/moodlelogo-med-white.gif', 40, $SITE->fullname, $CFG->wwwroot); $doc->setPrintFooter(true); $doc->setFooterMargin(10); $doc->setFooterFont(array($fontfamily, '', 8)); $doc->AddPage(); $doc->SetTextColor(255,255,255); $doc->SetFillColor(255,203,68); $doc->SetFont($fontfamily, 'B', 24); $doc->Cell(0, 0, 'Moodle PDF library test', 0, 1, 'C', 1); $doc->SetFont($fontfamily, '', 12); $doc->Ln(6); $doc->SetTextColor(0,0,0); $c = '

General information

'; $c .= 'Moodle release: ' . $CFG->release . '
'; $c .= 'PDF producer: TCPDF ' . $doc->getTCPDFVersion() . ' (http://www.tcpdf.org)
'; $c .= 'Font of this test page: ' . $fontfamily . '
'; $c .= '

Current settings

'; $c .= ''; foreach (array('K_PATH_MAIN', 'K_PATH_URL', 'K_PATH_FONTS', 'K_PATH_CACHE', 'K_PATH_IMAGES', 'K_BLANK_IMAGE', 'K_CELL_HEIGHT_RATIO', 'K_SMALL_RATIO', 'PDF_CUSTOM_FONT_PATH', 'PDF_DEFAULT_FONT') as $setting) { if (defined($setting)) { $c .= ''; } } $c .= ''; $c .= '
' . $setting . '' . constant($setting) . '
Effective font path' . $doc->_getfontpath() . '

'; $c .= '

Available font files

'; $fontfiles = $doc->returnFontsList(); sort($fontfiles); $c .= implode(', ', $fontfiles); $c .= '
'; $c .= '

Installed languages and their alphabets

'; $languages = array(); $langdirs = get_list_of_plugins('lang', '', $CFG->dataroot); array_unshift($langdirs, 'en'); foreach ($langdirs as $langdir) { if ('en' == $langdir) { $langconfig = $CFG->dirroot . '/lang/en/langconfig.php'; } else { $langconfig = $CFG->dataroot . '/lang/' . $langdir . '/langconfig.php'; } if (is_readable($langconfig)) { include($langconfig); if (is_array($string)) { $languages[$langdir] = new stdClass(); $languages[$langdir]->langname = isset($string['thislanguage']) ? $string['thislanguage'] : '(unknown)'; $languages[$langdir]->alphabet = isset($string['alphabet']) ? $string['alphabet'] : '(no alphabet defined)'; } } } $c .= '
'; foreach ($languages as $langcode => $language) { $c .= '
' . $language->langname . ' (' . $langcode . ')
'; $c .= '
"' . $language->alphabet . '"
'; } $c .= '
'; $doc->writeHTML($c); $doc->Output('pdflibtestpage.pdf'); exit(); } $PAGE->set_url('/admin/tool/unittest/other/pdflibtestpage.php'); $PAGE->set_context($context); $PAGE->set_title('PDF library test'); $PAGE->set_heading('PDF library test'); echo $OUTPUT->header(); echo $OUTPUT->heading('Press the button to generate test PDF', 2); echo $OUTPUT->continue_button(new moodle_url($PAGE->url, array('getpdf' => 1))); echo $OUTPUT->footer();