php - 使用 FPDF 时需要对齐顶部和环绕文本?

标签 php sql fpdf

您好,我正在使用 fpdf 自动生成 pdf 以从 sql 中读取数据>因为大部分内容都是从 db 中提取的,它是一段大约 300 字的段落..它没有被我在 fpdf 中制作的列包裹..它只是去作为单行..有没有什么方法可以在列中包装文本。输出图像附在帖子的末尾..还有一个问题,我如何自动将此 pdf 发送到电子邮件

   <?php

require('fpdf.php');

//Connect to your database
$link = mysql_connect('www.xxxxxxx.co.uk', 'xxxxxxx', 'xxxxxx');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}

//Create new pdf file
$pdf=new FPDF();

//Open file
$pdf->Open();

//Disable automatic page break
$pdf->SetAutoPageBreak(true);

//Add first page
$pdf->AddPage();

//set initial y axis position per page
$y_axis_initial = 25;

//print column titles for the actual page
$pdf->SetFillColor(232, 232, 232);
$pdf->SetFont('Arial', 'B', 12);
$pdf->SetY($y_axis_initial);
$pdf->SetX(5);
/*$pdf->Cell(30, 6, 'CODE', 1, 0, 'L', 1);
$pdf->Cell(30, 6, 'NAME', 1, 0, 'L', 1);
$pdf->Cell(30, 6, 'PRICE', 1, 0, 'R', 1);*/

$y_axis = $y_axis + $row_height;


mysql_select_db("web39-sdasdasd", $link);
$q = "SELECT qr_topics,start_of,differential_dia,things_not,investigations,risks FROM qr_table";
$result = mysql_query ($q, $link);

//initialize counter
$i = 0;

//Set maximum rows per page
$max = 25;

//Set Row Height
$row_height = 80;
$pdf->Cell(33, 6, '  ', 1, 0, 'L', 1);
$pdf->Cell(33, 6, 'Starting off', 1, 0, 'L', 1);
$pdf->Cell(33, 6, 'Differential diagnosis', 1, 0, 'L', 1);
$pdf->Cell(33, 6, 'Not to miss', 1, 0, 'L', 1);
$pdf->Cell(33, 6, 'Investigations', 1, 0, 'L', 1);
$pdf->Cell(33, 6, 'Risks', 1, 0, 'L', 1);

$y_axis =(35);

while($row = mysql_fetch_array($result))
{


    $cad = $row['qr_topics'];
    $pad = $row['start_of'];
    $nad = $row['differential_dia'];
    $vad = $row['things_not'];
    $sad = $row['investigations'];
    $tad = $row['risks'];

    $pdf->SetY($y_axis);
    $pdf->SetX(5);
    $pdf->Cell(33,80,$cad,1,0,'L',1);
    $pdf->Cell(33,80,$pad,1,0,'L',1);
    $pdf->Cell(33,80,$nad,1,0,'L',1);
    $pdf->Cell(33,80,$vad,1,0,'L',1);
    $pdf->Cell(33,80,$sad,1,0,'L',1);
    $pdf->Cell(33,80,$tad,1,0,'L',1);

    //Go to next row
    $y_axis = $y_axis + $row_height;
    $i = $i + 1;
}

mysql_close($link);

//Send file
$pdf->Output();
?>

输出如下图

enter image description here

最佳答案

$row_height = 80;
$pdf->Cell(33, 6, '  ', 1, 0, 'L', 1);
$pdf->Cell(33, 6, 'Starting off', 1, 0, 'L', 1);
$pdf->Cell(33, 6, 'Differential diagnosis', 1, 0, 'L', 1);
$pdf->Cell(33, 6, 'Not to miss', 1, 0, 'L', 1);
$pdf->Cell(33, 6, 'Investigations', 1, 0, 'L', 1);
$pdf->Cell(33, 6, 'Risks', 1, 0, 'L', 1);

从 L 变为 T 或 R

关于php - 使用 FPDF 时需要对齐顶部和环绕文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11125347/

相关文章:

php - Mysql 查询更新条目不起作用

php - 使用 FPDI 和 TCPDF 在 PDF 上添加图像

php - CSS 仅在短暂但明显的延迟后生效

基于 PHP MySQL 的近似匹配搜索

javascript - 在一个 ajax 帖子上发布表单和文本区域

sql - Teradata 中减和除外的区别

sql - 将分隔字符串匹配到表行

mysql - 从单个 SQL 查询返回聚合结果行

php - 将图像与 FPDF 中的文本对齐

php - 需要从mysql数据库显示图片到fpdf