Dokument generieren (Einzeln)
PDF4me Dokument generieren (Einzeln) Erzeugt ein einzelnes Dokument durch Zusammenführen einer Vorlage (Word, HTML, oder PDF) mit einer Datennutzlast (JSON, XML, oder CSV) in einem REST Anruf. Die Vorlage kann sein Base64, eine öffentliche URLoder roh HTMLDie Daten können als Inline-Text vorliegen, Base64-kodierte Datei oder eine URLGibt das gerenderte Ergebnis zurück PDF, Docx, oder HTML als Binärdaten (200) oder über eine Location-header poll URL (202).
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/GenerateDocumentSingleWichtige Fakten, die Sie nicht verpassen sollten
documentDataText oder documentDataFiledocumentDataText für Inline JSON / XML / CSV. Verwenden documentDataFile für ein Base64-kodierte Datendatei oder eine öffentliche URLDiePDF oder DocxHTML akzeptiert HTML Nur PDF-Dateien werden akzeptiert. PDF Nur. Die genaue Groß-/Kleinschreibung ist wichtig.IsAsync: true Die API kann mit dem Statuscode 202 und einem Location-Header antworten. GET Das URL (gleiche Autorisierung) bis 200 mit der gerenderten Datei (Standard) pdf4meAsyncRequest Muster).HTTP aufstellen
Verfahren: POST
URL: https://api.pdf4me.com/api/v2/GenerateDocumentSingle
Inhaltstyp: application/json
Genehmigung: Basic <Ihre PDF4me API Schlüssel>
Schicken IsAsync: true im Körper. 200 Gibt die gerenderten Dateibytes zurück. 202 gibt ein zurück Standort Überschrift mit einer Umfrage URL; GET Das URL mit demselben Authorization-Header bis 200.
Variantenmatrix (für Postman relevant)
Wählen Sie eine Template-Variante (T1 / T2 / T3) und eine Datenvariante (D1 / D2 / D3). Sechs Kombinationen decken jeden Anruf ab.
Vorlage (templateFileData)
| Code | Quelle | Postman-Wert in templateFileData | Ebenfalls erforderlich |
|---|---|---|---|
| T1 | Base64 | Base64 template file (strip data:...;base64, prefix if present) | templateFileName |
| T2 | URL | Full HTTPS URL string (not downloaded by the API request body) | templateFileName |
| T3 | HTML code | Base64-encoded UTF-8 HTML: Buffer.from(html, "utf8").toString("base64") | templateFileName, templateFileType: HTML |
Dokumentdaten (eines von zweien) API Felder)
| Code | Quelle | API-Feld | Postman-Wert |
|---|---|---|---|
| D1 | Text | documentDataText | Raw JSON / XML / CSV string |
| D2 | Base64 | documentDataFile | Base64 of the data file (strip data-URL prefix if present) |
| D3 | URL | documentDataFile | Full HTTPS URL to .json / .xml / .csv |
Regel: genau eines von documentDataText oder documentDataFile muss festgelegt werden. Lassen Sie das nicht verwendete Feld aus dem Textkörper weg.
Häufige Kombinationen
| # | Vorlage | Daten | Typische Verwendung |
|---|---|---|---|
| 1 | T1 Docx base64 | D1 JSON text | Word mail-merge to PDF |
| 2 | T2 Docx URL | D3 JSON URL | Hosted template + hosted data |
| 3 | T3 HTML | D1 JSON text | HTML mustache rendered to HTML / PDF |
| 4 | T1 PDF form | D2 JSON base64 | PDF template + encoded data file |
| 5 | T2 MailMerge URL | D1 XML text | Word merge fields + inline XML |
templateFileType → zulässiger Ausgabetyp
templateFileType | Erlaubt Ausgabetyp | Anmerkungen |
|---|---|---|
Docx | PDF, Docx | PDF4me Word template |
MailMerge | PDF, Docx | Mail merge Word |
GoogleDocs | PDF, Docx | Google Docs export style |
HTML | HTML only | Mustache in HTML |
PDF | PDF only | PDF form / template |
API Körperfelder
Immer gesendet
| Feld | Erforderlich | Typ | Anmerkungen |
|---|---|---|---|
templateFileType | Yes | string | Docx, HTML, PDF, MailMerge, GoogleDocs |
templateFileName | Yes | string | With extension, e.g. template.docx, template.html, template.pdf |
templateFileData | Yes | string | Base64 template, or template URL string |
documentDataType | Yes | string | Json, XML, or Csv (exact casing) |
outputType | Yes | string | PDF, Docx, or HTML (see allowed-output table above) |
IsAsync | Yes | boolean | true |
Dokumentdaten (ein Pfad)
| Feld | Erforderlich, wenn | Typ | Anmerkungen |
|---|---|---|---|
documentDataText | D1 (text) | string | Valid JSON when documentDataType is Json; XML must look like XML; CSV non-empty |
documentDataFile | D2 or D3 | string | Base64 data file or URL to data file |
Optional
| Feld | Wann | Standard |
|---|---|---|
KeepPdfEditable | outputType is PDF | false |
documentDataFile | D1 text path is used | Omitted |
documentDataText | D2 or D3 path is used | Omitted |
Validierungsregeln
| Überprüfen | Detail |
|---|---|
| Template URL | Non-empty, valid URL. |
| Template base64 | Non-empty after optional data-URL strip. |
| HTML code | Only when templateFileType is HTML. Empty is rejected. Auto-wraps <html> if missing. |
| JSON text | Must parse successfully with JSON.parse. |
| XML text | Must start with < and contain >. |
| CSV text | Non-empty after trim. |
| Either data source | documentDataFile or documentDataText is required. |
Platzhalterproben
| Artikel | Beispiel |
|---|---|
| Template URL (Docx) | https://example.com/template.docx |
| Template name | template.docx / template.html / template.pdf |
| Data URL (JSON) | https://example.com/data.json |
| Data file name | data.json |
| JSON text | {"name": "John Doe", "email": "[email protected]", "items": [{"product": "Widget", "price": 29.99}]} |
| XML text | <?xml version="1.0"?><root><name>John Doe</name></root> |
| CSV text | name,email\nJohn Doe,[email protected] |
| HTML template | <!DOCTYPE html>...{{title}}... |
Beispielnutzlasten
1. Word-Vorlage (base64) + JSON Text → PDF
{
"templateFileType": "Docx",
"templateFileName": "template.docx",
"templateFileData": "UEsDBBQAAAAI...",
"documentDataType": "Json",
"documentDataText": "{\"name\": \"John Doe\", \"email\": \"[email protected]\", \"items\": [{\"product\": \"Widget\", \"price\": 29.99}]}",
"outputType": "PDF",
"KeepPdfEditable": false,
"IsAsync": true
}
2. Word-Vorlage (URL) + JSON Daten (URL) → PDF
{
"templateFileType": "Docx",
"templateFileName": "template.docx",
"templateFileData": "https://example.com/template.docx",
"documentDataType": "Json",
"documentDataFile": "https://example.com/data.json",
"outputType": "PDF",
"KeepPdfEditable": false,
"IsAsync": true
}
3. Word-Vorlage (base64) + JSON Daten (Base64) → Wortausgabe
documentDataFile enthält die Base64-Kodierung der JSON Dateibytes (nicht das geparste Objekt).
{
"templateFileType": "Docx",
"templateFileName": "template.docx",
"templateFileData": "UEsDBBQAAAAI...",
"documentDataType": "Json",
"documentDataFile": "eyJuYW1lIjogIkpvaG4gRG9lIn0=",
"outputType": "Docx",
"IsAsync": true
}
4. HTML Vorlage (base64 von HTML Datei) + JSON Text → HTML
Für Rohkost HTML In Postman senden Sie die gleiche Nutzlast an n8n node würde: base64-kodiert HTML In templateFileDataDie
{
"templateFileType": "HTML",
"templateFileName": "template.html",
"templateFileData": "PCFET0NUWVBFIGh0bWw+...",
"documentDataType": "Json",
"documentDataText": "{\"title\": \"Invoice\", \"heading\": \"Hello\", \"content\": \"World\"}",
"outputType": "HTML",
"IsAsync": true
}
5. Serienbrieffunktion (URL) + XML Text → PDF
{
"templateFileType": "MailMerge",
"templateFileName": "template.docx",
"templateFileData": "https://example.com/template.docx",
"documentDataType": "XML",
"documentDataText": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root><name>John Doe</name><email>[email protected]</email></root>",
"outputType": "PDF",
"IsAsync": true
}
6. PDF Formularvorlage (base64) + CSV Text → PDF (bearbeitbar)
{
"templateFileType": "PDF",
"templateFileName": "template.pdf",
"templateFileData": "JVBERi0xLjQKJcfsj6IK...",
"documentDataType": "Csv",
"outputType": "PDF",
"KeepPdfEditable": true,
"IsAsync": true
}
7. Google Docs-Stil (base64) + JSON URL → Docx
{
"templateFileType": "GoogleDocs",
"templateFileName": "template.docx",
"templateFileData": "UEsDBBQAAAAI...",
"documentDataType": "Json",
"documentDataFile": "https://example.com/data.json",
"outputType": "Docx",
"IsAsync": true
}
Tipps zur Postboten-Abholung
curl-Beispiel
curl -X POST https://api.pdf4me.com/api/v2/GenerateDocumentSingle \
-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",
"documentDataFile": "https://example.com/data.json",
"outputType": "PDF",
"KeepPdfEditable": false,
"IsAsync": true
}' \
--output generated.pdf
Kurzübersicht: Erforderlich vs. Optional je nach Variante
| Feld | T1+D1 | T2+D3 | T1+D2 | T3+D1 | Jede PDF-Ausgabe |
|---|---|---|---|---|---|
templateFileType | Req | Req | Req | Req | Req |
templateFileName | Req | Req | Req | Req | Req |
templateFileData | Req (b64) | Req (URL) | Req (b64) | Req (b64 HTML) | Req |
documentDataType | Req | Req | Req | Req | Req |
outputType | Req | Req | Req | Req | Req |
documentDataText | Req | Omit | Omit | Req | Omit |
documentDataFile | Omit | Req (URL) | Req (b64) | Omit | Omit |
IsAsync | Req | Req | Req | Req | Req |
KeepPdfEditable | Opt | Opt | Opt | N/A* | Opt if PDF |
*PDF bearbeitbar halten gilt nur wenn Ausgabetyp Ist PDF; Die API Andernfalls erzwingt es den falschen Effekt.