ÿØÿà JFIF    ÿÛ „  ( %!1"%)+...383-7(-.+  -%%--------+------------/----------------------------ÿÀ  ¶" ÿÄ     ÿÄ @    !1AQaq‘¡"±ÁÑð2’BRráS‚ñ3b¢CT²Ò #cÿÄ    ÿÄ '   1!AQ2a"‘±#ÿÚ   ? ò(/p‘—–¢·,M|¯G»R£üešT. ôŸEoCFñ‡ 4ÔkåóxR|µÁ¨ÓDà!Ç´µ˜‡p ÍQ‹§!þž^õWsŒy  åÁ§$á«%ºq˜™JyyË0y«^Ϗ -3ÃÏËÈ£Æ\P’ä„s&•‹Üs üô'àWt¹pñCp$bÚF`·7.^)¾!)ÒÙ˜–ÅÏš^h¾ø³·ìe±ŒaeÖ—Í,e=B}Jéߦ$$½—šÙÜCC¯¶è8β–Åkèwx LÉngT±æ¹£Ócœ¿Í/©Éÿ ‰ÚCÒ­mq;Tt¶–}0"zÖPcd1š­¤tˆ„ÐÓâqú[™öUCŠ2޿د­É(¸ßúçšmW,Ò ºf‹Ån™ÄLêÁ8üÁkÁ€L¥ÍuJ1œôrÂSŒÓöt!7EUíïb)AËi¬â-ÙHk8òÁiXYwÅ)O^"ÇØriÛô{»wRUKÙÏÚlÓ¬€‚’שT ] ªb—ÊîKC^×M“xùäñz¬zJ× {4[¹M'IÆeH1LCWÕ]œûº WDæà°OÅ‚¹c²ÞuA–rL`HšpCez‡V’— Ž‚Ë„–ñ­'µR0ÕÖ=À:±G»C\nÆÉ5*¢ †3šhQ4ýÒi$Õ1"Ü]¢p-q3zcQ$ªö¨¥æf›‘»´ÝÚHá„e²JÇ–iÊ:·à¬Øc5Åk»Laª*wi [0Ówk ¦a¦0Õ²ÅÅ‚T¸’³q:Æ<¹ú Ò˜Æ}2VE•Ѐp¡Ô3Úº …h³^LJºçì¥Ánó|˜ÖˆÎˆ+« ¦dø‘Mº–d\ªDðÛ„Ì×LÝ——Ð9Ç|•FèçVm™¨€™3õS–9Äå¢<̉Ìm¢±`·º˜&Z²ž Ë®D«¶»6™‰©­HÈ Àá«h­i³04æ’hxœi3ï¨(ÓL·†‹¶ËpŒ ƒÜÒ? :õdsÀ –3æÓ·Üjâ¬9—]8n¼&]I F£¼…ì–—Œ0v°LǐÅfÛ2TÖ’aµ˜N@ÖBSÏ^à´4-±°b×nÈÈœÆD=KdŒø…ÄÈK,›ÖR§fjü$^ÔÎ!„6^ s:Üun\ôkCÞò÷<—Lúl Í›G¹ÀPá¼Nc¡šÒ…ÙWͳœ±vÊáЄ×9‹P‰cEØ‘™›µŸP<×g1 º©Ø¬wiÁ^l5× I/';Ë+´Z‡ÓÄFÕp[Èð’ HÄ ó 9¬Dl4“é±Ï”V=^Hð;žLädÉa‚°Ë,#/Ž~²BÔÛ QãñQtIeórVB,ÏÂf‹4#Μc‹É3ZIÖ Œ¢¥·üxa‡Ãçè„jŠ[5 Ä!U?,3žÎ×…ðdÓ÷háŠA‰ìÄ4÷ÃÜZÃE{‰®+W\ZÍE[‰»µk»MÝ­`¢©†˜ÃV‹-f¢¡†¢a«eŠ%«Y¨©q%jâd,Ôq`) ¤¦…šˆ ¦E>0Ùb²t–Ÿ  ÷jsςҒKÈcø(é›;k(’#ôŒQ ™C> õ³M9óºÆµ¤çâ;uÀ)5>RÔ¸fÓ~Ȧ—’-$fe«"FâUˆÊwµPÏu w+"åÉó¨6s™Û9(À¨ù©hE°½†n`m~“@©›p!Vkhµ Á1šbEqqÊ@ºèl›2 –Yã%‘‚hÛ{a¶‡ÅÞM²¬çL34®Çl]®‹ŽØŒm'RÜe35æöˆ­Á­ cP9šeÁköo´L³Ì=p8]”‡B¶,šº|ɏdzXˆØk*ÇÚ{#ñ‰pã(€¶‡9ý'šÜ³½¯kƒ†Â’ëSOƒ•Å®H6+a¢µˆ‹Y¨b˜b+XˆÖ!°u!¢"µˆˆn2ˆ Å0Ä`Å Ô®c(ÓÜGº•Ä»Œ âWî%q.áÐÄ÷î%umÍ£+ÜQ,Vn¦-GphU¸¢X­&,Gt ·K¢ÅÅ·¥RÄÊÉbKn N­R2g$VµÕó Qr#–ÓZUÏð0ÎtÙÀœz ëöo“Îk¯n„T°"SÞ+³/…€½"ižãO%Í%&Δâ‘ËØ´IˆÓ°Ë‰ÞM3.™yçÁzit›`4C`k¢¼á!álÄï sÂ[×!¤l¾æo"ƒIÔ'@ªu)3›ô®“@Z à¾] üœ'‡4¸PÞkÁ-qÄH‰ÓÍBd´ÿ —¹°ÄA&ÊUC„öz‚‚RæŠtf¬>˜ÑidšEçÑL÷áý¡V±h§­c¿¥¨ƒ@g¼…Ýö^ÞËc.ž„æ“I[ ª+·zÐÒÚ,½Ð»¶€C›7jk$๖€Ž¾ÅÙpp¶ÍþéΤ ½ØÎŒq ñpæžÅ¥#Øâ49ÃÂK^MYV“,¶Éz_òæ:…;Õ«¦I3âJ£¤û5$7Èxün\â]Êe¯(Ÿ&Ž‹¶2<6Ćf× æ¢ƱqWı[(ÙÂŽç‚T7¨@ÈÉÍß‚ïÙ"&3TYlGށ†)†#5ŠA©^T2ÆÁ†)©†©†¤yGXÁ†©"†)©¼ÅV WS†#©]R–r‹q5ÕbâWþBh¯u+ªÅÄ×ü„nÑ^êkªÁj‰jeœWˆÕÕ`µDµ2Ì+Ä µDµµ5Ô{¤Þ0RF’H÷AÛ<ÊÁ§ ƈæ0Ñ£ê4 öÚµ[¬/1²€â<-¬šö²r×0o×w ´xÐÒË„ g01¬„åEM蛇Ã\6µE›‘fÙO k÷CºnÓ1`iîÒ² áÂ!ÑLÄÿ ³¬\õ*:M=Ç»c‹2[‰ØsÕLò\ŒK L^™üÄN\¶#» Ç\……ßïIœÉ$¸ÎñÍ®ÔHÇ Ûí/´>Li”„†g^$ 7NÍÑÑ2M2ªNg=k½Ð}Ÿl6‡ —JWˆ”ÞéT·+µ¦üÂFè¢Vs6ýÆ4»2+2IÝ9ô9®ÇGÙÇ1+Ä8;*Õ§ž½D*îÑWÚçá3Ma¤·ˆ¥t}š²Ü…Q+Æüµ8HíS”üxGéÁˆ¦Ël„éÈ 5 µÄƒ6äÜ(kIš¯S†fÖ&¸®×v|Äyˆ*禌Éù@7-®Ä[]ÎÖ¿ê`º…=:…žJVnݳvðÖKE¼‚ »mà ÷f®:Ë ™–4rð¡4` ܹçž~‹C=œ…¾Ïj|VDtK.ƒ"9 Ï ­–éXá³6WÒïIL-Ї Ç lang/en/dataformat_pdf.php000064400000002062152265517460011570 0ustar00. /** * pdf dataformat lang strings. * * @package dataformat_pdf * @copyright 2019 Shamim Rezaie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ $string['dataformat'] = 'Portable Document Format (.pdf)'; $string['privacy:metadata'] = 'The PDF data format plugin does not store any personal data.'; $string['shortname'] = 'PDF'; version.php000064400000002067152265517460006764 0ustar00. /** * Data activity filter version information * * @package dataformat_pdf * @copyright 2019 Shamim Rezaie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); $plugin->version = 2025041400; $plugin->requires = 2025040800; // Requires this Moodle version. $plugin->component = 'dataformat_pdf'; classes/privacy/provider.php000064400000002754152265517460012246 0ustar00. /** * Privacy provider implementation for dataformat_pdf. * * @package dataformat_pdf * @copyright 2019 Shamim Rezaie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace dataformat_pdf\privacy; defined('MOODLE_INTERNAL') || die(); /** * Privacy provider implementation for dataformat_pdf. * * @copyright 2019 Shamim Rezaie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class provider implements \core_privacy\local\metadata\null_provider { /** * Get the language string identifier with the component's language * file to explain why this plugin stores no data. * * @return string */ public static function get_reason(): string { return 'privacy:metadata'; } } classes/writer.php000064400000015570152265517460010253 0ustar00. /** * pdf data format writer * * @package dataformat_pdf * @copyright 2019 Shamim Rezaie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace dataformat_pdf; defined('MOODLE_INTERNAL') || die(); /** * pdf data format writer * * @package dataformat_pdf * @copyright 2019 Shamim Rezaie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class writer extends \core\dataformat\base { public $mimetype = "application/pdf"; public $extension = ".pdf"; /** * @var \pdf The pdf object that is used to generate the pdf file. */ protected $pdf; /** * @var float Each column's width in the current sheet. */ protected $colwidth; /** * @var string[] Title of columns in the current sheet. */ protected $columns; /** * writer constructor. */ public function __construct() { global $CFG; require_once($CFG->libdir . '/pdflib.php'); $this->pdf = new \pdf(); $this->pdf->setPrintHeader(false); $this->pdf->SetFooterMargin(PDF_MARGIN_FOOTER); // Set background color for headings. $this->pdf->SetFillColor(238, 238, 238); } public function send_http_headers() { } /** * Start output to file, note that the actual writing of the file is done in {@see close_output_to_file()} */ public function start_output_to_file(): void { $this->start_output(); } public function start_output() { $this->pdf->AddPage('L'); } public function start_sheet($columns) { $margins = $this->pdf->getMargins(); $pagewidth = $this->pdf->getPageWidth() - $margins['left'] - $margins['right']; $this->colwidth = $pagewidth / count($columns); $this->columns = $columns; $this->print_heading($this->pdf); } /** * Method to define whether the dataformat supports export of HTML * * @return bool */ public function supports_html(): bool { return true; } /** * When exporting images, we need to return their Base64 encoded content. Otherwise TCPDF will create a HTTP * request for them, which will lead to the login page (i.e. not the image it expects) and throw an exception * * Note: ideally we would copy the file to a temp location and return it's path, but a bug in TCPDF currently * prevents that * * @param \stored_file $file * @return string|null */ protected function export_html_image_source(\stored_file $file): ?string { // Set upper dimensions for embedded images. $resizedimage = $file->resize_image(400, 300); return '@' . base64_encode($resizedimage); } /** * Write a single record * * @param array $record * @param int $rownum */ public function write_record($record, $rownum) { $rowheight = 0; $record = $this->format_record($record); foreach ($record as $cell) { // We need to calculate the row height (accounting for any content). Unfortunately TCPDF doesn't provide an easy // method to do that, so we create a second PDF inside a transaction, add cell content and use the largest cell by // height. Solution similar to that at https://stackoverflow.com/a/1943096. $pdf2 = clone $this->pdf; $pdf2->startTransaction(); $numpages = $pdf2->getNumPages(); $pdf2->AddPage('L'); $this->print_heading($pdf2); $pdf2->writeHTMLCell($this->colwidth, 0, '', '', $cell, 1, 1, false, true, 'L'); $pagesadded = $pdf2->getNumPages() - $numpages; $margins = $pdf2->getMargins(); $pageheight = $pdf2->getPageHeight() - $margins['top'] - $margins['bottom']; $cellheight = ($pagesadded - 1) * $pageheight + $pdf2->getY() - $margins['top'] - $this->get_heading_height(); $rowheight = max($rowheight, $cellheight); $pdf2->rollbackTransaction(); } $margins = $this->pdf->getMargins(); if ($this->pdf->getNumPages() > 1 && ($this->pdf->GetY() + $rowheight + $margins['bottom'] > $this->pdf->getPageHeight())) { $this->pdf->AddPage('L'); $this->print_heading($this->pdf); } // Get the last key for this record. end($record); $lastkey = key($record); // Reset the record pointer. reset($record); // Loop through each element. foreach ($record as $key => $cell) { // Determine whether we're at the last element of the record. $nextposition = ($lastkey === $key) ? 1 : 0; // Write the element. $this->pdf->writeHTMLCell($this->colwidth, $rowheight, '', '', $cell, 1, $nextposition, false, true, 'L'); } } public function close_output() { $filename = $this->filename . $this->get_extension(); $this->pdf->Output($filename, 'D'); } /** * Write data to disk * * @return bool */ public function close_output_to_file(): bool { $this->pdf->Output($this->filepath, 'F'); return true; } /** * Prints the heading row for a given PDF. * * @param \pdf $pdf A pdf to print headings in */ private function print_heading(\pdf $pdf) { $fontfamily = $pdf->getFontFamily(); $fontstyle = $pdf->getFontStyle(); $pdf->SetFont($fontfamily, 'B'); $total = count($this->columns); $counter = 1; foreach ($this->columns as $columns) { $nextposition = ($counter == $total) ? 1 : 0; $pdf->Multicell($this->colwidth, $this->get_heading_height(), $columns, 1, 'C', true, $nextposition); $counter++; } $pdf->SetFont($fontfamily, $fontstyle); } /** * Returns the heading height. * * @return int */ private function get_heading_height() { $height = 0; foreach ($this->columns as $columns) { $height = max($height, $this->pdf->getStringHeight($this->colwidth, $columns, false, true, '', 1)); } return $height; } } tests/writer_test.php000064400000005072152265517460011013 0ustar00. /** * Tests for the dataformat_pdf writer * * @package dataformat_pdf * @copyright 2020 Paul Holden * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace dataformat_pdf; use core\dataformat; use context_system; use html_writer; use moodle_url; /** * Writer tests * * @package dataformat_pdf * @copyright 2020 Paul Holden * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ final class writer_test extends \advanced_testcase { /** * Test writing data whose content contains an image with pluginfile.php source */ public function test_write_data_with_pluginfile_image(): void { global $CFG; $this->resetAfterTest(true); $imagefixture = "{$CFG->dirroot}/lib/filestorage/tests/fixtures/testimage.jpg"; $image = get_file_storage()->create_file_from_pathname([ 'contextid' => context_system::instance()->id, 'component' => 'dataformat_pdf', 'filearea' => 'test', 'itemid' => 0, 'filepath' => '/', 'filename' => basename($imagefixture), ], $imagefixture); $imageurl = moodle_url::make_pluginfile_url($image->get_contextid(), $image->get_component(), $image->get_filearea(), $image->get_itemid(), $image->get_filepath(), $image->get_filename()); // Insert out test image into the data so it is exported. $columns = ['animal', 'image']; $row = ['cat', html_writer::img($imageurl->out(), 'My image')]; // Export to file. Assert that the exported file exists. $exportfile = dataformat::write_data('My export', 'pdf', $columns, [$row]); $this->assertFileExists($exportfile); // The exported file should be a reasonable size (~275kb). $this->assertGreaterThan(270000, filesize($exportfile)); } }