Zum Hauptinhalt springen

Dokumente generieren (mehrere)

Was dieser Endpunkt bewirkt

PDF4me Dokumente generieren (mehrere) stellt viele Dokumente in einem dar REST Anruf. Senden Sie ein einzelnes Wort. HTML, oder PDF Vorlage (Base64, URLoder roh HTML) plus ein Array von Datensätzen (JSON oder XML, als Text, Base64 Datei oder URLGibt ein zurück JSON Liste der generierten Dateien (ein Eintrag pro Datensatz) als Base64 In outputDocuments[].streamFileoder ein einzelner Binärwert, abhängig von der Antwort.

Verwandte Blog-Beiträge
Zu dieser Funktion gibt es noch keinen Blogbeitrag – folgt in Kürze.
Schauen Sie sich in der Zwischenzeit im PDF4me-Blog Tutorials und Arbeitsabläufe für alle Plattformen an.
Besuchen Sie den Blog

Authentifizierung Ihres API Anfrage

Jeder PDF4me REST Der Anruf muss Ihre API Schlüssel im Authorization Header als Basic Auth. Ihren Schlüssel erhalten oder ändern Sie ihn im Entwickler-Dashboard.

Endpunkt

POST/api/v2/GenerateDocumentMultiple

Der Name des Endpunkts lautet: GenerierenSieMehrereDokumente (Singular) Dokumentieren), nicht GenerierenSieMehrereDokumenteDie

Wichtige Fakten, die Sie nicht verpassen sollten

Eine Vorlage, viele Datensätze
Sende eine JSON Array (oder sich wiederholender Datensatz) XML) in Ihrer Datennutzlast. Die Engine erzeugt für jedes Array-Element ein Ausgabedokument und gibt diese zusammen zurück.
Die Antwort lautet normalerweise JSON outputDocuments[]
Jeder Eintrag hat eine Dateiname und ein Base64 streamFile (Manchmal Dateiinhalt, Inhalt, oder Daten). Um die Datei zu speichern, muss jede Base64-Zeichenkette dekodiert werden.
Unterschiede zu Single: Keine CSV- oder XLSX-Dateien erlaubt, weniger Vorlagentypen
beschränkt auf Vorlagentypen Docx, HTML, PDF. Datentypen beschränkt auf JSON, XMLAusgabe fügt hinzu xlsx für Word / PDF Vorlagen.

HTTP aufstellen

Verfahren: POST
URL: https://api.pdf4me.com/api/v2/GenerateDocumentMultiple
Inhaltstyp: application/json
Genehmigung: Basic <Ihre PDF4me API Schlüssel>

Schicken IsAsync: true im Körper. 200 kann zurückkehren JSON mit outputDocuments[] oder eine einzelne Binärdatei. 202 gibt ein zurück Standort Überschrift mit einer Umfrage URLDie

Unterschiede vs. Dokument generieren (Einzeln)

ThemaMehrereEinzel
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

Variantenmatrix (für Postman relevant)

Vorlage (templateFileData)

CodeQuellePostman-WertEbenfalls erforderlich
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

Dokumentdaten

CodeQuelleAPI-FeldPostman-Wert
D1TextdocumentDataTextJSON array (or XML with multiple records)
D2Base64documentDataFileBase64 of the .json / .xml file
D3URLdocumentDataFileURL to the data file

Verwenden Sie entweder documentDataText oder documentDataFile (Nicht verwendete Felder auslassen).

templateFileType → zulässiger Ausgabetyp

templateFileTypeErlaubt Ausgabetyp
DocxPDF, Docx, xlsx
PDFPDF, Docx, xlsx
HTMLHTML only

API Körperfelder

Immer gesendet

FeldErforderlichTypAnmerkungen
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

Dokumentdaten (ein Pfad)

FeldErforderlich, wennTypAnmerkungen
documentDataTextD1stringValid JSON (JSON.parse) or XML-like for XML
documentDataFileD2 or D3stringBase64 data file or URL

Optional

FeldWannStandard
KeepPdfEditableoutputType is PDFfalse

Validierungsregeln

ÜberprüfenDetail
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.

Datenstruktur mit mehreren Datensätzen

Für JSON, verwenden Sie ein Array von Objekten (ein Objekt pro generiertem Dokument):

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

Für XMLVerwenden Sie eine Struktur, die Ihre Vorlage für wiederholte Zeilen erwartet (dasselbe Prinzip wie beim Serienbriefversand). API prüft nur, ob JSON Die Engine analysiert die Daten; sie steuert, wie viele Dokumente erzeugt werden.

API Antwort (Postbote)

Oftmals JSON wie:

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

Der Feldname kann auch wie folgt erscheinen: fileContent, content, oder dataEntschlüsseln Sie jedes Element Base64 Zeichenkette zum Speichern jeder Datei.

Beispielnutzlasten

1. Word-Vorlage (base64) + JSON Array (Text) → mehrere 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. Word-Vorlage (URL) + JSON Daten (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. Word-Vorlage (base64) + JSON Datei (base64) → Excel (xlsx)

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

(documentDataFile = Base64 von [{"name":"Alice"},{"name":"Bob"}].)

4. HTML Vorlage (base64) + JSON array (text) → 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 Vorlage (URL) + XML (Text) → mehrere 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. Word-Vorlage (base64) + XML (URL) → Word (Docx)

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

Tipps zur Postboten-Abholung

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.

curl-Beispiel

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

Kurzübersicht: Erforderlich vs. Optional je nach Variante

FeldT1+D1T2+D3T1+D2T3+D1PDF-Ausgabe
templateFileTypeReqReqReqReqReq
templateFileNameReqReqReqReqReq
templateFileDataReq (b64)Req (URL)Req (b64)Req (b64)Req
documentDataTypeReqReqReqReqReq
outputTypeReqReqReqReqReq
documentDataTextReqOmitOmitReqOmit
documentDataFileOmitReqReqOmitOmit
IsAsyncReqReqReqReqReq
KeepPdfEditableOptOptOptN/A*Opt

*Nur wenn Ausgabetyp Ist PDFDie

Codebeispiele

Häufig gestellte Fragen

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.

Ähnliche Aktionen

Dieselbe Aufgabe auf anderen Plattformen

Hilfe erhalten