【问题标题】:Converting Images to pdf before saving to server using PHP在使用 PHP 保存到服务器之前将图像转换为 pdf
【发布时间】:2015-08-04 13:02:15
【问题描述】:

我有一个包含以下代码的 php 文件,它将两个图像保存到服务器。如何在将这两个图像保存到服务器之前将其转换为单个 pdf 文件,以便保存这些图像的 pdf。这是我的php代码。

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL ^ E_NOTICE);
$data1 = $_POST['data1'];
$data2 = $_POST['data2'];

if(isset($data1)){
$uri1 =  substr($data1,strpos($data1,",")+1);

$uri2 =  substr($data2,strpos($data2,",")+1);

$path =$_SERVER["DOCUMENT_ROOT"].'/divya/custom_product/sites/default/files/cart';
$id = "test";
$type ="order";
$file1 = $path .'/'.$id.'-'.$type.'1.png';  
$file2 = $path .'/'.$id.'-'.$type.'2.png';  
file_put_contents($file1, base64_decode($uri1));
file_put_contents($file2, base64_decode($uri2));
}
?>

$file1 和 $file2 是两张图片的路径。

【问题讨论】:

    标签: php


    【解决方案1】:

    这就是你需要的FPDF。它是一个生成pdf文档的php类。您可以在其网站上找到教程。此外,对您的查询进行简单的谷歌搜索也会产生大量相同的结果。

    示例用法:

    require(‘fpdf.php’);
    
    $image = dirname(__FILE__).DIRECTORY_SEPARATOR.’my_image.png';
    $pdf = new FPDF();
    $pdf->AddPage();
    $pdf->Image($image,20,40,170,170);
    $pdf->Output();
    

    【讨论】:

      猜你喜欢
      • 2013-12-21
      • 1970-01-01
      • 1970-01-01
      • 2018-01-28
      • 2013-01-04
      • 1970-01-01
      • 2017-01-23
      • 2015-06-29
      • 1970-01-01
      相关资源
      最近更新 更多