Genera documenti (multipli)
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.
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
/api/v2/GenerateDocumentMultiplehttps://api.pdf4me.com/api/v2/GenerateDocumentMultipleIl nome dell'endpoint è GeneraDocumentoMultiplo (singolare) Documento), non GeneraDocumentiMultipli.
Informazioni importanti da non perdere
outputDocuments[]Nome file e una base64 streamFile (A volte contenuto del file, contenuto, O datiDecodifica ogni stringa base64 per salvare il file.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)
| Argomento | Stile | Separare |
|---|---|---|
| Endpoint | /api/v2/GenerateDocumentMultiple | /api/v2/GenerateDocumentSingle |
| templateFileType | Docx, HTML, PDF only | Also MailMerge, GoogleDocs |
| documentDataType | Json, XML only | Also Csv |
| outputType | PDF, Docx, xlsx (Word/PDF), HTML | No xlsx |
| Data shape | Typically array of records (one doc per row) | Usually one object |
| outputFileName | Integration-UI only (output naming) | Not in API body either |
Matrice variante (rilevante per Postman)
Modello (templateFileData)
| Codice | Fonte | Il valore del postino | È inoltre richiesto |
|---|---|---|---|
| T1 | Base64 | Base64 template (strip data:...;base64, prefix if present) | templateFileName |
| T2 | URL | HTTPS URL string | templateFileName |
| T3 | HTML code | Base64(UTF-8 HTML): Buffer.from(html, "utf8").toString("base64") | templateFileName, templateFileType: HTML |
Dati del documento
| Codice | Fonte | campo API | Il valore del postino |
|---|---|---|---|
| D1 | Text | documentDataText | JSON array (or XML with multiple records) |
| D2 | Base64 | documentDataFile | Base64 of the .json / .xml file |
| D3 | URL | documentDataFile | URL 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
templateFileType | Consentito tipo di output |
|---|---|
Docx | PDF, Docx, xlsx |
PDF | PDF, Docx, xlsx |
HTML | HTML only |
API campi corporei
Sempre inviato
| Campo | Necessario | Tipo | Note |
|---|---|---|---|
templateFileType | Yes | string | Docx, HTML, PDF |
templateFileName | Yes | string | e.g. template.docx, template.html, template.pdf |
templateFileData | Yes | string | Base64 template, or template URL |
documentDataType | Yes | string | Json or XML (exact casing) |
outputType | Yes | string | PDF, Docx, xlsx, or HTML |
IsAsync | Yes | boolean | true |
Dati del documento (un percorso)
| Campo | Richiesto quando | Tipo | Note |
|---|---|---|---|
documentDataText | D1 | string | Valid JSON (JSON.parse) or XML-like for XML |
documentDataFile | D2 or D3 | string | Base64 data file or URL |
Opzionale
| Campo | Quando | Predefinito |
|---|---|---|
KeepPdfEditable | outputType is PDF | false |
Regole di convalida
| Controllo | Dettaglio |
|---|---|
| Template URL / base64 | Same rules as Single. |
| HTML code | Only when templateFileType is HTML. |
| JSON text | Must parse with JSON.parse. |
| XML text | Looser than Single (no strict tag check); send XML the template expects. |
| Data source | documentDataFile or documentDataText is required. |
Struttura dei dati a record multipli
Per JSON, utilizzare un array di oggetti (un oggetto per ogni documento generato):
[
]
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
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
| Campo | T1+D1 | T2+D3 | T1+D2 | T3+D1 | output PDF |
|---|---|---|---|---|---|
templateFileType | Req | Req | Req | Req | Req |
templateFileName | Req | Req | Req | Req | Req |
templateFileData | Req (b64) | Req (URL) | Req (b64) | Req (b64) | Req |
documentDataType | Req | Req | Req | Req | Req |
outputType | Req | Req | Req | Req | Req |
documentDataText | Req | Omit | Omit | Req | Omit |
documentDataFile | Omit | Req | Req | Omit | Omit |
IsAsync | Req | Req | Req | Req | Req |
KeepPdfEditable | Opt | Opt | Opt | N/A* | Opt |
*Solo quando tipo di output È PDF.