无法在Core PHP中使用FPDF生成所需的PDF模板

rvpgvaaj  于 2023-05-05  发布在  PHP
关注(0)|答案(1)|浏览(135)

这不应该重叠,它应该包含文本。
我需要设计的模板可能的情况是。
1.有时候,date可能比response有更多的行(如图所示)
1.有时响应的行数比日期多。
当前代码:

$data = $this->getExportData($survey_id, $question_id);
            
$pdf = new PDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 16);

// Add header with survey name
$pdf->Cell(0, 10, $survey_name, 0, 1, 'C');

// Add table with survey results
$pdf->SetFont('Arial', '', 12);
$pdf->SetFillColor(242, 242, 242);
$pdf->Cell(80, 10, 'Time', 1, 0, 'C', true);
$pdf->Cell(0, 10, 'Response', 1, 1, 'C', true);
$pdf->SetFont('Arial', '', 10);

// Add data
foreach ($data as $row) {
    $pdf->Cell(80, 10, $row['Date'], 1, 0, 'C');
    $pdf->WordWrap($text,80);
    $pdf->Cell(0, 10, $row['Response'], 1, 1, 'L');
    $pdf->WordWrap($text,0);
}
// Output the generated PDF to Browser
$pdf->Output();
pw9qyyiw

pw9qyyiw1#

你可以试试MultiCell

$data = $this->getExportData($survey_id, $question_id);

$pdf = new PDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 16);

// Add header with survey name
$pdf->Cell(0, 10, $survey_name, 0, 1, 'C');

// Add table with survey results
$pdf->SetFont('Arial', '', 12);
$pdf->SetFillColor(242, 242, 242);
$pdf->Cell(80, 10, 'Time', 1, 0, 'C', true);
$pdf->Cell(0, 10, 'Response', 1, 1, 'C', true);
$pdf->SetFont('Arial', '', 10);

// Add data
foreach ($data as $row) {
    $date = $row['Date'];
    $response = $row['Response'];
    $dateLines = $pdf->getNumLines($date, 80);
    $responseLines = $pdf->getNumLines($response, $pdf->GetPageWidth() - 80);
    $maxLines = max($dateLines, $responseLines);
    $pdf->MultiCell(80, $maxLines * 10, $date, 1, 'C');
    $pdf->MultiCell(0, $maxLines * 10, $response, 1, 'L');
}

// Output the generated PDF to Browser
$pdf->Output();

相关问题