【发布时间】:2015-11-19 00:18:32
【问题描述】:
很抱歉问这个问题,因为它让我困惑了很长时间使用 Codeigniter。 这就是我正在做的事情。 如下所示,我正在显示一个表单,其中有一个“下载”按钮。 此下载按钮应将该图像下载到 PDF 文件中,其中包含详细信息 上面写着(红框里的)。
这就是我正在做的过程。
- 使用 PHP 函数 imagecreatefromjpeg 动态创建图像(动态)。
- 下载/复制在 URL 中生成的图像并将其保存在服务器的文件夹中
- 使用 mpdf 引用动态创建的图像生成 PDF。
我现在可以像下面这样动态地创建一个图像。我可以在图像中写入文本的位置(请参阅图像中写入的 2015 年文本)
我的问题是,当我点击“下载”按钮时,它不应该显示 浏览器中的图像,但自动将其下载到服务器上的文件夹中,然后它调用函数 MPDF 将其转换为 PDF 文件。这可能吗?
代码:
这是用户点击“下载”按钮时调用的方法
public function download_pdf() {
$data['image'] = $this -> get_photo();
$this -> mpdf_convert_pdf();
}
这是动态创建图像的函数。创建后,它应该将其下载到服务器上的指定文件夹位置。
function get_photo(){
//Create an Image on the Fly
header('Content-Type: image/jpg');
$imgpath = site_url() . 'assets/images/2316.jpg';
$img = @imagecreatefromjpeg($imgpath);
$white = imagecolorallocate($img, 0, 0, 0);
$font_path = 'assets/fonts/arial.ttf';
$text = "2015!";
imagettftext($img, 100, 0, 300, 300, $white, $font_path, $text);
imagejpeg($img);
imagedestroy($img);
//Copy an Image from URL into a server folder
$content = file_get_contents('http://localhost/run_ms/ccertificates/get_photo');
file_put_contents('C:\xampp\htdocs\run_ms\assets\images\thumb\Test.png', $content);
}
这是将图像转换为 PDF 文件的部分。
public function mpdf_convert_pdf() {
include ('application/third_party/mpdf/mpdf.php');
$mpdf = new mPDF('c', 'Legal', '', '', 5, 5, 5, '5', '5', '0');
//Display output
$html = '<img src="C:\xampp\htdocs\run_ms\assets\images\thumb\Test.png">';
//display PDF file
$mpdf -> WriteHTML($html);
$mpdf -> Output('Converted_pdf', 'D');
exit ;
}
非常感谢您在我的这个查询中提供的任何输入。
【问题讨论】:
标签: php codeigniter pdf