Buat Dokumen (Beberapa)
PDF4me Buat Dokumen (Beberapa) menampilkan banyak dokumen sekaligus REST Telepon. Kirim satu kata, HTML, atau PDF templat (Base64, URLatau mentah HTML) ditambah serangkaian catatan (JSON atau XML, sebagai teks, Base64 berkas, atau URL). Mengembalikan sebuah JSON daftar file yang dihasilkan (satu entri per catatan) sebagai Base64 di dalam outputDocuments[].streamFileatau satu nilai biner tunggal tergantung pada responsnya.
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/GenerateDocumentMultipleNama titik akhir adalah HasilkanDokumenBerganda (tunggal) Dokumen), bukan HasilkanDokumenBerganda.
Fakta Penting yang Tidak Boleh Anda Lewatkan
outputDocuments[]nama file dan base64 streamFile (Kadang-kadang isi file, isi, atau data). Dekode setiap string base64 untuk menyimpan file.Dokumenx, HTML, PDFTipe data terbatas pada Json, XMLOutput menambahkan xlsx untuk Word / PDF templat.HTTP pengaturan
Metode: POS
URL: https://api.pdf4me.com/api/v2/GenerateDocumentMultiple
Tipe Konten: aplikasi/json
Otorisasi: Dasar <Anda PDF4me API kunci>
Mengirim IsAsync: true di dalam tubuh. 200 mungkin kembali JSON dengan outputDocuments[] atau sebuah file biner tunggal. 202 mengembalikan Lokasi header dengan jajak pendapat URL.
Perbedaan vs Menghasilkan Dokumen (Tunggal)
| Topik | Beberapa | Lajang |
|---|---|---|
| Endpoint | /api/v2/GenerateDocumentMultiple | /api/v2/GenerateDocumentSingle |
| templateFileType | Docx, HTML, PDF only | Also MailMerge, GoogleDocs |
| documentDataType | Json, XML only | Also Csv |
| outputType | PDF, Docx, xlsx (Word/PDF), HTML | No xlsx |
| Data shape | Typically array of records (one doc per row) | Usually one object |
| outputFileName | Integration-UI only (output naming) | Not in API body either |
Matriks varian (relevan dengan Postman)
Templat (templateFileData)
| Kode | Sumber | Nilai tukang pos | Juga diperlukan |
|---|---|---|---|
| T1 | Base64 | Base64 template (strip data:...;base64, prefix if present) | templateFileName |
| T2 | URL | HTTPS URL string | templateFileName |
| T3 | HTML code | Base64(UTF-8 HTML): Buffer.from(html, "utf8").toString("base64") | templateFileName, templateFileType: HTML |
Data dokumen
| Kode | Sumber | Bidang API | Nilai tukang pos |
|---|---|---|---|
| D1 | Text | documentDataText | JSON array (or XML with multiple records) |
| D2 | Base64 | documentDataFile | Base64 of the .json / .xml file |
| D3 | URL | documentDataFile | URL to the data file |
Gunakan salah satu documentDataText atau documentDataFile (abaikan kolom yang tidak digunakan).
templateFileType → allowed outputType
templateFileType | Diizinkan tipe keluaran |
|---|---|
Docx | PDF, Docx, xlsx |
PDF | PDF, Docx, xlsx |
HTML | HTML only |
API bidang tubuh
Selalu dikirim
| Bidang | Diperlukan | Jenis | Catatan |
|---|---|---|---|
templateFileType | Yes | string | Docx, HTML, PDF |
templateFileName | Yes | string | e.g. template.docx, template.html, template.pdf |
templateFileData | Yes | string | Base64 template, or template URL |
documentDataType | Yes | string | Json or XML (exact casing) |
outputType | Yes | string | PDF, Docx, xlsx, or HTML |
IsAsync | Yes | boolean | true |
Data dokumen (satu jalur)
| Bidang | Diperlukan ketika | Jenis | Catatan |
|---|---|---|---|
documentDataText | D1 | string | Valid JSON (JSON.parse) or XML-like for XML |
documentDataFile | D2 or D3 | string | Base64 data file or URL |
Opsional
| Bidang | Kapan | Bawaan |
|---|---|---|
KeepPdfEditable | outputType is PDF | false |
Aturan validasi
| Memeriksa | Detail |
|---|---|
| Template URL / base64 | Same rules as Single. |
| HTML code | Only when templateFileType is HTML. |
| JSON text | Must parse with JSON.parse. |
| XML text | Looser than Single (no strict tag check); send XML the template expects. |
| Data source | documentDataFile or documentDataText is required. |
Bentuk data multi-rekaman
Untuk JSON, gunakan array objek (satu objek per dokumen yang dihasilkan):
[
]
Untuk XMLGunakan struktur yang diharapkan templat Anda untuk baris yang berulang (ide yang sama seperti penggabungan surat). The API hanya memeriksa bahwa JSON mengurai; mesin tersebut menentukan berapa banyak dokumen yang dihasilkan.
API tanggapan (Postman)
Seringkali JSON seperti:
{
"outputDocuments": [
{
"fileName": "document1.pdf",
"streamFile": "<base64>"
}
]
}
Nama kolom juga dapat muncul sebagai fileContent, content, atau data. Dekode masing-masing Base64 string untuk menyimpan setiap file.
Contoh muatan
1. Templat Word (base64) + JSON array (teks) → beberapa PDFs
{
"templateFileType": "Docx",
"templateFileName": "template.docx",
"templateFileData": "UEsDBBQAAAAI...",
"documentDataType": "Json",
"documentDataText": "[{\"name\": \"Alice\", \"email\": \"[email protected]\"}, {\"name\": \"Bob\", \"email\": \"[email protected]\"}]",
"outputType": "PDF",
"KeepPdfEditable": false,
"IsAsync": true
}
2. Templat Word (URL) + JSON data (URL) → PDFs
{
"templateFileType": "Docx",
"templateFileName": "template.docx",
"templateFileData": "https://example.com/template.docx",
"documentDataType": "Json",
"documentDataFile": "https://example.com/customers.json",
"outputType": "PDF",
"IsAsync": true
}
3. Templat Word (base64) + JSON berkas (base64) → Excel (xlsx)
{
"templateFileType": "Docx",
"templateFileName": "template.docx",
"templateFileData": "UEsDBBQAAAAI...",
"documentDataType": "Json",
"documentDataFile": "W3sibmFtZSI6ICJBbGljZSJ9LCB7Im5hbWUiOiAiQm9iIn1d",
"outputType": "xlsx",
"IsAsync": true
}
(documentDataFile = basis64 dari [{"name":"Alice"},{"name":"Bob"}].)
4. HTML templat (base64) + JSON array (teks) → HTML
{
"templateFileType": "HTML",
"templateFileName": "template.html",
"templateFileData": "PCFET0NUWVBFIGh0bWw+...",
"documentDataType": "Json",
"documentDataText": "[{\"title\": \"Invoice 1\", \"heading\": \"Hello\", \"content\": \"A\"}, {\"title\": \"Invoice 2\", \"heading\": \"Hi\", \"content\": \"B\"}]",
"outputType": "HTML",
"IsAsync": true
}
5. PDF templat (URL) + XML (teks) → beberapa PDFs
{
"templateFileType": "PDF",
"templateFileName": "template.pdf",
"templateFileData": "https://example.com/template.pdf",
"documentDataType": "XML",
"documentDataText": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><records><record><name>Alice</name></record><record><name>Bob</name></record></records>",
"outputType": "PDF",
"KeepPdfEditable": true,
"IsAsync": true
}
6. Templat Word (base64) + XML (URL) → Word (Docx)
{
"templateFileType": "Docx",
"templateFileName": "template.docx",
"templateFileData": "UEsDBBQAAAAI...",
"documentDataType": "XML",
"documentDataFile": "https://example.com/data.xml",
"outputType": "Docx",
"IsAsync": true
}
Tips pengambilan oleh tukang pos
contoh curl
curl -X POST https://api.pdf4me.com/api/v2/GenerateDocumentMultiple \
-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",
"documentDataText": "[{\"name\":\"Alice\"},{\"name\":\"Bob\"}]",
"outputType": "PDF",
"IsAsync": true
}' \
--output response.json
Referensi cepat: wajib vs opsional berdasarkan varian
| Bidang | T1+D1 | T2+D3 | T1+D2 | T3+D1 | Output PDF |
|---|---|---|---|---|---|
templateFileType | Req | Req | Req | Req | Req |
templateFileName | Req | Req | Req | Req | Req |
templateFileData | Req (b64) | Req (URL) | Req (b64) | Req (b64) | Req |
documentDataType | Req | Req | Req | Req | Req |
outputType | Req | Req | Req | Req | Req |
documentDataText | Req | Omit | Omit | Req | Omit |
documentDataFile | Omit | Req | Req | Omit | Omit |
IsAsync | Req | Req | Req | Req | Req |
KeepPdfEditable | Opt | Opt | Opt | N/A* | Opt |
*Hanya ketika tipe keluaran adalah PDF.