如何从php代码生成pdf文件或在图像上打印文本


how to generate pdf file from php code or print text over image

我在暑期培训系统项目中工作,我想通过正常的html表格收集学生信息,这些表格将存储在数据库中

我有PDF文件的官方表格图片包含:名称:ID:公司:等…

我想从html表单中收集以上数据

如何移动收集到的数据,然后将其写在图像上(官方表格)?我可以把它保存成pdf格式吗?

我试着四处搜索,但没有找到我的ansower

使用以下代码在图像上打印。

<?php
  //Set the Content Type
  header('Content-type: image/jpeg');
  // Create Image From Existing File
  $jpg_image = imagecreatefromjpeg('sunset.jpg');
  // Allocate A Color For The Text
  $white = imagecolorallocate($jpg_image, 255, 255, 255);
  // Set Path to Font File
  $font_path = 'font.TTF';
  // Set Text to Be Printed On Image
  $text = "This is a sunset!";
  // Print Text On Image
  imagettftext($jpg_image, 25, 0, 75, 300, $white, $font_path, $text);
  // Send Image to Browser
  imagejpeg($jpg_image);
  // Clear Memory
  imagedestroy($jpg_image);
?>

您可以使用fpdf库从图像生成pdf