Dokumente generieren (mehrere)
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.
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
/api/v2/GenerateDocumentMultipleDer Name des Endpunkts lautet: GenerierenSieMehrereDokumente (Singular) Dokumentieren), nicht GenerierenSieMehrereDokumenteDie
Wichtige Fakten, die Sie nicht verpassen sollten
outputDocuments[]Dateiname und ein Base64 streamFile (Manchmal Dateiinhalt, Inhalt, oder Daten). Um die Datei zu speichern, muss jede Base64-Zeichenkette dekodiert werden.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)
| Thema | Mehrere | Einzel |
|---|---|---|
| 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 |
Variantenmatrix (für Postman relevant)
Vorlage (templateFileData)
| Code | Quelle | Postman-Wert | Ebenfalls erforderlich |
|---|---|---|---|
| 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 |
Dokumentdaten
| Code | Quelle | API-Feld | Postman-Wert |
|---|---|---|---|
| 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 |
Verwenden Sie entweder documentDataText oder documentDataFile (Nicht verwendete Felder auslassen).
templateFileType → zulässiger Ausgabetyp
templateFileType | Erlaubt Ausgabetyp |
|---|---|
Docx | PDF, Docx, xlsx |
PDF | PDF, Docx, xlsx |
HTML | HTML only |
API Körperfelder
Immer gesendet
| Feld | Erforderlich | Typ | Anmerkungen |
|---|---|---|---|
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 |
Dokumentdaten (ein Pfad)
| Feld | Erforderlich, wenn | Typ | Anmerkungen |
|---|---|---|---|
documentDataText | D1 | string | Valid JSON (JSON.parse) or XML-like for XML |
documentDataFile | D2 or D3 | string | Base64 data file or URL |
Optional
| Feld | Wann | Standard |
|---|---|---|
KeepPdfEditable | outputType is PDF | false |
Validierungsregeln
| Überprüfen | Detail |
|---|---|
| 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. |
Datenstruktur mit mehreren Datensätzen
Für JSON, verwenden Sie ein Array von Objekten (ein Objekt pro generiertem Dokument):
[
]
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
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
| Feld | T1+D1 | T2+D3 | T1+D2 | T3+D1 | PDF-Ausgabe |
|---|---|---|---|---|---|
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 |
*Nur wenn Ausgabetyp Ist PDFDie