Search code examples
phphtmlserver-side

Server side font resizing


I have this PHP file that can 'create' course certificates with custom names passed through $_GET.
The goal is to get the file output into any printable format and download all of the certificates in one (.zip) file.

The problem is that the name's width are dynamic, and the name must match div width.

This is a sample code:

<html>
    <head>
    </head>
    <body style="background-image: image; background-image-size: 100% 100%; width: 1200px; height: 1200px;">
       <div class="name_1" style="width: 250px; height: 80px; margin-top: 400px; margin-left: 500px;">
            <p><?php echo $_GET['name_1']; ?></p>
       </div>
       <div class="name_2" style="width: 250px; height: 80px; margin-top: 900px; margin-left: 500px;">
            <p><?php echo $_GET['name_2']; ?></p>
        </div>
    </body>

I have achieved this dynamic text resizing to fit div width with jQuery.

The big problem is that I need to load page by page for 100+ pages to get this dynamic text re-sizing...

So, is there any way of re-sizing all the pages names and download all of them in one click?


Solution

  • Grab the page screenshot(s) using wkhtmltopdf framework, documentation here. It will execute the script on page load, you even have parameter to prolong time for script execution.

    --javascript-delay (default to 200ms)
    

    You have a PHP interface, but you can simply use PHP exec this way:

    exec("wkhtmltopdf test.html output.pdf")
    

    For creating ZIP libraries, you can find examples here.