I want to generate a pdf file with specific user information that I have stored on a mysql database, and add to it external pdf files that are stored on the server (these external files belong to the same user ). I’ve tried doing it using TCPDF but it doesn’t have the feature of adding external pdf files to the generated file. How can I achieve this?
>Solution :
I suggest you to use library libmergepdf you can find it online, with that plugin you can add page PDF to your original PDF, so save tcpdf in a temp folder then add pages from other PDF and save the final output like:
require_once('./vendor/autoload.php');
use iio\libmergepdf\Merger;
use iio\libmergepdf\Driver\TcpdiDriver;
$query = $mysqli->prepare("SELECT * FROM document"); //query of files
$query->execute();
$result = $query->get_result();
$merger = new Merger(new TcpdiDriver);
$merger->addFile($_SERVER['DOCUMENT_ROOT'] . '/files/temp/' . $nameFile); //original path PDF
while ($document = $result->fetch_array()) {
$pdf = $_SERVER['DOCUMENT_ROOT'] . $document['urlfile'];
if (is_file($pdf)) {
$merger->addFile($pdf);
}
}
ob_end_clean();
ob_start();
$merger->merge();