Ana içeriğe geç

Belge Oluştur (Tekli)

Bu uç noktanın işlevi

PDF4me Belge Oluştur (Tekli) Şablonları (Word, ...) birleştirerek tek bir belge oluşturur. HTML, veya PDF) veri yüküyle (JSON, XML, veya CSV) birinde REST Çağrı. Şablon şu olabilir: Base64halka açık bir URLveya ham HTMLVeriler satır içi metin olabilir, bir Base64-kodlanmış bir dosya veya bir URLOluşturulan görüntüyü döndürür. PDF, Docx, veya HTML ikili olarak (200) veya bir aracılığıyla Location-başlık anketi URL (202).

İlgili Blog Yazıları
Bu özellik için henüz bir blog yazısı yok — yakında yayınlanacak.
Bu arada, her platforma yönelik eğitimler ve iş akışları için PDF4me bloguna göz atın.
Blogu ziyaret edin

Kimliğinizi Doğrulama API Rica etmek

Her PDF4me REST Çağrınızda mutlaka sizin de bulunmanız gerekiyor. API anahtara Authorization Başlıkta Temel kimlik doğrulama (Basic auth) belirtilmiştir. Anahtarınızı geliştirici kontrol panelinden alın veya değiştirin.

Uç nokta

POSTALAMAK/api/v2/GenerateDocumentSingle

Kaçırmamanız Gereken Önemli Bilgiler

Herhangi biri belgeVeriMetni veya belgeVeriDosyası
Yalnızca bir veri kaynağı ayarlanmalı, ikisi birden içerikle birlikte ayarlanmamalıdır. Kullanın belgeVeriMetni satır içi için JSON / XML / CSV. Kullanmak belgeVeriDosyası bir için Base64-kodlanmış veri dosyası veya herkese açık bir URL.
İzin verilen çıktı türü, şablon dosya türüne bağlıdır.
Docx, MailMerge, GoogleDocs kabul eder PDF veya DocxHTML kabul eder HTML yalnızca PDF kabul edilir. PDF Sadece bu kadar. Büyük/küçük harf duyarlılığı önemlidir.
Async 202 + Location başlığı döndürüyor
İle IsAsync: true o API 202 yanıtı ve bir Location başlığı içerebilir. GET O URL (aynı Yetkilendirme) işlenmiş dosya ile 200'e kadar (standart) pdf4meAsyncRequest model).

HTTP kurmak

Yöntem: POSTALAMAK
URL: https://api.pdf4me.com/api/v2/GenerateDocumentSingle
İçerik Türü: uygulama/json
Yetkilendirme: Temel <sizin PDF4me API anahtar>

Göndermek IsAsync: true Vücutta. 200 Oluşturulan dosya baytlarını döndürür. 202 bir döndürür Konum anket içeren başlık URL; GET O URL 200'e kadar aynı Yetkilendirme başlığıyla.

Varyant matrisi (Postman ile ilgili)

Bir şablon varyantı (T1 / T2 / T3) ve bir veri varyantı (D1 / D2 / D3) seçin. Altı kombinasyon her çağrıyı kapsar.

Şablon (templateFileData)

KodKaynakPostacının değeri şablonDosyaVerileriAyrıca gerekli
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

Belge verileri (iki seçenekten biri) API alanlar)

KodKaynakAPI alanıPostacı değeri
D1TextdocumentDataTextRaw JSON / XML / CSV string
D2Base64documentDataFileBase64 of the data file (strip data-URL prefix if present)
D3URLdocumentDataFileFull HTTPS URL to .json / .xml / .csv

Kural: tam olarak bir tane belgeVeriMetni veya belgeVeriDosyası Ayarlanmalıdır. Kullanılmayan alanı gövdeden çıkarın.

Yaygın kombinasyonlar

#ŞablonVeriTipik kullanım
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

şablonDosyaTipi → izin verilen çıktıTipi

şablonDosyaTürüİzin verilmiş çıktıTürüNotlar
DocxPDF, DocxPDF4me Word template
MailMergePDF, DocxMail merge Word
GoogleDocsPDF, DocxGoogle Docs export style
HTMLHTML onlyMustache in HTML
PDFPDF onlyPDF form / template

API vücut alanları

Her zaman gönderildi

AlanGerekliTipNotlar
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

Belge verileri (tek yol)

AlanGerekli olduğu zamanlarTipNotlar
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

İsteğe bağlı

AlanNe zamanVarsayılan
KeepPdfEditableoutputType is PDFfalse
documentDataFileD1 text path is usedOmitted
documentDataTextD2 or D3 path is usedOmitted

Doğrulama kuralları

Kontrol etmekDetay
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.

Yer tutucu örnekler

ÖğeÖrnek
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}}...

Örnek yükler

1. Word şablonu (base64) + JSON metin → 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. Word şablonu (URL) + JSON veri (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. Word şablonu (base64) + JSON Veri (base64) → Word çıktısı

documentDataFile base64 formatındaki verileri tutar. JSON Dosya baytları (ayrıştırılmış nesne değil).

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

4. HTML şablon (base64'ten) HTML dosya) + JSON metin → HTML

Ham madde için HTML Postman'de aynı veri paketini gönderin. n8n düğüm şunları yapardı: base64 kodlu HTML içinde templateFileData.

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

5. Posta birleştirme (URL) + XML metin → 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 Form şablonu (base64) + CSV metin → PDF (düzenlenebilir)

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

7. Google Dokümanlar stili (base64) + JSON URL → Docx

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

Postacı tahsilat ipuçları

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.

curl örneği

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

Hızlı referans: varyanta göre gerekli ve isteğe bağlı olanlar

AlanT1+D1T2+D3T1+D2T3+D1Herhangi bir PDF çıktısı
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 yalnızca şu durumlarda geçerlidir çıktıTürü dır PDF; API aksi takdirde yanlış sonuçlar doğurur.

Kod örnekleri

SSS

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.

İlgili işlemler

Diğer platformlarda aynı görev

Yardım Alın