Passa al contenuto principale

Genera documenti (multipli)

Cosa fa questo endpoint

PDF4me Genera documenti (multipli) visualizza molti documenti in uno REST chiamata. Invia una sola parola, HTML, O PDF modello (Base64, URL, o crudo HTML) più un array di record (JSON O XML, come testo, Base64 file o URL). Restituisce un JSON elenco dei file generati (una voce per record) come Base64 In outputDocuments[].streamFileoppure un singolo valore binario a seconda della risposta.

Articoli correlati del blog
Non ci sono ancora post sul blog dedicati a questa funzionalità — in arrivo a breve.
Nel frattempo, dai un'occhiata al blog di PDF4me per trovare tutorial e procedure operative su tutte le piattaforme.
Visita il blog

Autenticazione del tuo API Richiesta

Ogni PDF4me REST la chiamata deve includere il tuo API chiave nel Authorization Intestazione come autenticazione di base. Ottieni o ruota la tua chiave dalla dashboard dello sviluppatore.

Punto finale

INVIARE/api/v2/GenerateDocumentMultiple

Il nome dell'endpoint è GeneraDocumentoMultiplo (singolare) Documento), non GeneraDocumentiMultipli.

Informazioni importanti da non perdere

Un unico modello, molti record
Invia un JSON matrice (o record ripetuto) XML) nel tuo payload di dati. Il motore genera un documento di output per ogni elemento dell'array e li restituisce insieme.
La risposta è solitamente JSON outputDocuments[]
Ogni voce ha un Nome file e una base64 streamFile (A volte contenuto del file, contenuto, O datiDecodifica ogni stringa base64 per salvare il file.
Differisce da Single: non sono consentiti file CSV e xlsx, meno tipi di modello
Tipi di modello limitati a Docx, HTML, PDF. I tipi di dati sono limitati a Json, XML. L'output aggiunge xlsx per Word / PDF modelli.

HTTP impostare

Metodo: INVIARE
URL: https://api.pdf4me.com/api/v2/GenerateDocumentMultiple
Tipo di contenuto: applicazione/json
Autorizzazione: Base <il tuo PDF4me API chiave>

Inviare IsAsync: true nel corpo. 200 potrebbe tornare JSON con outputDocuments[] o un singolo file binario. 202 restituisce un Posizione intestazione con un sondaggio URL.

Differenze rispetto a Genera documento (singolo)

ArgomentoStileSeparare
Endpoint/api/v2/GenerateDocumentMultiple/api/v2/GenerateDocumentSingle
templateFileTypeDocx, HTML, PDF onlyAlso MailMerge, GoogleDocs
documentDataTypeJson, XML onlyAlso Csv
outputTypePDF, Docx, xlsx (Word/PDF), HTMLNo xlsx
Data shapeTypically array of records (one doc per row)Usually one object
outputFileNameIntegration-UI only (output naming)Not in API body either

Matrice variante (rilevante per Postman)

Modello (templateFileData)

CodiceFonteIl valore del postinoÈ inoltre richiesto
T1Base64Base64 template (strip data:...;base64, prefix if present)templateFileName
T2URLHTTPS URL stringtemplateFileName
T3HTML codeBase64(UTF-8 HTML): Buffer.from(html, "utf8").toString("base64")templateFileName, templateFileType: HTML

Dati del documento

CodiceFontecampo APIIl valore del postino
D1TextdocumentDataTextJSON array (or XML with multiple records)
D2Base64documentDataFileBase64 of the .json / .xml file
D3URLdocumentDataFileURL to the data file

Utilizzare uno dei due documentoDatiTesto O file di dati del documento (omettere il campo non utilizzato).

templateFileType → tipo di output consentito

templateFileTypeConsentito tipo di output
DocxPDF, Docx, xlsx
PDFPDF, Docx, xlsx
HTMLHTML only

API campi corporei

Sempre inviato

CampoNecessarioTipoNote
templateFileTypeYesstringDocx, HTML, PDF
templateFileNameYesstringe.g. template.docx, template.html, template.pdf
templateFileDataYesstringBase64 template, or template URL
documentDataTypeYesstringJson or XML (exact casing)
outputTypeYesstringPDF, Docx, xlsx, or HTML
IsAsyncYesbooleantrue

Dati del documento (un percorso)

CampoRichiesto quandoTipoNote
documentDataTextD1stringValid JSON (JSON.parse) or XML-like for XML
documentDataFileD2 or D3stringBase64 data file or URL

Opzionale

CampoQuandoPredefinito
KeepPdfEditableoutputType is PDFfalse

Regole di convalida

ControlloDettaglio
Template URL / base64Same rules as Single.
HTML codeOnly when templateFileType is HTML.
JSON textMust parse with JSON.parse.
XML textLooser than Single (no strict tag check); send XML the template expects.
Data sourcedocumentDataFile or documentDataText is required.

Struttura dei dati a record multipli

Per JSON, utilizzare un array di oggetti (un oggetto per ogni documento generato):

[
{ "name": "Alice", "email": "[email protected]" },
{ "name": "Bob", "email": "[email protected]" }
]

Per XML, usa una struttura che il tuo modello si aspetta per le righe ripetute (stessa idea della stampa unione). API controlla soltanto che JSON analizza; il motore determina quanti documenti vengono prodotti.

API risposta (Postino)

Spesso in formato JSON:

{
"outputDocuments": [
{
"fileName": "document1.pdf",
"streamFile": "<base64>"
}
]
}

Il nome del campo può anche apparire come fileContent, content, O data. Decodifica ciascuno Base64 stringa per salvare ciascun file.

Esempi di carichi utili

1. Modello Word (base64) + JSON array (testo) → multiplo PDFs

{
"templateFileType": "Docx",
"templateFileName": "template.docx",
"templateFileData": "UEsDBBQAAAAI...",
"documentDataType": "Json",
"documentDataText": "[{\"name\": \"Alice\", \"email\": \"[email protected]\"}, {\"name\": \"Bob\", \"email\": \"[email protected]\"}]",
"outputType": "PDF",
"KeepPdfEditable": false,
"IsAsync": true
}

2. Modello Word (URL) + JSON dati (URL) → PDFs

{
"templateFileType": "Docx",
"templateFileName": "template.docx",
"templateFileData": "https://example.com/template.docx",
"documentDataType": "Json",
"documentDataFile": "https://example.com/customers.json",
"outputType": "PDF",
"IsAsync": true
}

3. Modello Word (base64) + JSON file (base64) → Excel (xlsx)

{
"templateFileType": "Docx",
"templateFileName": "template.docx",
"templateFileData": "UEsDBBQAAAAI...",
"documentDataType": "Json",
"documentDataFile": "W3sibmFtZSI6ICJBbGljZSJ9LCB7Im5hbWUiOiAiQm9iIn1d",
"outputType": "xlsx",
"IsAsync": true
}

documentDataFile = base64 di [{"name":"Alice"},{"name":"Bob"}].)

