Example #1
0
    public function testPdfOutput()
    {
        // create new PDF document
        $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
        // set document information
        $pdf->SetCreator(PDF_CREATOR);
        $pdf->SetAuthor('Nicola Asuni');
        $pdf->SetTitle('TCPDF Example 041');
        $pdf->SetSubject('TCPDF Tutorial');
        $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
        // set default header data
        $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 041', PDF_HEADER_STRING);
        // set header and footer fonts
        $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
        $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
        // set default monospaced font
        $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
        // set margins
        $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
        $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
        $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
        // set auto page breaks
        $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
        // set image scale factor
        $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
        // set some language-dependent strings (optional)
        $pdf->setLanguageArray($this->langSettings);
        // ---------------------------------------------------------
        // set font
        $pdf->SetFont('times', '', 16);
        // add a page
        $pdf->AddPage();
        $txt = 'Example of File Attachment.
Double click on the icon to open the attached file.';
        $pdf->Write(0, $txt, '', 0, 'L', true, 0, false, false, 0);
        // attach an external file
        $pdf->Annotation(85, 27, 5, 5, 'text file', array('Subtype' => 'FileAttachment', 'Name' => 'PushPin', 'FS' => 'tests/data/utf8test.txt'));
        $this->comparePdfs($pdf);
    }
Example #2
0
    public function testPdfOutput()
    {
        // create new PDF document
        $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
        // set document information
        $pdf->SetCreator(PDF_CREATOR);
        $pdf->SetAuthor('Nicola Asuni');
        $pdf->SetTitle('TCPDF Example 036');
        $pdf->SetSubject('TCPDF Tutorial');
        $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
        // set default header data
        $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 036', PDF_HEADER_STRING);
        // set header and footer fonts
        $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
        $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
        // set default monospaced font
        $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
        // set margins
        $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
        $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
        $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
        // set auto page breaks
        $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
        // set image scale factor
        $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
        // set some language-dependent strings (optional)
        $pdf->setLanguageArray($this->langSettings);
        // ---------------------------------------------------------
        // set font
        $pdf->SetFont('times', '', 16);
        // add a page
        $pdf->AddPage();
        $txt = 'Example of Text Annotation.
Move your mouse over the yellow box or double click on it to display the annotation text.';
        $pdf->Write(0, $txt, '', 0, 'L', true, 0, false, false, 0);
        // text annotation
        $pdf->Annotation(83, 27, 10, 10, "Text annotation example\naccented letters test: à èéìòù", array('Subtype' => 'Text', 'Name' => 'Comment', 'T' => 'title example', 'Subj' => 'example', 'C' => array(255, 255, 0)));
        $this->comparePdfs($pdf);
    }
