Lewati ke konten utama

Buat Dokumen (Tunggal)

Fungsi dari endpoint ini

PDF4me Buat Dokumen (Tunggal) menghasilkan satu dokumen dengan menggabungkan templat (Word, HTML, atau PDF) dengan muatan data (JSON, XML, atau CSV) dalam satu REST panggilan. Templatnya bisa berupa Base64, publik URLatau mentah HTMLData tersebut dapat berupa teks sebaris, atau Base64file yang dienkode, atau URLMengembalikan hasil render. PDF, Dokumenx, atau HTML sebagai biner (200) atau melalui sebuah Location-jajak pendapat header URL (202).

Postingan Blog Terkait
Belum ada postingan blog untuk fitur ini — akan segera hadir.
Sementara itu, jelajahi blog PDF4me untuk menemukan tutorial dan alur kerja di berbagai platform.
Kunjungi blog ini

Memverifikasi Identitas Anda API Meminta

Setiap PDF4me REST panggilan harus menyertakan Anda API kunci di Authorization Header sebagai otentikasi Dasar. Dapatkan atau putar kunci Anda dari dasbor pengembang.

Titik akhir

POS/api/v2/GenerateDocumentSingle

Fakta Penting yang Tidak Boleh Anda Lewatkan

Salah satu documentDataText atau documentDataFile
Hanya satu sumber data yang harus diatur, bukan keduanya dengan konten. Gunakan documentDataText untuk inline JSON / XML / CSV. Menggunakan documentDataFile untuk sebuah Base64berkas data yang dikodekan atau publik URL.
Tipe output yang diizinkan bergantung pada tipe file templat.
Format Docx, MailMerge, dan GoogleDocs diterima. PDF atau DokumenxHTML menerima HTML hanya PDF yang menerima PDF hanya itu. Penulisan huruf besar dan kecil sangat penting.
Async mengembalikan 202 + header Lokasi
Dengan IsAsync: true itu API Mungkin akan merespons dengan kode 202 dan header Lokasi. GET itu URL (Otorisasi yang sama) hingga 200 dengan file yang dirender (standar) pdf4meAsyncRequest pola).

HTTP pengaturan

Metode: POS
URL: https://api.pdf4me.com/api/v2/GenerateDocumentSingle
Tipe Konten: aplikasi/json
Otorisasi: Dasar <Anda PDF4me API kunci>

Mengirim IsAsync: true di dalam tubuh. 200 Mengembalikan byte file yang telah dirender. 202 mengembalikan Lokasi header dengan jajak pendapat URL; GET itu URL dengan header Otorisasi yang sama hingga 200.

Matriks varian (relevan dengan Postman)

Pilih satu varian templat (T1 / T2 / T3) dan satu varian data (D1 / D2 / D3). Enam kombinasi mencakup setiap panggilan.

Templat (templateFileData)

KodeSumberNilai tukang pos dalam templateFileDataJuga diperlukan
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

Data dokumen (salah satu dari dua) API bidang)

KodeSumberBidang APINilai tukang pos
D1TextdocumentDataTextRaw JSON / XML / CSV string
D2Base64documentDataFileBase64 of the data file (strip data-URL prefix if present)
D3URLdocumentDataFileFull HTTPS URL to .json / .xml / .csv

Aturan: tepat satu dari documentDataText atau documentDataFile Harus diatur. Hilangkan kolom yang tidak digunakan dari isi.

Kombinasi umum

#TemplatDataPenggunaan umum
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 → allowed outputType

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

API bidang tubuh

Selalu dikirim

BidangDiperlukanJenisCatatan
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

Data dokumen (satu jalur)

BidangDiperlukan ketikaJenisCatatan
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

Opsional

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

Aturan validasi

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

Contoh placeholder

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

Contoh muatan

1. Templat Word (base64) + JSON teks → 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. Templat Word (URL) + JSON data (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. Templat Word (base64) + JSON data (base64) → Output kata

documentDataFile menyimpan basis64 dari JSON byte file (bukan objek yang diuraikan).

{
"templateFileType": "Docx",
"templateFileName": "template.docx",
"templateFileData": "UEsDBBQAAAAI...",
"documentDataType": "Json",
"documentDataFile": "eyJuYW1lIjogIkpvaG4gRG9lIn0=",
"outputType": "Docx",
"IsAsync": true
}

4. HTML templat (base64 dari HTML berkas) + JSON teks → HTML

Untuk mentah HTML Di Postman, kirim payload yang sama n8n node akan: dikodekan base64 HTML di dalam templateFileData.

{
"templateFileType": "HTML",
"templateFileName": "template.html",
"templateFileData": "PCFET0NUWVBFIGh0bWw+...",
"documentDataType": "Json",
"documentDataText": "{\"title\": \"Invoice\", \"heading\": \"Hello\", \"content\": \"World\"}",
"outputType": "HTML",
"IsAsync": true
}

5. Penggabungan surat (Mail merge)URL) + XML teks → 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 templat formulir (base64) + CSV teks → PDF (dapat diedit)

{
"templateFileType": "PDF",
"templateFileName": "template.pdf",
"templateFileData": "JVBERi0xLjQKJcfsj6IK...",
"documentDataType": "Csv",
"documentDataText": "name,email\nJohn Doe,[email protected]",
"outputType": "PDF",
"KeepPdfEditable": true,
"IsAsync": true
}

7. Gaya Google Docs (base64) + JSON URL → Dokumenx

{
"templateFileType": "GoogleDocs",
"templateFileName": "template.docx",
"templateFileData": "UEsDBBQAAAAI...",
"documentDataType": "Json",
"documentDataFile": "https://example.com/data.json",
"outputType": "Docx",
"IsAsync": true
}

Tips pengambilan oleh tukang pos

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.

contoh curl

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

Referensi cepat: wajib vs opsional berdasarkan varian

BidangT1+D1T2+D3T1+D2T3+D1Keluaran PDF apa pun
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 hanya berlaku bila tipe keluaran adalah PDF; itu API memaksa sebaliknya menjadi salah.

Contoh kode

Pertanyaan yang Sering Diajukan (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.

Tindakan terkait

Tugas yang sama di platform lain

Dapatkan Bantuan