risscsolutions/printformer-php-sdk

SDK for the printformer API


README

License: MIT Latest Stable Version Total Downloads GitHub Workflow Status (event) GitHub Workflow Status (event)

Documentation

Installation

composer require risscsolutions/printformer-php-sdk

Usage

Create a new Instance of the printformer-SDK

use Rissc\Printformer;

$config = [
    'base_uri' => 'YOUR printformer URL',
    'identifier' => 'YOUR TENANT IDENTIFIER',
    'api_key' => 'YOUR TENANT API KEY',
];

$printformer = new Printformer($config);

Create a new User

$pfUser = $this->printformer->clientFactory()->user()->create([
    'first_name' => 'John',
    'last_name' => 'Doe',
    'locale' => 'en',
    'email' => 'john.doe@rissc.com', 
]);

Create a new Draft

by passing an array to the DraftClient

$draftClient = $printformer->clientFactory()->draft();
$draft = $draftClient
    ->create([
        'templateIdentifier' => 'YOUR MASTER TEMPLATE IDENTIFIER',
        'user_identifier' => $pfUser->getIdentifier(),
        'intent' => 'customize'
    ]);

or with a fluid builder

$draftBuilder = $printformer->builderFactory()->draft();
$draft = $draftBuilder
    ->template('YOUR MASTER TEMPLATE IDENTIFIER')
    ->user($pfUser->getIdentifier())
    ->intent('customize')
    ->create();

Create a URL to the Editor

$url = (string)$printformer->urlGenerator()->editor()
        ->draft($draft->getIdentifier())
        ->callback('https://YOUR-CALLBACK-URL-HERE')
        ->callbackCancel('https://YOUR-CANCEL-CALLBACK-URL-HERE') // Optional, if omitted the callback URL is used
        ->callbackHalt('https://YOUR-HALT-CALLBACK-URL-HERE') // Optional, if omitted the callbackCancel URL is used
        ->user($pfUser->getIdentifier())
        ->step('preview') // Optional, if omitted the editor jumps to the last visited step

Create a Print PDF

$printformer->clientFactory()->processing()->create(
    [$draft->getIdentifier(), $otherDraft->getIdentifier()],
    'https://YOUR-CALLBACK-URL-HERE'
);

Create a URL to the Print PDF

(string)$printformer->urlGenerator()
->draftFiles()
->printFile($draft->getIdentifier())
->expiresAt((new \DateTimeImmutable())->modify('+1 hour'))

Replicate a draft

$draftClient = $printformer->clientFactory()->draft();
$draft = $draftClient
    ->replicate($draft, []);