From 0a39261b8e42d4198fc02fdaa366b835a411a7f3 Mon Sep 17 00:00:00 2001 From: mudrd8mz Date: Mon, 20 Jul 2009 17:32:44 +0000 Subject: [PATCH] MDL-19877 adding a script producing a test PDF --- lib/simpletest/pdflibtestpage.php | 144 ++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 lib/simpletest/pdflibtestpage.php diff --git a/lib/simpletest/pdflibtestpage.php b/lib/simpletest/pdflibtestpage.php new file mode 100644 index 0000000000..24d1659f36 --- /dev/null +++ b/lib/simpletest/pdflibtestpage.php @@ -0,0 +1,144 @@ +. + +/** + * Pruduces a sample PDF using lib/pdflib.php + * + * @package moodlecore + * @copyright 2009 David Mudrak + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once(dirname(dirname(dirname(__FILE__))) . '/config.php'); +require_once($CFG->libdir . '/pdflib.php'); + +require_login(); +$context = get_context_instance(CONTEXT_SYSTEM); +require_capability('moodle/site:config', $context); + +$getpdf = optional_param('getpdf', 0, PARAM_INT); +$fontfamily = ''; // use default + +/** + * 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('lib/simpletest/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: ' . PDF_PRODUCER . '
'; + $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, 'Moodle core English'); + foreach ($langdirs as $langdir) { + if ('Moodle core English' == $langdir) { + $langconfig = $CFG->dirroot . '/lang/en_utf8/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('lib/simpletest/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($PAGE->url->out(false, array('getpdf' => 1))); +echo $OUTPUT->footer(); -- 2.39.5