umanit/document-generator-bundle

This bundle is used to drive the document generator microservice developed by UmanIT: https://github.com/umanit/microservice-document-generator

1.0.0 2020-01-28 10:31 UTC

This package is auto-updated.

Last update: 2024-04-20 16:19:13 UTC


README

This bundle is used to drive the document generator microservice developed by UmanIT: https://github.com/umanit/microservice-document-generator

Installation

$ composer require umanit/document-generator-bundle

The bundle relies on HTTPlug to perform HTTP requests, so you will need to install a client implementation to use it. For example, the following will use the HTTPlug message factory and the Guzzle adapter.

$ composer require php-http/message php-http/guzzle6-adapter

Configuration

  • umanit_document_generator.base_uri: Base URI of the API used to generate documents.
  • umanit_document_generator.encryption_key: (Optional) Key used to crypt message before calling the API. It must match the one defined in the micro-service.

Usage

The only exposed service is umanit_document_generator.document_generator. It provides all the necessary methods to communicate with the micro-service API.

You can generate PNG or PDF using an URL or a HTML source code string.

Examples:

<?php

$generator = $container->get('umanit_document_generator.document_generator');

// Get a PNG of https://www.google.fr
$image = $generator->generatePngFromUrl('https://www.google.fr');

// Get a PDF from a HTML code source
$pdf = $generator->generatePdfFromHtml('<html><body>Hello World!</body></html>');

Each methods provides an additional parameter to specify other supported options by the micro-service, such as decode for HTML generation or pageOptions and scenario for both types.

Data encryption

By default, messages are not encrypted before calling the API. If you want to enable this feature, ensure you have define the umanit_document_generator.encryption_key configuration the same as in the micro-service then call the encryptData(true) method on the service. The encryption could be disabled the same way by calling encryptData(false).