2010-10-23 75 views
0

我正在一个脚本中,我必须根据给定的文本创建一个图像。在php中的图像处理和获得PDFof处理的图像

基本上我必须将这些文本放置在生成图像的各个位置。

直到我的工作完成。以下是该代码。

header ("Content-type: image/jpeg"); 
$handle = imagecreate(415, 588) or die ("Cannot Create image"); 

$inven_tory=imagecreatefromjpeg($_SERVER['DOCUMENT_ROOT'].'/thumb/editor/text_letter.jpg'); 
imagecopymerge($handle,$inven_tory,0,0,0,0,415,588,100); 

$bg_color = imagecolorallocate ($handle, 255, 255, 255); // 0 -255 
$txt_color = imagecolorallocate ($handle, 0, 0, 0); 


// The first parameter is our handle, then font size, rotation, starting X, starting Y, text color, font, and finally our text. 
imagettftext($handle, 15, 0, 10, 25, $txt_color, "fonts/" . $font, wordwrap($text1, 35, "\n", true)); 

// The first parameter is our handle, then font size, rotation, starting X, starting Y, text color, font, and finally our text. 
imagettftext($handle, 20, 0, 40, 120, $txt_color, "fonts/" . $font, wordwrap($text2, 13, "\n", true)); 

// The first parameter is our handle, then font size, rotation, starting X, starting Y, text color, font, and finally our text. 
imagettftext($handle, 15, 0, 10, 500, $txt_color, "fonts/" . $font, wordwrap($text3, 40, "\n", true)); 

imagejpeg($handle); 

图片正在从本页面正确创建。现在我将这个生成的图像放在PDF中,并让用户保存该PDF。我怎样才能做到这一点?如果你不清楚,请告诉我。

回答

0

我会尝试使用exec()的wkhtmltodpf。

0

如果你是一个Linux服务器与ImageMagick的安装,你可以这样做:你打算如何创建PDF

exec("convert foo.jpg bar.pdf"); 
0

你如何放置在PDF图像依赖。有扩展和PHP类,允许您直接创建PDF(CPDF,FPDF,TCPDF)。还有一些类和程序允许您从HTML文档创建PDF。 PDF类为您提供更精确的控制,HTML到PDF类使它更易于使用,因为大多数PHP开发人员已经在某种程度上已经了解了HTML。你的情况很简单,我倾向于使用PDF生成类。

您不指定如何获取$ text1,$ text2和$ text3的值。据推测它们是由用户提供的。所以你想要的是一个收集用户输入并创建PDF的中间PHP。然后,您使用完整的URL引用图像生成PHP。像下面的内容会(使用EZPDF + CPDF)工作:

<?php 
include ('class.ezpdf.php'); 
$pdf = new Cezpdf(); 
$pdf->ezImage('http://example.com/image.php?text1='.urlencode($text1)); 
$pdf->ezStream(); 
?> 

我通常与DOMPDF,其中HTML文档转换为PDF文档工作。使用这个库的情况也是如此简单:

<?php 
require_once('dompdf_config.inc.php'); 
$dompdf = new DOMPDF(); 
$dompdf->load_html('http://example.com/image.php?text1='.urlencode($text1)); 
$dompdf->render(); 
$dompdr->stream(); 
?>