Example #3
0
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
$pdf->setLanguageArray($l);
// ---------------------------------------------------------
// set font
$pdf->SetFont('times', '', 16);
// add a page
$pdf->AddPage();
// print a line using Cell()
$pdf->Cell(0, 12, 'Example 036', 1, 1, 'C');
// text annotation
$pdf->Annotation(124, 30, 10, 10, "Text annotation example\naccented letters test: àèéìòù", array('Subtype' => 'Text', 'Name' => 'Comment', 'T' => 'title example', 'Subj' => 'example', 'C' => array(255, 255, 0)));
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('example_036.pdf', 'I');
//============================================================+
// END OF FILE
//============================================================+
Example #4
0
    public function testPdfOutput()
    {
        // create new PDF document
        $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
        // set document information
        $pdf->SetCreator(PDF_CREATOR);
        $pdf->SetAuthor('Nicola Asuni');
        $pdf->SetTitle('TCPDF Example 015');
        $pdf->SetSubject('TCPDF Tutorial');
        $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
        // set default header data
        $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 015', PDF_HEADER_STRING);
        // set header and footer fonts
        $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
        $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
        // set default monospaced font
        $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
        // set margins
        $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
        $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
        $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
        // set auto page breaks
        $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
        // set image scale factor
        $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
        // set some language-dependent strings (optional)
        $pdf->setLanguageArray($this->langSettings);
        // ---------------------------------------------------------
        // Bookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0))
        // set font
        $pdf->SetFont('times', 'B', 20);
        // add a page
        $pdf->AddPage();
        // set a bookmark for the current position
        $pdf->Bookmark('Chapter 1', 0, 0, '', 'B', array(0, 64, 128));
        // print a line using Cell()
        $pdf->Cell(0, 10, 'Chapter 1', 0, 1, 'L');
        $pdf->SetFont('times', 'I', 14);
        $pdf->Write(0, 'You can set PDF Bookmarks using the Bookmark() method.
You can set PDF Named Destinations using the setDestination() method.');
        $pdf->SetFont('times', 'B', 20);
        // add other pages and bookmarks
        $pdf->AddPage();
        $pdf->Bookmark('Paragraph 1.1', 1, 0, '', '', array(0, 0, 0));
        $pdf->Cell(0, 10, 'Paragraph 1.1', 0, 1, 'L');
        $pdf->AddPage();
        $pdf->Bookmark('Paragraph 1.2', 1, 0, '', '', array(0, 0, 0));
        $pdf->Cell(0, 10, 'Paragraph 1.2', 0, 1, 'L');
        $pdf->AddPage();
        $pdf->Bookmark('Sub-Paragraph 1.2.1', 2, 0, '', 'I', array(0, 0, 0));
        $pdf->Cell(0, 10, 'Sub-Paragraph 1.2.1', 0, 1, 'L');
        $pdf->AddPage();
        $pdf->Bookmark('Paragraph 1.3', 1, 0, '', '', array(0, 0, 0));
        $pdf->Cell(0, 10, 'Paragraph 1.3', 0, 1, 'L');
        $pdf->AddPage();
        // add a named destination so you can open this document at this page using the link: "example_015.pdf#chapter2"
        $pdf->setDestination('chapter2', 0, '');
        // add a bookmark that points to a named destination
        $pdf->Bookmark('Chapter 2', 0, 0, '', 'BI', array(128, 0, 0), -1, '#chapter2');
        $pdf->Cell(0, 10, 'Chapter 2', 0, 1, 'L');
        $pdf->SetFont('times', 'I', 14);
        $pdf->Write(0, 'Once saved, you can open this document at this page using the link: "example_015.pdf#chapter2".');
        $pdf->AddPage();
        $pdf->setDestination('chapter3', 0, '');
        $pdf->SetFont('times', 'B', 20);
        $pdf->Bookmark('Chapter 3', 0, 0, '', 'B', array(0, 64, 128));
        $pdf->Cell(0, 10, 'Chapter 3', 0, 1, 'L');
        $pdf->AddPage();
        $pdf->setDestination('chapter4', 0, '');
        $pdf->SetFont('times', 'B', 20);
        $pdf->Bookmark('Chapter 4', 0, 0, '', 'B', array(0, 64, 128));
        $pdf->Cell(0, 10, 'Chapter 4', 0, 1, 'L');
        $pdf->AddPage();
        $pdf->Bookmark('Chapter 5', 0, 0, '', 'B', array(0, 128, 0));
        $pdf->Cell(0, 10, 'Chapter 5', 0, 1, 'L');
        $txt = 'Example of File Attachment.
Double click on the icon to open the attached file.';
        $pdf->SetFont('helvetica', '', 10);
        $pdf->Write(0, $txt, '', 0, 'L', true, 0, false, false, 0);
        // attach an external file TXT file
        $pdf->Annotation(20, 50, 5, 5, 'TXT file', array('Subtype' => 'FileAttachment', 'Name' => 'PushPin', 'FS' => 'tests/data/utf8test.txt'));
        // attach an external file
        $pdf->Annotation(50, 50, 5, 5, 'PDF file', array('Subtype' => 'FileAttachment', 'Name' => 'PushPin', 'FS' => 'tests/_expected_pdfs/example_012.pdf'));
        // add a bookmark that points to an embedded file
        // NOTE: prefix the file name with the * character for generic file and with % character for PDF file
        $pdf->Bookmark('TXT file', 0, 0, '', 'B', array(128, 0, 255), -1, '*utf8test.txt');
        // add a bookmark that points to an embedded file
        // NOTE: prefix the file name with the * character for generic file and with % character for PDF file
        $pdf->Bookmark('PDF file', 0, 0, '', 'B', array(128, 0, 255), -1, '%tests/_expected_pdfs/example_012.pdf');
        // add a bookmark that points to an external URL
        $pdf->Bookmark('External URL', 0, 0, '', 'B', array(0, 0, 255), -1, 'http://www.tcpdf.org');
        $this->comparePdfs($pdf);
    }
Example #5
0
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
    require_once dirname(__FILE__) . '/lang/eng.php';
    $pdf->setLanguageArray($l);
}
// ---------------------------------------------------------
// set font
$pdf->SetFont('times', '', 16);
// add a page
$pdf->AddPage();
$txt = 'Example of File Attachment.
Double click on the icon to open the attached file.';
$pdf->Write(0, $txt, '', 0, 'L', true, 0, false, false, 0);
// attach an external file
$pdf->Annotation(85, 27, 5, 5, 'text file', array('Subtype' => 'FileAttachment', 'Name' => 'PushPin', 'FS' => 'data/utf8test.txt'));
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('example_041.pdf', 'D');
//============================================================+
// END OF FILE
//============================================================+
$pdf->Bookmark('Chapter 3', 0, 0, '', 'B', array(0, 64, 128));
$pdf->Cell(0, 10, 'Chapter 3', 0, 1, 'L');
$pdf->AddPage();
$pdf->setDestination('chapter4', 0, '');
$pdf->SetFont('times', 'B', 20);
$pdf->Bookmark('Chapter 4', 0, 0, '', 'B', array(0, 64, 128));
$pdf->Cell(0, 10, 'Chapter 4', 0, 1, 'L');
$pdf->AddPage();
$pdf->Bookmark('Chapter 5', 0, 0, '', 'B', array(0, 128, 0));
$pdf->Cell(0, 10, 'Chapter 5', 0, 1, 'L');
$txt = 'Example of File Attachment.
Double click on the icon to open the attached file.';
$pdf->SetFont('helvetica', '', 10);
$pdf->Write(0, $txt, '', 0, 'L', true, 0, false, false, 0);
// attach an external file TXT file
$pdf->Annotation(20, 50, 5, 5, 'TXT file', array('Subtype' => 'FileAttachment', 'Name' => 'PushPin', 'FS' => '../cache/utf8test.txt'));
// attach an external file
$pdf->Annotation(50, 50, 5, 5, 'PDF file', array('Subtype' => 'FileAttachment', 'Name' => 'PushPin', 'FS' => 'example_012.pdf'));
// add a bookmark that points to an embedded file
// NOTE: prefix the file name with the * character for generic file and with % character for PDF file
$pdf->Bookmark('TXT file', 0, 0, '', 'B', array(128, 0, 255), -1, '*utf8test.txt');
// add a bookmark that points to an embedded file
// NOTE: prefix the file name with the * character for generic file and with % character for PDF file
$pdf->Bookmark('PDF file', 0, 0, '', 'B', array(128, 0, 255), -1, '%example_012.pdf');
// add a bookmark that points to an external URL
$pdf->Bookmark('External URL', 0, 0, '', 'B', array(0, 0, 255), -1, 'http://www.tcpdf.org');
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('example_015.pdf', 'I');
//============================================================+
// END OF FILE
Example #7
0
/**
 * Creates the PDF version (downloadable) of the whole feedback produced by the teacher/tutor
 *
 * @param unknown $draft            
 * @param unknown $student            
 * @param unknown $context            
 * @param unknown $cmid            
 * @return boolean
 */