4. HTML modello (base64) + JSON matrice (testo) → HTML

{
"templateFileType": "HTML",
"templateFileName": "template.html",
"templateFileData": "PCFET0NUWVBFIGh0bWw+...",
"documentDataType": "Json",
"documentDataText": "[{\"title\": \"Invoice 1\", \"heading\": \"Hello\", \"content\": \"A\"}, {\"title\": \"Invoice 2\", \"heading\": \"Hi\", \"content\": \"B\"}]",
"outputType": "HTML",
"IsAsync": true
}

5. PDF modello (URL) + XML (testo) → multiplo PDFs

{
"templateFileType": "PDF",
"templateFileName": "template.pdf",
"templateFileData": "https://example.com/template.pdf",
"documentDataType": "XML",
"documentDataText": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><records><record><name>Alice</name></record><record><name>Bob</name></record></records>",
"outputType": "PDF",
"KeepPdfEditable": true,
"IsAsync": true
}

6. Modello Word (base64) + XML URL) → Word (Docx)

{
"templateFileType": "Docx",
"templateFileName": "template.docx",
"templateFileData": "UEsDBBQAAAAI...",
"documentDataType": "XML",
"documentDataFile": "https://example.com/data.xml",
"outputType": "Docx",
"IsAsync": true
}

Consigli per la raccolta del postino

Array data
Prefer a JSON array in documentDataText when documentDataType is Json and you expect more than one file.
Filename match
Match the extension in templateFileName to templateFileType.
Base64 of file
For D2, base64-encode the whole data file (not each row separately).
Decode response
If the response is JSON, decode each outputDocuments[].streamFile (or fileContent / content / data) from base64.
Endpoint name
Endpoint name is GenerateDocumentMultiple (singular Document), not GenerateDocumentsMultiple.

esempio di riccio

curl -X POST https://api.pdf4me.com/api/v2/GenerateDocumentMultiple \
-H "Content-Type: application/json" \
-H "Authorization: Basic YOUR_API_KEY" \
-d '{
"templateFileType": "Docx",
"templateFileName": "template.docx",
"templateFileData": "https://example.com/template.docx",
"documentDataType": "Json",
"documentDataText": "[{\"name\":\"Alice\"},{\"name\":\"Bob\"}]",
"outputType": "PDF",
"IsAsync": true
}' \
--output response.json

Riferimento rapido: obbligatorio vs facoltativo per variante

CampoT1+D1T2+D3T1+D2T3+D1output PDF
templateFileTypeReqReqReqReqReq
templateFileNameReqReqReqReqReq
templateFileDataReq (b64)Req (URL)Req (b64)Req (b64)Req
documentDataTypeReqReqReqReqReq
outputTypeReqReqReqReqReq
documentDataTextReqOmitOmitReqOmit
documentDataFileOmitReqReqOmitOmit
IsAsyncReqReqReqReqReq
KeepPdfEditableOptOptOptN/A*Opt

*Solo quando tipo di output È PDF.

Esempi di codice

FAQ

How is Multiple different from Single?+
Different endpoint (/api/v2/GenerateDocumentMultiple), fewer template types (Docx, HTML, PDF only), no CSV, can output xlsx, and expects array-shaped data to produce one document per record in a single call.
What does the response look like?+
Typically a JSON object with outputDocuments[], each containing fileName and streamFile (base64). Some responses may use fileContent, content, or data as the field name. Decode each base64 string to save the file.
Which output types are allowed?+
Docx and PDF templates accept PDF, Docx, or xlsx. HTML template accepts HTML only.
Does HTML output produce multiple files?+
Yes when the engine renders one HTML document per input record. The response still uses the outputDocuments[] shape.
What is the maximum array size?+
No published hard cap. Large batches usually push you onto the async path (202 + Location poll). For very large workloads, split into multiple calls of a few hundred records each.
Why is the endpoint name singular Document?+
The path is /api/v2/GenerateDocumentMultiple, not GenerateDocumentsMultiple. A common typo. The plural version returns 404.
Does KeepPdfEditable work for xlsx or HTML output?+
No. It only applies when outputType is PDF. For other outputs the API ignores it.
Can I mix multiple template files in one call?+
No. One call uses one template. To render the same data set against multiple templates, issue one call per template.

Azioni correlate

Stessa attività su altre piattaforme

Richiedi assistenza