Passa al contenuto principale

Genera documento (singolo)

Cosa fa questo endpoint

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

Articoli correlati del blog
Non ci sono ancora post sul blog dedicati a questa funzionalità — in arrivo a breve.
Nel frattempo, dai un'occhiata al blog di PDF4me per trovare tutorial e procedure operative su tutte le piattaforme.
Visita il blog

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

INVIARE/api/v2/GenerateDocumentSingle

Informazioni importanti da non perdere

O documentoDatiTesto O file di dati del documento
Deve essere impostata esattamente una fonte di dati, non entrambe con contenuto. Utilizzare documentoDatiTesto per in linea JSON / XML / CSV. Utilizzo file di dati del documento per un Base64-file di dati codificati o pubblico URL.
Il tipo di output consentito dipende dal tipo di file del modello.
Sono accettati i formati Docx, MailMerge e Google Docs. PDF O Docx. HTML accetta HTML solo. PDF accetta PDF solo. La forma esatta delle maiuscole/minuscole è importante.
La funzione asincrona restituisce 202 + intestazione Location
Con 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)

CodiceFonteValore del postino in templateFileDataÈ inoltre richiesto
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

Dati del documento (uno dei due API campi)

CodiceFontecampo APIValore del postino
D1TextdocumentDataTextRaw JSON / XML / CSV string
D2Base64documentDataFileBase64 of the data file (strip data-URL prefix if present)
D3URLdocumentDataFileFull 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

#ModelloDatiUso tipico
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 → tipo di output consentito

templateFileTypeConsentito tipo di outputNote
DocxPDF, DocxPDF4me Word template
MailMergePDF, DocxMail merge Word
GoogleDocsPDF, DocxGoogle Docs export style
HTMLHTML onlyMustache in HTML
PDFPDF onlyPDF form / template

API campi corporei

Sempre inviato

CampoNecessarioTipoNote
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

Dati del documento (un percorso)

CampoRichiesto quandoTipoNote
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

Opzionale

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

Regole di convalida

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

Esempi segnaposto

ArticoloEsempio
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}}...

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",
"documentDataText": "name,email\nJohn Doe,[email protected]",
"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

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.

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

CampoT1+D1T2+D3T1+D2T3+D1Qualsiasi PDF in uscita
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

*KeepPdfEditable si applica solo quando tipo di output È PDF; IL API altrimenti, le forze sono false.

Esempi di codice

FAQ

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.

Azioni correlate

Stessa attività su altre piattaforme

Richiedi assistenza