Zum Hauptinhalt springen

Dokument generieren (Einzeln)

Was dieser Endpunkt bewirkt

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).

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/GenerateDocumentSingle

Wichtige Fakten, die Sie nicht verpassen sollten

Entweder documentDataText oder documentDataFile
Es muss genau eine Datenquelle festgelegt werden, nicht beide mit Inhalt. documentDataText für Inline JSON / XML / CSV. Verwenden documentDataFile für ein Base64-kodierte Datendatei oder eine öffentliche URLDie
Der zulässige Ausgabetyp hängt vom Vorlagendateityp ab.
Docx, MailMerge, Google Docs akzeptieren PDF oder DocxHTML akzeptiert HTML Nur PDF-Dateien werden akzeptiert. PDF Nur. Die genaue Groß-/Kleinschreibung ist wichtig.
Async gibt 202 + Location-Header zurück
Mit 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)

CodeQuellePostman-Wert in templateFileDataEbenfalls erforderlich
T1Base64Base64 template file (strip data:...;base64, prefix if present)templateFileName
T2URLFull HTTPS URL string (not downloaded by the API request body)templateFileName
T3HTML codeBase64-encoded UTF-8 HTML: Buffer.from(html, "utf8").toString("base64")templateFileName, templateFileType: HTML

Dokumentdaten (eines von zweien) API Felder)

CodeQuelleAPI-FeldPostman-Wert
D1TextdocumentDataTextRaw JSON / XML / CSV string
D2Base64documentDataFileBase64 of the data file (strip data-URL prefix if present)
D3URLdocumentDataFileFull 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

#VorlageDatenTypische Verwendung
1T1 Docx base64D1 JSON textWord mail-merge to PDF
2T2 Docx URLD3 JSON URLHosted template + hosted data
3T3 HTMLD1 JSON textHTML mustache rendered to HTML / PDF
4T1 PDF formD2 JSON base64PDF template + encoded data file
5T2 MailMerge URLD1 XML textWord merge fields + inline XML

templateFileType → zulässiger Ausgabetyp

templateFileTypeErlaubt AusgabetypAnmerkungen
DocxPDF, DocxPDF4me Word template
MailMergePDF, DocxMail merge Word
GoogleDocsPDF, DocxGoogle Docs export style
HTMLHTML onlyMustache in HTML
PDFPDF onlyPDF form / template

API Körperfelder

Immer gesendet

FeldErforderlichTypAnmerkungen
templateFileTypeYesstringDocx, HTML, PDF, MailMerge, GoogleDocs
templateFileNameYesstringWith extension, e.g. template.docx, template.html, template.pdf
templateFileDataYesstringBase64 template, or template URL string
documentDataTypeYesstringJson, XML, or Csv (exact casing)
outputTypeYesstringPDF, Docx, or HTML (see allowed-output table above)
IsAsyncYesbooleantrue

Dokumentdaten (ein Pfad)

FeldErforderlich, wennTypAnmerkungen
documentDataTextD1 (text)stringValid JSON when documentDataType is Json; XML must look like XML; CSV non-empty
documentDataFileD2 or D3stringBase64 data file or URL to data file

Optional

FeldWannStandard
KeepPdfEditableoutputType is PDFfalse
documentDataFileD1 text path is usedOmitted
documentDataTextD2 or D3 path is usedOmitted

Validierungsregeln

ÜberprüfenDetail
Template URLNon-empty, valid URL.
Template base64Non-empty after optional data-URL strip.
HTML codeOnly when templateFileType is HTML. Empty is rejected. Auto-wraps <html> if missing.
JSON textMust parse successfully with JSON.parse.
XML textMust start with < and contain >.
CSV textNon-empty after trim.
Either data sourcedocumentDataFile or documentDataText is required.

Platzhalterproben

ArtikelBeispiel
Template URL (Docx)https://example.com/template.docx
Template nametemplate.docx / template.html / template.pdf
Data URL (JSON)https://example.com/data.json
Data file namedata.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 textname,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",
"documentDataText": "name,email\nJohn Doe,[email protected]",
"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

Body
Use raw JSON. The API does not accept form-data for this endpoint.
Base64 of data
For D2, base64-encode the whole .json / .xml / .csv file and put it in documentDataFile. Set documentDataType accordingly.
HTML template
For T3 in Postman: Buffer.from(html, "utf8").toString("base64"). Send the base64 in templateFileData with templateFileType: HTML.
Filename match
Match the extension in templateFileName to templateFileType: .docx for Word / MailMerge / GoogleDocs, .html for HTML, .pdf for PDF.
Save response
Save the response body as .pdf, .docx, or .html depending on outputType.

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

FeldT1+D1T2+D3T1+D2T3+D1Jede PDF-Ausgabe
templateFileTypeReqReqReqReqReq
templateFileNameReqReqReqReqReq
templateFileDataReq (b64)Req (URL)Req (b64)Req (b64 HTML)Req
documentDataTypeReqReqReqReqReq
outputTypeReqReqReqReqReq
documentDataTextReqOmitOmitReqOmit
documentDataFileOmitReq (URL)Req (b64)OmitOmit
IsAsyncReqReqReqReqReq
KeepPdfEditableOptOptOptN/A*Opt if PDF

*PDF bearbeitbar halten gilt nur wenn Ausgabetyp Ist PDF; Die API Andernfalls erzwingt es den falschen Effekt.

Codebeispiele

Häufig gestellte Fragen

Can I send both documentDataText and documentDataFile in one request?+
No. Exactly one data source must be set. Omit the unused field. Sending both with content is rejected by the validation layer.
Which output types are allowed for each templateFileType?+
Docx, MailMerge, and GoogleDocs accept PDF or Docx. HTML accepts HTML only. PDF accepts PDF only. The casing of outputType matters.
Does KeepPdfEditable apply to every request?+
No. It only applies when outputType is PDF. For HTML or Docx output the API forces false and ignores the flag.
How do I send raw HTML in Postman?+
Base64-encode the UTF-8 HTML string (Buffer.from(html, "utf8").toString("base64") or the equivalent in your language). Put the result in templateFileData with templateFileType: HTML.
How do I encode the data file for D2?+
Base64-encode the entire .json, .xml, or .csv file bytes, not the parsed object. Put the base64 string in documentDataFile and set documentDataType to match.
How does the async flow work?+
Send IsAsync true. If the API returns 200, the rendered file is in the body. If 202, read the Location header for a poll URL. GET that URL with the same Authorization. Poll until 200.
My template Base64 has a data: prefix. Do I strip it?+
Yes. The API expects raw Base64 in templateFileData. Strip any data:...;base64, prefix before posting. Same applies to documentDataFile.
What extension should the response file have?+
Match outputType: .pdf for PDF, .docx for Docx, .html for HTML.

Ähnliche Aktionen

Dieselbe Aufgabe auf anderen Plattformen

Hilfe erhalten