Pogodoc
Get Started

PHP

Get started with Pogodoc using PHP - from installation to your first document render

PHP Quickstart

Welcome! This guide will help you get started with Pogodoc using PHP. You'll learn how to install the SDK, authenticate, and generate your first document in minutes.

Prerequisites

Before you begin, make sure you have:

Quick Start Guide

Install the SDK

Install the Pogodoc SDK using Composer:

composer require pogodoc/pogodoc-php

Initialize the Client

Create a Pogodoc client with your API token. You can get your token from the API tokens page.

<?php

require __DIR__ . '/vendor/autoload.php';

use PogodocSdk\PogodocSdk;

$client = new PogodocSdk('<YOUR_API_TOKEN>');

Using Environment Variables

For better security, store your API token in an environment variable:

.env
POGODOC_API_TOKEN=your_token_here

The SDK will automatically read the POGODOC_API_TOKEN environment variable if no token is provided:

$client = new PogodocSdk();

Generate Your First Document

Now you're ready to generate a document! Here's a simple example using an EJS template:

<?php

require __DIR__ . '/vendor/autoload.php';

use PogodocSdk\PogodocSdk;

$client = new PogodocSdk();

$template = '
<!DOCTYPE html>
<html>
  <head>
    <title>Invoice</title>
    <style>
      body { font-family: Arial, sans-serif; }
      h1 { color: #333; }
    </style>
  </head>
  <body>
    <h1>Invoice for <%= customerName %></h1>
    <p>Amount: $<%= amount %></p>
    <p>Date: <%= date %></p>
  </body>
</html>
';

$data = [
    'customerName' => 'John Doe',
    'amount' => 1299.99,
    'date' => date('m/d/Y'),
];

$response = $client->generateDocument([
    'template' => $template,
    'data' => $data,
    'renderConfig' => [
        'type' => 'ejs',
        'target' => 'pdf',
    ]
]);

// Get the URL to your generated PDF
printf("Document URL: %s\n", $response->output->data->url);

Success!

Your document is now generated and available at the returned URL. The URL is publicly accessible and can be shared or downloaded.

Next Steps

Now that you've generated your first document, explore the detailed SDK documentation: