<?php
// Include the main TCPDF library (search for installation path).
require_once('tcpdf_include.php');

// create new PDF document
//public function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false, $pdfa=false)
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$file = 'logo.png';
$date = date('Y-m-d');
//$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 038', PDF_HEADER_STRING);
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, '太子HQ分校', "熱線: 2612 4900/6182 2022\n香港太子砵蘭街450-454 HQ 7樓B室\n\n列印日期: " . $date);

// set header and footer fonts
// * @param $font (array) Array describing the basic font parameters: (family, style, size).
$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/chi.php')) {
    require_once(dirname(__FILE__) . '/lang/chi.php');
    $pdf->setLanguageArray($l);
}

// ---------------------------------------------------------
// add a page
$pdf->AddPage();

$pdf->SetFont('stsongstdlight', '', 20);

$html = '<html><head><meta http-equiv=Content-Type content="text/html; charset=UTF-8"></head>' .
        '<body>';
$pdf->writeHTML($html, true, false, false, false, 'L');
$html = '<div style="font-size: 20.1px; color: rgb(0,92,161);font-weight: normal; font-style: normal; text-decoration: none;"><span>練習四 — 修辭手法</span></div><div style="line-height:20%;">&nbsp;</div>';
$pdf->writeHTML($html, true, false, false, false, 'C'); //rgb(216, 236, 247)
$html = '<div style="padding:5em;background-color:rgb(216, 236, 247);font-size:16px;"><div style="line-height:20%;">&nbsp;</div>'
        . '<span style="display:block;color:rgb(58,93,162);"> 課程名稱：</span><span>P5 全科功課班（一 / 三 / 五）</span>'
        . '<div style="line-height:95%;">&nbsp;</div>'
        . '<span style="color:rgb(58,93,162);"> 練習日期：</span><span>2020-06-18</span>'
        . '</div>';
$pdf->writeHTML($html, true, false, false, true, 'L');
$html = '<div style="color:rgb(58,93,162);font-size:16px;"><span>練習題目</span><span>（</span><span>共</span><span>10</span><span>題</span><span>）</span><hr></div>';
$pdf->writeHTML($html, true, false, true, false, 'L');

//to be implemented...
$questions = array('', '', '', '', '', '',);
$idx = 1;
foreach ($questions as $k => $q) {
//    if ($idx > 5) {
//        $pdf->writeHTML('<br pagebreak="true"/>', true, false, false, false, 'L');
//    }
    $html = '<div style="font-size:16px;"><span>' . $idx . '.</span><span>「他的年紀比我大」的「大」字</span><span>，</span><span>屬於以下哪一種詞類</span><span>？</span></div><div style="line-height:20%;">&nbsp;</div>';
    $pdf->writeHTML($html, true, false, false, false, 'L');
    $html = '<div style="font-size:16px;">&nbsp;&nbsp;'
            . '<span>A. </span><span>量詞</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>B. </span><span>形容詞</span></div>'
            . '<div style="font-size:16px;line-height:80%;">&nbsp;&nbsp;'
            . '<span>C. </span><span>動詞</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>D. </span><span>代詞</span></div>'
            . '<div style="font-size:16px;line-height:60%;color:red;">&nbsp;'
            . '<span>（</span><span>答案</span><span>：B）</span><div style="color:rgb(58,93,162);">_______________________________________________________________________________</div></div>';
    $pdf->writeHTML($html, true, false, false, false, 'L');
    $idx++;
//$pdf->writeHTML('<div style="line-height:1%;">&nbsp;</div>',true,false,false,false,'L');
}



$html = '</body></html>';
$pdf->writeHTML($html, true, false, false, false, 'L');
//public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='')
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output(__DIR__ .'/exercise_'.$date.'.pdf', 'FI');

//============================================================+
// END OF FILE
//============================================================+
