Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

generate pdf with php and attach external pdfs

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading