opensistemas-hub/cert-generator

Make Certs (PDF) from templates (PDF)

0.1.5 2019-08-26 08:47 UTC

This package is auto-updated.

Last update: 2025-02-26 21:21:33 UTC


README

Build Status codecov

Example usage:

<?php

require_once __DIR__ . '/vendor/autoload.php'; // Autoload files using Composer autoload


$vars = [
    'full_name'   => "Antonio Cortés",
    'course_name' => "Mi nombre de curso",

];

$settings = json_decode( __DIR__ . '/template1.json' , true );

$template = \Opensistemas\CertGenerator\Template::create( $settings, __DIR__ . '/test.pdf' ) ;

$template->generate( 'my.pdf', $vars  );

template1.json

{
  "pages": [
    {
      "template": {
        "page": 1
      },
      "elements": [
        {
          "type": "text",
          "x": 20,
          "y": 50,
          "value": "Hola Mundo",
          "font": {
            "size": 20,
            "color": "#cc0000"
          }
        },
        {
          "type": "text",
          "x": 20,
          "y": 70,
          "value": {
            "key": "course_name"
          },
          "font": {
            "size": 20,
            "color": "#cc0000"
          }
        },
        {
          "type": "textBox",
          "x": 10,
          "y": 100,
          "w": 190,
          "h": 30,
          "align": "C",
          "value": {
            "key": "full_name"
          },
          "font": {
            "size": 34,
            "color": "#00CC00"
          }
        }
      ]
    },
    {
      "template": {
        "page": 2
      },
      "elements": [
        {
          "type": "textBox",
          "x": 10,
          "y": 100,
          "w": 280,
          "h": 30,
          "align": "C",
          "value": {
            "key": "full_name"
          },
          "font": {
            "size": 34,
            "color": "#102030",
            "bg": "#ffffff"
          }
        }
      ]
    }
  ]
}