:::

8-3-3 產出套用設定的PDF檔

您沒有觀看影片的權限

您沒有觀看影片的權限

請先登入,登入後,確認您的權限後,即可觀看影片。

  1. 修改 pdf_signup.php
    <?php
    use Xmf\Request;
    use XoopsModules\Tadtools\TadDataCenter;
    use XoopsModules\Tad_signup\Tad_signup_actions;
    use XoopsModules\Tad_signup\Tad_signup_data;
    /*-----------引入檔案區--------------*/
    require_once __DIR__ . '/header.php';
    
    /*--略--*/
    
    $TadDataCenter = new TadDataCenter('tad_signup');
    $TadDataCenter->set_col('pdf_setup_id', $id);
    $pdf_setup_col = $TadDataCenter->getData('pdf_setup_col', 0);
    $col_arr = explode(',', $pdf_setup_col);
    
    $col_count = count($col_arr);
    if (empty($col_count)) {
        $col_count = 1;
    }
    
    $h = 15;
    $w = 120 / $col_count;
    $maxh = 15;
    $pdf->Cell(15, $h, '編號', 1, 0, 'C');
    foreach ($col_arr as $col_name) {
        $pdf->Cell($w, $h, $col_name, 1, 0, 'C');
    }
    $pdf->Cell(55, $h, '簽名', 1, 1, 'C');
    
    $signup = Tad_signup_data::get_all($action['id'], null, true, true);
    // Utility::dd($signup);
    $i = 1;
    foreach ($signup as $signup_data) {
        $pdf->MultiCell(15, $h, $i, 1, 'C', false, 0, '', '', true, 0, false, true, $maxh, 'M');
        foreach ($col_arr as $col_name) {
            $pdf->MultiCell($w, $h, implode('、', $signup_data['tdc'][$col_name]), 1, 'C', false, 0, '', '', true, 0, false, true, $maxh, 'M');
        }
    
        $pdf->MultiCell(55, $h, '', 1, 'C', false, 1, '', '', true, 0, false, true, $maxh, 'M');
        $i++;
    }
    
    $pdf->Output("{$title}.pdf", 'D');
    

     

補充一:避免表格被切一半的作法(4~14行):

$i = 1;
foreach ($signup as $signup_data) {

    $pdf2 = clone $pdf;
    $pdf2->SetMargins(15, 0);
    $pdf2->AddPage();
    $pdf2->MultiCell(15, $h, $i, 1, 'C', false, 0, '', '', true, 0, false, true, $maxh, 'M');
    foreach ($col_arr as $col_name) {
        $pdf2->MultiCell($w, $h, implode('、', $signup_data['tdc'][$col_name]), 1, 'C', false, 0, '', '', true, 0, false, true, $maxh, 'M');
    }
    $pdf2->MultiCell(55, $h, '', 1, 'C', false, 1, '', '', true, 0, false, true, $maxh, 'M');
    $height = $pdf2->getY();
    $pdf2->deletePage($pdf2->getPage());
    $pdf->checkPageBreak($height);

    $pdf->MultiCell(15, $h, $i, 1, 'C', false, 0, '', '', true, 0, false, true, $maxh, 'M');
    foreach ($col_arr as $col_name) {
        $pdf->MultiCell($w, $h, implode('、', $signup_data['tdc'][$col_name]), 1, 'C', false, 0, '', '', true, 0, false, true, $maxh, 'M');
    }

    $pdf->MultiCell(55, $h, '', 1, 'C', false, 1, '', '', true, 0, false, true, $maxh, 'M');
    $i++;
}

條碼二:製作條碼

$BarcodeStyle = array(
    'border' => true,
    'hpadding' => 'auto',
    'vpadding' => 'auto',
    'fgcolor' => array(0, 0, 0),
    'bgcolor' => false, //array(255,255,255),
    'text' => true,
    'font' => 'helvetica',
    'fontsize' => 8,
    'stretchtext' => 4,
);
$pdf->write1DBarcode('條碼內容', 'C39', $pdf->GetX(), $pdf->GetY(), 50, 16, 0.4, $BarcodeStyle, 'N');

link to https://github.com/tadlearn/tad_signup/commit/d5ba2d733007205dcafe76f1b03beb991b080b24 \

 

link to https://github.com/tadlearn/tad_signup/commit/d5ba2d733007205dcafe76f1b03beb991b080b24 \


:::

搜尋

QR Code 區塊

https%3A%2F%2Ftad0616.net%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbdsn%3D1779%26tbsn%3D48

書籍目錄

展開 | 闔起

線上使用者

39人線上 (8人在瀏覽線上書籍)

會員: 0

訪客: 39

更多…