项目作者: mtcextendee

项目描述 :
Badge PDF generator
高级语言: PHP
项目地址: git://github.com/mtcextendee/mautic-badge-generator-bundle.git


Mautic Badge Generator for Mautic

Plugin from Mautic Extension family (https://mtcextendee.com)

Download 7 ultimate free Mautic email themes https://mtcextendee.com/themes/

In general, plugin modify any PDF and add new text custom slots and barcode to PDF. Useful for your events.

Features

  • Add with custom text slots to PDF
    • Custom contact fields
    • Custom font-size, color and position
  • Add barcode to PDF
  • Token support - use link to badge in email/page ({badge=1})
  • Add to stage after download generate PDF
  • Generate custom PDF for each contacts from contact list
  • Display badge generator bundle just for contact with certain tags

Installation

Installation from command line:

  1. composer require mtcextendee/mautic-badge-generator-bundle
  2. php app/console mautic:plugins:reload

Manual installation is not allowed because plugins depend on another setasign/fpdi-tcpdf, which is installed automatically from command line.

Setup

Just go to plugins and enable new BadgeGenerator integration. Then you should see new column in left menu.

image

Generate PDF

In contact list

image

Before

image

After

image

API

Library: https://github.com/mautic/api-library

Hook

  1. $api = new \Mautic\Api\Api($auth, $apiUrl);
  2. $contactId = 1;
  3. $badgeId = 2;
  4. $response = $api->makeRequest(sprintf("badge/generator/%d/%d", $contactId, $badgeId));

Example for Basic Authorization:

  1. // Bootup the Composer autoloader
  2. include __DIR__.'/vendor/autoload.php';
  3. use Mautic\Auth\ApiAuth;
  4. $apiUrl = 'http://mautic.site';
  5. $settings = [
  6. 'userName' => 'admin',
  7. 'password' => 'mautic',
  8. ];
  9. $initAuth = new ApiAuth();
  10. $auth = $initAuth->newAuth($settings, 'BasicAuth');
  11. $api = new \Mautic\Api\Api($auth, $apiUrl);
  12. $contactId = 1;
  13. $badgeId = 2;
  14. $response = $api->makeRequest(sprintf("badge/generator/%d/%d", $contactId, $badgeId));
  15. if (isset($response['pdf'])) {
  16. $result = base64_decode($response['pdf']);
  17. // Write on file
  18. file_put_contents('test.pdf', $result);
  19. echo 'PDF created';
  20. } elseif (isset($response['errors'][0]['message'])) {
  21. echo $response['errors'][0]['message'];
  22. }

Response:

  • If badge exist for contact

$response['pdf'] = 'base64 encode of PDF content';

You need base64decode of PDF content and then process it (dispay or save..). For more info check: https://selectpdf.com/web-html-to-pdf-rest-api-for-php-samples/

  • If badge or contact not exist:

$response['errors']