Lewati ke konten utama

Buat Dokumen (Beberapa)

Fungsi dari endpoint ini

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.

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/GenerateDocumentMultiple

Nama titik akhir adalah HasilkanDokumenBerganda (tunggal) Dokumen), bukan HasilkanDokumenBerganda.

Fakta Penting yang Tidak Boleh Anda Lewatkan

Satu templat, banyak catatan
Kirim JSON array (atau rekaman berulang) XML) dalam muatan data Anda. Mesin ini merender satu dokumen keluaran per elemen array dan mengembalikannya bersama-sama.
Responsnya biasanya JSON outputDocuments[]
Setiap entri memiliki nama file dan base64 streamFile (Kadang-kadang isi file, isi, atau data). Dekode setiap string base64 untuk menyimpan file.
Berbeda dari Single: tidak mengizinkan CSV dan xlsx, jenis templat lebih sedikit.
Jenis templat terbatas pada 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)

TopikBeberapaLajang
Endpoint/api/v2/GenerateDocumentMultiple/api/v2/GenerateDocumentSingle
templateFileTypeDocx, HTML, PDF onlyAlso MailMerge, GoogleDocs
documentDataTypeJson, XML onlyAlso Csv
outputTypePDF, Docx, xlsx (Word/PDF), HTMLNo xlsx
Data shapeTypically array of records (one doc per row)Usually one object
outputFileNameIntegration-UI only (output naming)Not in API body either

Matriks varian (relevan dengan Postman)

Templat (templateFileData)

KodeSumberNilai tukang posJuga diperlukan
T1Base64Base64 template (strip data:...;base64, prefix if present)templateFileName
T2URLHTTPS URL stringtemplateFileName
T3HTML codeBase64(UTF-8 HTML): Buffer.from(html, "utf8").toString("base64")templateFileName, templateFileType: HTML

Data dokumen

KodeSumberBidang APINilai tukang pos
D1TextdocumentDataTextJSON array (or XML with multiple records)
D2Base64documentDataFileBase64 of the .json / .xml file
D3URLdocumentDataFileURL to the data file

Gunakan salah satu documentDataText atau documentDataFile (abaikan kolom yang tidak digunakan).

templateFileType → allowed outputType

templateFileTypeDiizinkan tipe keluaran
DocxPDF, Docx, xlsx
PDFPDF, Docx, xlsx
HTMLHTML only

API bidang tubuh

Selalu dikirim

BidangDiperlukanJenisCatatan
templateFileTypeYesstringDocx, HTML, PDF
templateFileNameYesstringe.g. template.docx, template.html, template.pdf
templateFileDataYesstringBase64 template, or template URL
documentDataTypeYesstringJson or XML (exact casing)
outputTypeYesstringPDF, Docx, xlsx, or HTML
IsAsyncYesbooleantrue

Data dokumen (satu jalur)

BidangDiperlukan ketikaJenisCatatan
documentDataTextD1stringValid JSON (JSON.parse) or XML-like for XML
documentDataFileD2 or D3stringBase64 data file or URL

Opsional

BidangKapanBawaan
KeepPdfEditableoutputType is PDFfalse

Aturan validasi

MemeriksaDetail
Template URL / base64Same rules as Single.
HTML codeOnly when templateFileType is HTML.
JSON textMust parse with JSON.parse.
XML textLooser than Single (no strict tag check); send XML the template expects.
Data sourcedocumentDataFile or documentDataText is required.

Bentuk data multi-rekaman

Untuk JSON, gunakan array objek (satu objek per dokumen yang dihasilkan):

[
{ "name": "Alice", "email": "[email protected]" },
{ "name": "Bob", "email": "[email protected]" }
]

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

Array data
Prefer a JSON array in documentDataText when documentDataType is Json and you expect more than one file.
Filename match
Match the extension in templateFileName to templateFileType.
Base64 of file
For D2, base64-encode the whole data file (not each row separately).
Decode response
If the response is JSON, decode each outputDocuments[].streamFile (or fileContent / content / data) from base64.
Endpoint name
Endpoint name is GenerateDocumentMultiple (singular Document), not GenerateDocumentsMultiple.

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

BidangT1+D1T2+D3T1+D2T3+D1Output PDF
templateFileTypeReqReqReqReqReq
templateFileNameReqReqReqReqReq
templateFileDataReq (b64)Req (URL)Req (b64)Req (b64)Req
documentDataTypeReqReqReqReqReq
outputTypeReqReqReqReqReq
documentDataTextReqOmitOmitReqOmit
documentDataFileOmitReqReqOmitOmit
IsAsyncReqReqReqReqReq
KeepPdfEditableOptOptOptN/A*Opt

*Hanya ketika tipe keluaran adalah PDF.

Contoh kode

Pertanyaan yang Sering Diajukan (FAQ)

How is Multiple different from Single?+
Different endpoint (/api/v2/GenerateDocumentMultiple), fewer template types (Docx, HTML, PDF only), no CSV, can output xlsx, and expects array-shaped data to produce one document per record in a single call.
What does the response look like?+
Typically a JSON object with outputDocuments[], each containing fileName and streamFile (base64). Some responses may use fileContent, content, or data as the field name. Decode each base64 string to save the file.
Which output types are allowed?+
Docx and PDF templates accept PDF, Docx, or xlsx. HTML template accepts HTML only.
Does HTML output produce multiple files?+
Yes when the engine renders one HTML document per input record. The response still uses the outputDocuments[] shape.
What is the maximum array size?+
No published hard cap. Large batches usually push you onto the async path (202 + Location poll). For very large workloads, split into multiple calls of a few hundred records each.
Why is the endpoint name singular Document?+
The path is /api/v2/GenerateDocumentMultiple, not GenerateDocumentsMultiple. A common typo. The plural version returns 404.
Does KeepPdfEditable work for xlsx or HTML output?+
No. It only applies when outputType is PDF. For other outputs the API ignores it.
Can I mix multiple template files in one call?+
No. One call uses one template. To render the same data set against multiple templates, issue one call per template.

Tindakan terkait

Tugas yang sama di platform lain

Dapatkan Bantuan