Guida · API REST

Generare una presentazione PowerPoint da JSON e da un template

I Suoi numeri sono JSON, le slide sono un template PowerPoint che il Suo team mantiene. XGenerate oggi compila template Word dalla busta fields; i template PowerPoint con gli stessi segnaposto nominati vengono forniti come parte della Sua integrazione, così la stessa richiesta compila le slide e la presentazione torna come PPTX o PDF.

Perché non costruire la presentazione nel codice

  • Una libreria per slide trasforma ogni layout in un compito di programmazione; chi è responsabile della presentazione non può spostare un riquadro senza uno sviluppatore.
  • Automatizzare PowerPoint su un server aggiunge un'installazione di Office al Suo deployment e non è supportato per l'uso non presidiato.
  • Report mensili, presentazioni di offerta e dossier per il consiglio ripetono le stesse slide con numeri nuovi; copiarle a mano è la fonte degli errori.

La richiesta

L'API di oggi compila template Word: un MERGEFIELD per valore, una regione TableStart per tabella ripetuta, PDF o DOCX in risposta. I template PowerPoint vengono legati alla stessa busta come parte della Sua integrazione (tracciato come xgenerateio/xgenerate#366); oggi non è esposto alcun output PPTX né alcun endpoint per presentazioni, quindi l'esempio mostra la chiamata su template Word così com'è.

TOKEN=$(curl -sS https://auth.xgenerate.io/realms/xgenerate/protocol/openid-connect/token \
  -d grant_type=client_credentials \
  -d client_id="$XGENERATE_CLIENT_ID" \
  -d client_secret="$XGENERATE_CLIENT_SECRET" | jq -r .access_token)

# Today's call: a Word template with MERGEFIELD placeholders and a TableStart:kpis region.
cat > fields.json <<'JSON'
{
  "fields": [
    { "name": "report.title",  "value": "Quarterly review Q3 2026" },
    { "name": "report.period", "value": "July to September 2026" }
  ],
  "lists": [
    { "name": "kpis", "value": [
      { "fields": [ { "name": "label", "value": "Revenue" },       { "name": "value", "value": "CHF 1.2 M" } ] },
      { "fields": [ { "name": "label", "value": "New customers" }, { "name": "value", "value": "14" } ] }
    ] }
  ]
}
JSON

curl -sS https://api.xgenerate.io/v2/documents/generate \
  -H "Authorization: Bearer $TOKEN" \
  -F "file=@quarterly-review.docx" \
  -F "fields=@fields.json;type=application/json" \
  -F "format=PDF" \
  -o quarterly-review.pdf

# A PowerPoint template is bound to the same envelope as part of your integration;
# the API exposes no PPTX output today.

Da .NET

using System.Net.Http.Json;

using var http = new HttpClient();
http.DefaultRequestHeaders.Authorization = new("Bearer", token);

// Today's call fills a Word template over the JSON transport; a PowerPoint template
// bound as part of your integration takes the same envelope.
var request = new
{
    filename = "quarterly-review.docx",
    content = Convert.ToBase64String(await File.ReadAllBytesAsync("quarterly-review.docx")),
    format = "PDF",
    fields = new
    {
        fields = new[]
        {
            new { name = "report.title", value = "Quarterly review Q3 2026" },
            new { name = "report.period", value = "July to September 2026" }
        },
        lists = new[]
        {
            new
            {
                name = "kpis",
                value = new[]
                {
                    new { fields = new[] { new { name = "label", value = "Revenue" }, new { name = "value", value = "CHF 1.2 M" } } },
                    new { fields = new[] { new { name = "label", value = "New customers" }, new { name = "value", value = "14" } } }
                }
            }
        }
    }
};
var response = await http.PostAsJsonAsync(
    "https://api.xgenerate.io/v2/documents/generate", request);
response.EnsureSuccessStatusCode();

var result = await response.Content.ReadFromJsonAsync<GenerateResult>();
await File.WriteAllBytesAsync(result!.Filename, Convert.FromBase64String(result.Content));

record GenerateResult(string Filename, string Content, string Format);

La risposta

La chiamata multipart restituisce il PDF come byte grezzi; il trasporto JSON restituisce filename, content, format e warnings. Gli avvisi indicano i segnaposto per immagine, QR e carta intestata rimasti senza valore; i campi unione e le regioni senza dati vengono rimossi senza avviso. La richiesta riesce in ogni caso.

Cosa XGenerate non fa

Il PPTX oggi non è un formato di output dell'API: format è PDF o DOCX, i template sono file Word e non esiste un endpoint per presentazioni. Il supporto dei template PowerPoint, prima segnaposto di testo e tabella, grafici inizialmente esclusi, viene costruito come parte della Sua integrazione ed è tracciato come xgenerateio/xgenerate#366. Le presentazioni esistenti non vengono convertite; un template viene legato una volta e poi compilato a ogni richiesta.

Lo provi sul Suo template

Ci invii un file Word che usa oggi. Lo renderizziamo con i Suoi dati e Le restituiamo il PDF insieme al template adattato, così la Sua valutazione non deve aspettare noi.

Richiedi una demo

Guide correlate