php - 使用 FPDF 在图像上写入文本

标签 php fpdf

我想生成 PDF。 我正在使用 FPDF 生成 pdf 文件。 我生成包含内容文本和图像的 pdf。 现在我想将图像作为背景图像。 所以场景是文本位于图像之上。我尝试了很多解决方案,但任何解决方案都适合我。我使用下面的代码生成了 PDF。

$pdf = new FPDF();
$title = 'Without User Details';
$img_title = 'Your Voucher Image is-:  ';
$php2pdf = '';
$php2pdf .= 'Your Voucher Code is-:  ';
$php2pdf .= $voucher_prefix;
$php2pdf .= get_post_meta($post->ID, 'voucher_start_digit', true);

 if (has_post_thumbnail( $post->ID ) ):
 $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
 $image_url = $image[0];
 endif;

$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->SetTitle($title);
$pdf->MultiCell($w, $h, $title);
$pdf->Ln(3);
$pdf->Cell(90,90,$php2pdf);
$pdf->Ln(20);
$pdf->MultiCell(40, 10, $img_title);
$pdf->Image($image_url,30,60,90,0); ob_start();
$pdf->Output();
ob_end_flush();

最佳答案

试试这个方法,效果不错

[![require_once('fpdf/fpdf.php');  
$pdf = new FPDF(); 


$pdf->AddPage();
$pdf->Image('PC_Letterhead.jpg',0,0,210,0); ob_start();
$pdf->SetFont('Arial','B',22);
 $pdf->Cell(0,20,'Your Shipping',0,1); 
$pdf->SetFont('Arial','',12); 

          $pdf->SetFillColor(224,224,224); //Set background of the cell to be that grey color
           $pdf->Cell(40,12,"Label",1,0,'C',true);
          $pdf->Cell(40,12,"Quanitity",1,1,'C',true); //the 1 before the 'C' instead of 0 in previous lines tells it to move down by the height of the cell after writing this
           $pdf->Cell(40,12,"SIZE",1,0,'C');
          $pdf->Cell(40,12,"1",1,1,'C');
            $pdf->Cell(40,12,"COLOR",1,0,'C');
          $pdf->Cell(40,12,"2",1,1,'C');
            $pdf->Cell(40,12,"NECK",1,0,'C');
          $pdf->Cell(40,12,"3",1,1,'C');
            $pdf->Cell(40,12,"HANDLE",1,0,'C');
          $pdf->Cell(40,12,"4",1,1,'C');
            $pdf->Cell(40,12,"VENTS",1,0,'C');
          $pdf->Cell(40,12,"5",1,1,'C');
$pdf->Output();
ob_end_flush();][1]][1]

关于php - 使用 FPDF 在图像上写入文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37893796/

相关文章:

php - 如何通过 php 中的 while 循环回显数据库中的所有 MySQL 表标题

php - Codeigniter 查询 count() 连接三个表的评论总数

php - 运行 linux 命令以通过 PHP 输出到文本文件

fpdf - tFDPF 中 AddFont 调用的顺序生成错误

php - 将数据写入文件在行尾添加 ^M

javascript - 加速从 sql 数据库加载选择选项

php - 我只能下载表头,不能下载FPDF中MYSQL数据库的数据

mysql - 根据内容长度从具有动态列宽的mysql生成pdf

使用 FPDF 的 PHP 转 PDF 无法打开我的 pdf 文件(损坏)

php - 在 FPDF 中生成换行符