I have a php file with the following code that saves two images to server. How can I convert these two images into single pdf file before it gets saved into server so that pdf of this images get saved. Here is my php code.
<?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 and $file2 are the paths of two images.
This is what you need FPDF . It is a php class to generate pdf document. You can find tutorials on its website. Also a simple google search for your query would yield numerous results for same.
A sample usage:
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();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.