Genera documento (singolo)
PDF4me Genera documento (singolo) genera un singolo documento unendo un modello (Word, HTML, O PDF) con un payload di dati (JSON, XML, O CSV) in uno REST chiamata. Il modello può essere Base64, un pubblico URL, o crudo HTML. I dati possono essere testo in linea, un Base64-file codificato o un URL. Restituisce il rendering PDF, Docx, O HTML come binario (200) o tramite un Location-sondaggio di intestazione URL (202).
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 per sviluppatori.
Punto finale
/api/v2/GenerateDocumentSinglehttps://api.pdf4me.com/api/v2/GenerateDocumentSingleInformazioni importanti da non perdere
documentoDatiTesto O file di dati del documentodocumentoDatiTesto per in linea JSON / XML / CSV. Utilizzo file di dati del documento per un Base64-file di dati codificati o pubblico URL.PDF O Docx. HTML accetta HTML solo. PDF accetta PDF solo. La forma esatta delle maiuscole/minuscole è importante.IsAsync: true IL API potrebbe rispondere con 202 e un'intestazione Location. GET Quello URL (stessa autorizzazione) fino a 200 con il file renderizzato (standard) pdf4meAsyncRequest modello).HTTP impostare
Metodo: INVIARE
URL: https://api.pdf4me.com/api/v2/GenerateDocumentSingle
Tipo di contenuto: applicazione/json
Autorizzazione: Base <il tuo PDF4me API chiave>
Inviare IsAsync: true nel corpo. 200 restituisce i byte del file renderizzato. 202 restituisce un Posizione intestazione con un sondaggio URL; GET Quello URL con la stessa intestazione di autorizzazione fino al 200.
Matrice variante (rilevante per Postman)
Scegli una variante del modello (T1 / T2 / T3) e una variante dei dati (D1 / D2 / D3). Sei combinazioni coprono ogni chiamata.
Modello (templateFileData)
| Codice | Fonte | Valore del postino in templateFileData | È inoltre richiesto |
|---|---|---|---|
| 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 |
Dati del documento (uno dei due API campi)
| Codice | Fonte | campo API | Valore del postino |
|---|---|---|---|
| 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 |
Regola: esattamente uno di documentoDatiTesto O file di dati del documento deve essere impostato. Omettere il campo non utilizzato dal corpo.
Combinazioni comuni
| # | Modello | Dati | Uso tipico |
|---|---|---|---|
| 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 → tipo di output consentito
templateFileType | Consentito tipo di output | Note |
|---|---|---|
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 campi corporei
Sempre inviato
| Campo | Necessario | Tipo | Note |
|---|---|---|---|
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 |
Dati del documento (un percorso)
| Campo | Richiesto quando | Tipo | Note |
|---|---|---|---|
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 |
Opzionale
| Campo | Quando | Predefinito |
|---|---|---|
KeepPdfEditable | outputType is PDF | false |
documentDataFile | D1 text path is used | Omitted |
documentDataText | D2 or D3 path is used | Omitted |
Regole di convalida
| Controllo | Dettaglio |
|---|---|
| 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. |
Esempi segnaposto
| Articolo | Esempio |
|---|---|
| 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}}... |
Esempi di carichi utili
1. Modello Word (base64) + JSON testo → 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. Modello Word (URL) + JSON dati (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. Modello Word (base64) + JSON dati (base64) → output in formato parola
documentDataFile detiene la base64 del JSON byte del file (non l'oggetto analizzato).
{
"templateFileType": "Docx",
"templateFileName": "template.docx",
"templateFileData": "UEsDBBQAAAAI...",
"documentDataType": "Json",
"documentDataFile": "eyJuYW1lIjogIkpvaG4gRG9lIn0=",
"outputType": "Docx",
"IsAsync": true
}
4. HTML modello (base64 di HTML file) + JSON testo → HTML
Per crudo HTML in Postman, invia lo stesso payload n8n il nodo sarebbe: codificato in base64 HTML In templateFileData.
{
"templateFileType": "HTML",
"templateFileName": "template.html",
"templateFileData": "PCFET0NUWVBFIGh0bWw+...",
"documentDataType": "Json",
"documentDataText": "{\"title\": \"Invoice\", \"heading\": \"Hello\", \"content\": \"World\"}",
"outputType": "HTML",
"IsAsync": true
}
5. Stampa unione (URL) + XML testo → 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 modello del modulo (base64) + CSV testo → PDF (modificabile)
{
"templateFileType": "PDF",
"templateFileName": "template.pdf",
"templateFileData": "JVBERi0xLjQKJcfsj6IK...",
"documentDataType": "Csv",
"outputType": "PDF",
"KeepPdfEditable": true,
"IsAsync": true
}
7. Stile Google Docs (base64) + JSON URL → Docx
{
"templateFileType": "GoogleDocs",
"templateFileName": "template.docx",
"templateFileData": "UEsDBBQAAAAI...",
"documentDataType": "Json",
"documentDataFile": "https://example.com/data.json",
"outputType": "Docx",
"IsAsync": true
}
Consigli per la raccolta del postino
esempio di riccio
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
Riferimento rapido: obbligatorio vs facoltativo per variante
| Campo | T1+D1 | T2+D3 | T1+D2 | T3+D1 | Qualsiasi PDF in uscita |
|---|---|---|---|---|---|
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 |
*KeepPdfEditable si applica solo quando tipo di output È PDF; IL API altrimenti, le forze sono false.