skip to Main Content
First Name Last Name File Location
Andy Lee
Jason Hulce
Ibrahim Muhammad

I am trying to make an E-certificate for all the user that are listed in the table. I have imported the data into my database(phpmyadmin).

I have design a Microsoft Word certificate, just wondering is it possible to insert the name of the participant in the file and convert it into a pdf? There are around 500 participants and if I am to update one by one in word it is time consuming.

I am trying to do it in PHP and JS. Do you guys have any other idea on how to make this work?

2

Answers


  1. Use this library, you can create and word document and pdf. https://phpspreadsheet.readthedocs.io/en/latest/

    Login or Signup to reply.
  2. Yes you can do it using class named ZipArchive.

    I am adding a sample code. You can change it according to your needs.

    <?php
    $template_file_name = 'certificate.docx';
    $rand_no = rand(111111, 999999);
    $fileName = $rand_no . ".docx";
    $folder   = "results";
    $full_path = $folder . '/' . $fileName;
    try
    {
        if (!file_exists($folder))
        {
            mkdir($folder);
        }
        //Copy the Template file to the Result Directory
        copy($template_file_name, $full_path);
        // add calss Zip Archive
        $zip_val = new ZipArchive;
        //Docx file is nothing but a zip file. Open this Zip File
        if($zip_val->open($full_path) == true)
        {
            // In the Open XML Wordprocessing format content is stored.
            // In the document.xml file located in the word directory.
            $key_file_name = 'word/document.xml';
            $message = $zip_val->getFromName($key_file_name);
            $timestamp = date('d-M-Y H:i:s');
            // this data Replace the placeholders with actual values
            $message = str_replace("full_name",      "John Doe",       $message);
            $message = str_replace("email_address",  "[email protected]",  $message);
            //Replace the content with the new content created above.
            $zip_val->addFromString($key_file_name, $message);
            $zip_val->close();
        }
    }
    catch (Exception $exc) 
    {
        $error_message =  "Error creating the Word Document";
        var_dump($exc);
    }
    ?>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search