function emarking_create_response_pdf($draft, $student, $context, $cmid)
{
    global $CFG, $DB;
    require_once $CFG->libdir . '/pdflib.php';
    $fs = get_file_storage();
    if (!($submission = $DB->get_record('emarking_submission', array('id' => $draft->submissionid)))) {
        return false;
    }
    if (!($pages = $DB->get_records('emarking_page', array('submission' => $submission->id, 'student' => $student->id), 'page ASC'))) {
        return false;
    }
    if (!($emarking = $DB->get_record('emarking', array('id' => $submission->emarking)))) {
        return false;
    }
    $numpages = count($pages);
    $sqlcomments = "SELECT ec.id,\n\t\t\tec.posx,\n\t\t\tec.posy,\n\t\t\tec.rawtext,\n\t\t\tec.pageno,\n\t\t\tgrm.maxscore,\n\t\t\tec.levelid,\n\t\t\tec.width,\n\t\t\tec.colour,\n\t\t\tec.textformat,\n\t\t\tgrl.score AS score,\n\t\t\tgrl.definition AS leveldesc,\n\t\t\tgrc.id AS criterionid,\n\t\t\tgrc.description AS criteriondesc,\n\t\t\tu.id AS markerid, CONCAT(u.firstname,' ',u.lastname) AS markername\n\t\t\tFROM {emarking_comment} AS ec\n\t\t\tINNER JOIN {emarking_page} AS ep ON (ec.draft = :draft AND ec.page = ep.id)\n\t\t\tLEFT JOIN {user} AS u ON (ec.markerid = u.id)\n\t\t\tLEFT JOIN {gradingform_rubric_levels} AS grl ON (ec.levelid = grl.id)\n\t\t\tLEFT JOIN {gradingform_rubric_criteria} AS grc ON (grl.criterionid = grc.id)\n\t\t\tLEFT JOIN (\n\t\t\tSELECT grl.criterionid, max(score) AS maxscore\n\t\t\tFROM {gradingform_rubric_levels} AS grl\n\t\t\tGROUP BY grl.criterionid\n\t\t\t) AS grm ON (grc.id = grm.criterionid)\n\t\t\tWHERE ec.pageno > 0\n\t\t\tORDER BY ec.pageno";
    $params = array('draft' => $draft->id);
    $comments = $DB->get_records_sql($sqlcomments, $params);
    $commentsperpage = array();
    foreach ($comments as $comment) {
        if (!isset($commentsperpage[$comment->pageno])) {
            $commentsperpage[$comment->pageno] = array();
        }
        $commentsperpage[$comment->pageno][] = $comment;
    }
    // Parameters for PDF generation
    $iconsize = 5;
    $tempdir = emarking_get_temp_dir_path($emarking->id);
    if (!file_exists($tempdir)) {
        mkdir($tempdir);
    }
    // create new PDF document
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    // set document information
    $pdf->SetCreator(PDF_CREATOR);
    $pdf->SetAuthor($student->firstname . ' ' . $student->lastname);
    $pdf->SetTitle($emarking->name);
    $pdf->SetSubject('Exam feedback');
    $pdf->SetKeywords('feedback, emarking');
    $pdf->SetPrintHeader(false);
    $pdf->SetPrintFooter(false);
    // set default header data
    $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 036', PDF_HEADER_STRING);
    // set header and footer fonts
    $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
    $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
    // set default monospaced font
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    // set margins
    $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
    $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
    // set auto page breaks
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    // set image scale factor
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    // set some language-dependent strings (optional)
    if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
        require_once dirname(__FILE__) . '/lang/eng.php';
        $pdf->setLanguageArray($l);
    }
    // ---------------------------------------------------------
    // set font
    $pdf->SetFont('times', '', 16);
    foreach ($pages as $page) {
        // add a page
        $pdf->AddPage();
        // get the current page break margin
        $bMargin = $pdf->getBreakMargin();
        // get current auto-page-break mode
        $auto_page_break = $pdf->getAutoPageBreak();
        // disable auto-page-break
        $pdf->SetAutoPageBreak(false, 0);
        // set bacground image
        $pngfile = $fs->get_file_by_id($page->file);
        $img_file = emarking_get_path_from_hash($tempdir, $pngfile->get_pathnamehash());
        $pdf->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
        // restore auto-page-break status
        // $pdf->SetAutoPageBreak($auto_page_break, $bMargin);
        // set the starting point for the page content
        $pdf->setPageMark();
        $dimensions = $pdf->getPageDimensions();
        if (isset($commentsperpage[$page->page])) {
            foreach ($commentsperpage[$page->page] as $comment) {
                $content = $comment->rawtext;
                $posx = (int) ((double) $comment->posx * $dimensions['w']);
                $posy = (int) ((double) $comment->posy * $dimensions['h']);
                if ($comment->textformat == 1) {
                    // text annotation
                    $pdf->Annotation($posx, $posy, 6, 6, $content, array('Subtype' => 'Text', 'StateModel' => 'Review', 'State' => 'None', 'Name' => 'Comment', 'NM' => 'Comment' . $comment->id, 'T' => $comment->markername, 'Subj' => 'example', 'C' => array(0, 0, 255)));
                } elseif ($comment->textformat == 2) {
                    $content = $comment->criteriondesc . ': ' . round($comment->score, 1) . '/' . round($comment->maxscore, 1) . "\n" . $comment->leveldesc . "\n" . get_string('comment', 'mod_emarking') . ': ' . $content;
                    // text annotation
                    $pdf->Annotation($posx, $posy, 6, 6, $content, array('Subtype' => 'Text', 'StateModel' => 'Review', 'State' => 'None', 'Name' => 'Comment', 'NM' => 'Mark' . $comment->id, 'T' => $comment->markername, 'Subj' => 'grade', 'C' => array(255, 255, 0)));
                } elseif ($comment->textformat == 3) {
                    $pdf->Image($CFG->dirroot . "/mod/emarking/img/check.gif", $posx, $posy, $iconsize, $iconsize, '', '', '', false, 300, '', false, false, 0);
                } elseif ($comment->textformat == 4) {
                    $pdf->Image($CFG->dirroot . "/mod/emarking/img/crossed.gif", $posx, $posy, $iconsize, $iconsize, '', '', '', false, 300, '', false, false, 0);
                }
            }
        }
    }
    // ---------------------------------------------------------
    // COGIDO PARA IMPRIMIR RÚBRICA
    if ($emarking->downloadrubricpdf) {
        $cm = new StdClass();
        $rubricdesc = $DB->get_recordset_sql("SELECT\n\t\td.name AS rubricname,\n\t\ta.id AS criterionid,\n\t\ta.description ,\n\t\tb.definition,\n\t\tb.id AS levelid,\n\t\tb.score,\n\t\tIFNULL(E.id,0) AS commentid,\n\t\tIFNULL(E.pageno,0) AS commentpage,\n\t\tE.rawtext AS commenttext,\n\t\tE.markerid AS markerid,\n\t\tIFNULL(E.textformat,2) AS commentformat,\n\t\tIFNULL(E.bonus,0) AS bonus,\n\t\tIFNULL(er.id,0) AS regradeid,\n\t\tIFNULL(er.motive,0) AS motive,\n\t\ter.comment AS regradecomment,\n\t\tIFNULL(er.markercomment, '') AS regrademarkercomment,\n\t\tIFNULL(er.accepted,0) AS regradeaccepted\n\t\tFROM {course_modules} AS c\n\t\tINNER JOIN {context} AS mc ON (c.id = :coursemodule AND c.id = mc.instanceid)\n\t\tINNER JOIN {grading_areas} AS ar ON (mc.id = ar.contextid)\n\t\tINNER JOIN {grading_definitions} AS d ON (ar.id = d.areaid)\n\t\tINNER JOIN {gradingform_rubric_criteria} AS a ON (d.id = a.definitionid)\n\t\tINNER JOIN {gradingform_rubric_levels} AS b ON (a.id = b.criterionid)\n\t\tLEFT JOIN (\n\t\tSELECT ec.*, d.id AS draftid\n\t\tFROM {emarking_comment} AS ec\n\t\tINNER JOIN {emarking_draft} AS d ON (d.id = :draft AND ec.draft = d.id)\n\t\t) AS E ON (E.levelid = b.id)\n\t\tLEFT JOIN {emarking_regrade} AS er ON (er.criterion = a.id AND er.draft = E.draftid)\n\t\tORDER BY a.sortorder ASC, b.score ASC", array('coursemodule' => $cmid, 'draft' => $draft->id));
        $table = new html_table();
        $data = array();
        foreach ($rubricdesc as $rd) {
            if (!isset($data[$rd->criterionid])) {
                $data[$rd->criterionid] = array($rd->description, $rd->definition . " (" . round($rd->score, 2) . " ptos. )");
            } else {
                array_push($data[$rd->criterionid], $rd->definition . " (" . round($rd->score, 2) . " ptos. )");
            }
        }
        $table->data = $data;
        // add extra page with rubrics
        $pdf->AddPage();
        $pdf->Write(0, 'Rúbrica', '', 0, 'L', true, 0, false, false, 0);
        $pdf->SetFont('helvetica', '', 8);
        $tbl = html_writer::table($table);
        $pdf->writeHTML($tbl, true, false, false, false, '');
    }
    // ---------------------------------------------------------
    $pdffilename = 'response_' . $emarking->id . '_' . $draft->id . '.pdf';
    $pathname = $tempdir . '/' . $pdffilename;
    if (@file_exists($pathname)) {
        unlink($pathname);
    }
    // Close and output PDF document
    $pdf->Output($pathname, 'F');
    // Copiar archivo desde temp a �rea
    $file_record = array('contextid' => $context->id, 'component' => 'mod_emarking', 'filearea' => 'response', 'itemid' => $student->id, 'filepath' => '/', 'filename' => $pdffilename, 'timecreated' => time(), 'timemodified' => time(), 'userid' => $student->id, 'author' => $student->firstname . ' ' . $student->lastname, 'license' => 'allrightsreserved');
    // Si el archivo ya existía entonces lo borramos
    if ($fs->file_exists($context->id, 'mod_emarking', 'response', $student->id, '/', $pdffilename)) {
        $previousfile = $fs->get_file($context->id, 'mod_emarking', 'response', $student->id, '/', $pdffilename);
        $previousfile->delete();
    }
    $fileinfo = $fs->create_file_from_pathname($file_record, $pathname);
    return true;
}
Example #8
0
/**
 * Creates the PDF version (downloadable) of the whole feedback produced by the teacher/tutor
 *
 * @param unknown $draft            
 * @param unknown $student            
 * @param unknown $context            
 * @param unknown $cmid            
 * @return boolean
 */
function emarking_create_response_pdf($draft, $student, $context, $cmid)
{
    global $CFG, $DB;
    require_once $CFG->libdir . '/pdflib.php';
    $fs = get_file_storage();
    if (!($submission = $DB->get_record('emarking_submission', array('id' => $draft->submissionid)))) {
        return false;
    }
    if (!($pages = $DB->get_records('emarking_page', array('submission' => $submission->id), 'page ASC'))) {
        return false;
    }
    if (!($emarking = $DB->get_record('emarking', array('id' => $submission->emarking)))) {
        return false;
    }
    $numpages = count($pages);
    $sqlcomments = "SELECT ec.id,\n\t\t\tec.posx,\n\t\t\tec.posy,\n\t\t\tec.rawtext,\n\t\t\tec.pageno,\n\t\t\tgrm.maxscore,\n\t\t\tec.levelid,\n\t\t\tec.width,\n\t\t\tec.colour,\n\t\t\tec.textformat,\n\t\t\tgrl.score AS score,\n\t\t\tgrl.definition AS leveldesc,\n\t\t\tgrc.id AS criterionid,\n\t\t\tgrc.description AS criteriondesc,\n\t\t\tu.id AS markerid, CONCAT(u.firstname,' ',u.lastname) AS markername\n\t\t\tFROM {emarking_comment} ec\n\t\t\tINNER JOIN {emarking_page} ep ON (ec.draft = :draft AND ec.page = ep.id)\n\t\t\tLEFT JOIN {user} u ON (ec.markerid = u.id)\n\t\t\tLEFT JOIN {gradingform_rubric_levels} grl ON (ec.levelid = grl.id)\n\t\t\tLEFT JOIN {gradingform_rubric_criteria} grc ON (grl.criterionid = grc.id)\n\t\t\tLEFT JOIN (\n\t\t\tSELECT grl.criterionid, max(score) AS maxscore\n\t\t\tFROM {gradingform_rubric_levels} grl\n\t\t\tGROUP BY grl.criterionid\n\t\t\t) AS grm ON (grc.id = grm.criterionid)\n\t\t\tWHERE ec.pageno > 0\n\t\t\tORDER BY ec.pageno";
    $params = array('draft' => $draft->id);
    $comments = $DB->get_records_sql($sqlcomments, $params);
    $commentsperpage = array();
    foreach ($comments as $comment) {
        if (!isset($commentsperpage[$comment->pageno])) {
            $commentsperpage[$comment->pageno] = array();
        }
        $commentsperpage[$comment->pageno][] = $comment;
    }
    // Parameters for PDF generation.
    $iconsize = 5;
    $tempdir = emarking_get_temp_dir_path($emarking->id);
    if (!file_exists($tempdir)) {
        emarking_initialize_directory($tempdir, true);
    }
    // Create new PDF document.
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    // Set document information.
    $pdf->SetCreator(PDF_CREATOR);
    $pdf->SetAuthor($student->firstname . ' ' . $student->lastname);
    $pdf->SetTitle($emarking->name);
    $pdf->SetSubject('Exam feedback');
    $pdf->SetKeywords('feedback, emarking');
    $pdf->SetPrintHeader(false);
    $pdf->SetPrintFooter(false);
    // Set default header data.
    $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 036', PDF_HEADER_STRING);
    // Set header and footer fonts.
    $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
    $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
    // Set default monospaced font.
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    // Set margins.
    $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
    $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
    // Set auto page breaks.
    $pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);
    // Set image scale factor.
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    // Set some language-dependent strings (optional).
    if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
        require_once dirname(__FILE__) . '/lang/eng.php';
        $pdf->setLanguageArray($l);
    }
    // Set font.
    $pdf->SetFont('times', '', 16);
    foreach ($pages as $page) {
        // Add a page.
        $pdf->AddPage();
        // Get the current page break margin.
        $bmargin = $pdf->getBreakMargin();
        // Get current auto-page-break mode.
        $autopagebreak = $pdf->getAutoPageBreak();
        // Disable auto-page-break.
        $pdf->SetAutoPageBreak(false, 0);
        // Set bacground image.
        $pngfile = $fs->get_file_by_id($page->file);
        $imgfile = emarking_get_path_from_hash($tempdir, $pngfile->get_pathnamehash());
        $pdf->Image($imgfile, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
        // Restore auto-page-break status.
        // Set the starting point for the page content.
        $pdf->setPageMark();
        $dimensions = $pdf->getPageDimensions();
        if (isset($commentsperpage[$page->page])) {
            foreach ($commentsperpage[$page->page] as $comment) {
                $content = $comment->rawtext;
                $posx = (int) ((double) $comment->posx * 210);
                $posy = (int) ((double) $comment->posy * 297);
                if ($comment->textformat == 1) {
                    // Text annotation.
                    $pdf->Annotation($posx, $posy, 6, 6, $content, array('Subtype' => 'Text', 'StateModel' => 'Review', 'State' => 'None', 'Name' => 'Comment', 'NM' => 'Comment' . $comment->id, 'T' => $comment->markername, 'Subj' => 'example', 'C' => array(0, 0, 255)));
                    $pdf->Bookmark(get_string('comment', 'mod_emarking') . ' ' . $comment->id, 0, $posy);
                } else {
                    if ($comment->textformat == 2) {
                        $feedback = strlen($comment->rawtext) > 0 ? "\n" . get_string('comment', 'mod_emarking') . ': ' . $comment->rawtext : '';
                        $content = $comment->criteriondesc . ': ' . round($comment->score, 1) . '/' . round($comment->maxscore, 1) . "\n" . $comment->leveldesc . $feedback;
                        // Text annotation.
                        $pdf->Annotation($posx, $posy, 6, 6, $content, array('Subtype' => 'Text', 'StateModel' => 'Review', 'State' => 'None', 'Name' => 'Comment', 'NM' => 'Mark' . $comment->id, 'T' => $comment->markername, 'Subj' => 'grade', 'C' => array(255, 255, 0)));
                        $pdf->Bookmark($comment->criteriondesc, 0, $posy);
                    } else {
                        if ($comment->textformat == 3) {
                            $pdf->Image($CFG->dirroot . "/mod/emarking/img/check.gif", $posx, $posy, $iconsize, $iconsize, '', '', '', false, 300, '', false, false, 0);
                        } else {
                            if ($comment->textformat == 4) {
                                $pdf->Image($CFG->dirroot . "/mod/emarking/img/crossed.gif", $posx, $posy, $iconsize, $iconsize, '', '', '', false, 300, '', false, false, 0);
                            }
                        }
                    }
                }
            }
        }
    }
    $pdffilename = 'response_' . $emarking->id . '_' . $draft->id . '.pdf';
    $pathname = $tempdir . '/' . $pdffilename;
    if (@file_exists($pathname)) {
        unlink($pathname);
    }
    // Close and output PDF document.
    $pdf->Output($pathname, 'F');
    // Copiar archivo desde temp a Area.
    $filerecord = array('contextid' => $context->id, 'component' => 'mod_emarking', 'filearea' => 'response', 'itemid' => $draft->id, 'filepath' => '/', 'filename' => $pdffilename, 'timecreated' => time(), 'timemodified' => time(), 'userid' => $student->id, 'author' => $student->firstname . ' ' . $student->lastname, 'license' => 'allrightsreserved');
    // Si el archivo ya existía entonces lo borramos.
    if ($fs->file_exists($context->id, 'mod_emarking', 'response', $draft->id, '/', $pdffilename)) {
        $previousfile = $fs->get_file($context->id, 'mod_emarking', 'response', $draft->id, '/', $pdffilename);
        $previousfile->delete();
    }
    $fileinfo = $fs->create_file_from_pathname($filerecord, $pathname);
    return true;
}
Example #9
0
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
$pdf->setLanguageArray($l);
//initialize document
$pdf->AliasNbPages();
// add a page
$pdf->AddPage();
// ---------------------------------------------------------
// set font
$pdf->SetFont('times', '', 16);
// print a line using Cell()
$pdf->Cell(0, 12, 'File Attachment', 1, 1, 'C');
// attach an external file
$pdf->Annotation(124, 28, 4, 4, 'text file', array('Subtype' => 'FileAttachment', 'Name' => 'PushPin', 'FS' => '../cache/utf8test.txt'));
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output("example_041.pdf", "I");
//============================================================+
// END OF FILE
//============================================================+