Buat Dokumen (Tunggal)
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).
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
/api/v2/GenerateDocumentSingleFakta Penting yang Tidak Boleh Anda Lewatkan
documentDataText atau documentDataFiledocumentDataText untuk inline JSON / XML / CSV. Menggunakan documentDataFile untuk sebuah Base64berkas data yang dikodekan atau publik URL.PDF atau DokumenxHTML menerima HTML hanya PDF yang menerima PDF hanya itu. Penulisan huruf besar dan kecil sangat penting.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)
| Kode | Sumber | Nilai tukang pos dalam templateFileData | Juga diperlukan |
|---|---|---|---|
| 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 |
Data dokumen (salah satu dari dua) API bidang)
| Kode | Sumber | Bidang API | Nilai tukang pos |
|---|---|---|---|
| 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 |
Aturan: tepat satu dari documentDataText atau documentDataFile Harus diatur. Hilangkan kolom yang tidak digunakan dari isi.
Kombinasi umum
| # | Templat | Data | Penggunaan umum |
|---|---|---|---|
| 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 → allowed outputType
templateFileType | Diizinkan tipe keluaran | Catatan |
|---|---|---|
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 bidang tubuh
Selalu dikirim
| Bidang | Diperlukan | Jenis | Catatan |
|---|---|---|---|
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 |
Data dokumen (satu jalur)
| Bidang | Diperlukan ketika | Jenis | Catatan |
|---|---|---|---|
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 |
Opsional
| Bidang | Kapan | Bawaan |
|---|---|---|
KeepPdfEditable | outputType is PDF | false |
documentDataFile | D1 text path is used | Omitted |
documentDataText | D2 or D3 path is used | Omitted |
Aturan validasi
| Memeriksa | 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. |
Contoh placeholder
| Barang | Contoh |
|---|---|
| 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}}... |
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",
"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
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
| Bidang | T1+D1 | T2+D3 | T1+D2 | T3+D1 | Keluaran PDF apa pun |
|---|---|---|---|---|---|
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 hanya berlaku bila tipe keluaran adalah PDF; itu API memaksa sebaliknya menjadi salah.