Generate PDF
POST /api/v1/generate-pdf — upload a Peppol BIS 3.0 XML file and receive a binary PDF download.
Generate PDF
POST /api/v1/generate-pdfAccepts a multipart/form-data request containing a Peppol BIS 3.0 XML file and returns a binary PDF download.
Request
Headers
| Header | Value | Required |
|---|---|---|
Authorization | Bearer <your_api_key> | Yes |
Form fields
| Field | Type | Required | Description |
|---|---|---|---|
file | file | Yes | Peppol BIS 3.0 XML file to convert |
config | string | No | JSON object with generation options (see below) |
The config field must be sent as a JSON string. When omitted, defaults to {"locale":"en"}.
Config options
{
"locale": "en",
"preset": "accountant",
"fields": { ... }
}| Field | Type | Default | Description |
|---|---|---|---|
locale | string | en | Locale code for label translation. Supported: en, nl, fr |
preset | string | — | Predefined field mapping preset. One of accountant or administration. Mutually exclusive with fields |
fields | object | — | Granular field visibility control. Mutually exclusive with preset |
Presets
| Preset | Description |
|---|---|
accountant | Fields relevant for accounting purposes |
administration | Fields relevant for administrative purposes |
Fields
Use fields to show or hide individual Peppol BIS 3.0 data fields in the generated PDF. Each key maps to a Peppol element and accepts a boolean (true to include, false to exclude). Nested objects allow fine-grained control over sub-fields.
Document header
| Field | BT / BG | Description |
|---|---|---|
CustomizationID | BT-24 | Specification identifier |
ProfileID | BT-23 | Business process type |
ID | BT-1 | Invoice number |
IssueDate | BT-2 | Invoice issue date |
DueDate | BT-9 | Payment due date |
InvoiceTypeCode | BT-3 | Invoice type code (e.g. 380) |
Note | BT-22 | Invoice note |
TaxPointDate | BT-7 | Value added tax point date |
DocumentCurrencyCode | BT-5 | Invoice currency code |
TaxCurrencyCode | BT-6 | VAT accounting currency code |
AccountingCost | BT-19 | Buyer accounting reference |
BuyerReference | BT-10 | Buyer reference |
PaymentTerms | BT-20 | Payment terms |
Document references
| Field | BT / BG | Description |
|---|---|---|
BillingReference | BG-3 | Preceding invoice references |
DespatchDocumentReference | BT-16 | Despatch advice reference |
ReceiptDocumentReference | BT-15 | Receipt advice reference |
OriginatorDocumentReference | BT-17 | Tender or lot reference |
ContractDocumentReference | BT-12 | Contract reference |
AdditionalDocumentReference | BG-24 | Additional supporting documents |
ProjectReference | BT-11 | Project reference |
InvoicePeriod
BG-14 — Invoicing period
InvoicePeriod accepts false or an object with sub-fields:
| Sub-field | BT | Description |
|---|---|---|
StartDate | BT-73 | Invoicing period start date |
EndDate | BT-74 | Invoicing period end date |
DescriptionCode | BT-8 | Value added tax point date code |
OrderReference
OrderReference accepts false or an object:
| Sub-field | BT | Description |
|---|---|---|
ID | BT-13 | Purchase order reference |
SalesOrderID | BT-14 | Sales order reference |
Parties
AccountingSupplierParty / AccountingCustomerParty
BG-4 — Seller / BG-7 — Buyer
AccountingSupplierParty (BG-4 — Seller) and AccountingCustomerParty (BG-7 — Buyer) each accept false or an object containing a Party sub-object with these fields:
| Sub-field | BT | Description |
|---|---|---|
EndpointID | BT-34 / BT-49 | Electronic address (incl. scheme) |
PartyIdentification | BT-29 / BT-46 | Identifier(s) (incl. scheme) |
PartyName | BT-27 / BT-44 | Name / trading name |
PostalAddress | — | false or object — see sub-fields below |
PartyTaxScheme | BT-31 / BT-48 | VAT identifier / tax registration identifier |
PartyLegalEntity | — | false or object — see sub-fields below |
Contact | BG-6 / BG-9 | false or object — see sub-fields below |
PostalAddress sub-fields:
| Sub-field | Description |
|---|---|
StreetName | Street name |
AdditionalStreetName | Additional street name |
CityName | City |
PostalZone | Post code |
CountrySubentity | Country subdivision |
AddressLine.Line | Additional address line |
Country.IdentificationCode | Country code |
PartyLegalEntity sub-fields:
| Sub-field | BT | Description |
|---|---|---|
RegistrationName | BT-27 / BT-44 | Legal registration name |
CompanyID | BT-30 / BT-47 | Legal registration identifier |
CompanyLegalForm | BT-33 (seller only) | Additional legal information |
Contact sub-fields:
| Sub-field | Description |
|---|---|
Name | Contact name |
Telephone | Phone number |
ElectronicMail | Email address |
PayeeParty
BG-10 — Payee
PayeeParty accepts false or an object:
| Sub-field | BT | Description |
|---|---|---|
PartyIdentification | BT-60 | Payee identifier (incl. scheme) |
PartyName | BT-59 | Payee name |
PartyLegalEntity | BT-61 | Payee legal registration identifier |
TaxRepresentativeParty
BG-11 — Seller tax representative party
TaxRepresentativeParty accepts false or an object:
| Sub-field | BT | Description |
|---|---|---|
PartyName | BT-62 | Seller tax representative name |
PostalAddress | — | false or object — same sub-fields as PostalAddress above |
PartyTaxScheme | — | false or object — see sub-fields below |
PartyTaxScheme sub-fields:
| Sub-field | BT | Description |
|---|---|---|
CompanyID | BT-63 | Seller tax representative VAT identifier |
TaxScheme | — | Object with ID (boolean) |
Delivery
Delivery
BG-13 — Delivery information
Delivery accepts false or an object:
| Sub-field | BT | Description |
|---|---|---|
ActualDeliveryDate | BT-72 | Actual delivery date |
DeliveryParty | BT-70 | Deliver to party name |
DeliveryLocation | BG-15 | false or object — see sub-fields below |
DeliveryLocation sub-fields:
| Sub-field | BT | Description |
|---|---|---|
ID | BT-71 | Deliver to location identifier (incl. scheme BT-71-1) |
Address | — | false or object — same sub-fields as PostalAddress above |
Payment
PaymentMeans
BG-16 — Payment instructions
PaymentMeans accepts false or an object:
| Sub-field | BT | Description |
|---|---|---|
PaymentMeansCode | BT-81 | Payment means type code (incl. BT-82 name) |
PaymentID | BT-83 | Remittance information |
PayeeFinancialAccount | BG-17 | Credit transfer (IBAN, bank name, etc.) |
CardAccount | BG-18 | Payment card information |
PaymentMandate | BG-19 | Direct debit (mandate reference, debited account) |
AllowanceCharge
BG-20 — Document level allowances / BG-21 — Document level charges
AllowanceCharge accepts false or an object:
| Sub-field | BT | Description |
|---|---|---|
AllowanceChargeReasonCode | BT-98/BT-140 | Reason code |
AllowanceChargeReason | BT-97/BT-139 | Reason text |
MultiplierFactorNumeric | BT-94/BT-138 | Percentage |
Amount | BT-92/BT-137 | Amount |
BaseAmount | BT-93/BT-138 | Base amount |
TaxCategory | — | false or object — see sub-fields below |
TaxCategory sub-fields:
| Sub-field | BT | Description |
|---|---|---|
ID | BT-95/BT-102 | VAT category code |
Percent | BT-96/BT-103 | VAT rate |
TaxScheme | — | Object with ID (boolean) |
Tax and totals
TaxTotal
BG-22 — VAT breakdown
TaxTotal accepts false or an object:
| Sub-field | BT | Description |
|---|---|---|
TaxAmount | BT-110/BT-111 | Invoice total VAT amount |
TaxSubtotal | BG-23 | false or object — see sub-fields below |
TaxSubtotal sub-fields (BG-23 — VAT breakdown row):
| Sub-field | BT | Description |
|---|---|---|
TaxableAmount | BT-116 | VAT category taxable amount |
TaxAmount | BT-117 | VAT category tax amount |
TaxCategory | — | false or object — see sub-fields below |
TaxSubtotal.TaxCategory sub-fields:
| Sub-field | BT | Description |
|---|---|---|
ID | BT-118 | VAT category code |
Percent | BT-119 | VAT category rate |
TaxExemptionReasonCode | BT-121 | VAT exemption reason code |
TaxExemptionReason | BT-120 | VAT exemption reason text |
TaxScheme | — | Object with ID (boolean) |
LegalMonetaryTotal
BG-22 — Document totals
LegalMonetaryTotal accepts false or an object:
| Sub-field | BT | Description |
|---|---|---|
LineExtensionAmount | BT-106 | Sum of invoice line net amounts |
AllowanceTotalAmount | BT-107 | Sum of allowances on document level |
ChargeTotalAmount | BT-108 | Sum of charges on document level |
TaxExclusiveAmount | BT-109 | Invoice total amount without VAT |
TaxInclusiveAmount | BT-112 | Invoice total amount with VAT |
PrepaidAmount | BT-113 | Paid amount |
PayableRoundingAmount | BT-114 | Rounding amount |
PayableAmount | BT-115 | Amount due for payment |
Invoice lines
InvoiceLine
BG-25 — Invoice line
InvoiceLine accepts false or an object:
| Sub-field | BT | Description |
|---|---|---|
ID | BT-126 | Invoice line identifier |
Note | BT-127 | Invoice line note |
InvoicedQuantity | BT-129 / BT-130 | Invoiced quantity / unit of measure |
LineExtensionAmount | BT-131 | Invoice line net amount |
AccountingCost | BT-133 | Invoice line buyer accounting reference |
InvoicePeriod | BG-26 | false or object — see sub-fields below |
OrderLineReference | — | false or object — see sub-fields below |
DocumentReference | — | false or object — see sub-fields below |
AllowanceCharge | BG-27 / BG-28 | false or object — see sub-fields below |
Item | BG-31 | false or object — see sub-fields below |
Price | BG-29 | false or object — see sub-fields below |
InvoicePeriod sub-fields (BG-26 — Invoice line period):
| Sub-field | BT | Description |
|---|---|---|
StartDate | BT-134 | Invoice line period start date |
EndDate | BT-135 | Invoice line period end date |
OrderLineReference sub-fields:
| Sub-field | BT | Description |
|---|---|---|
LineID | BT-132 | Referenced purchase order line reference |
DocumentReference sub-fields:
| Sub-field | BT | Description |
|---|---|---|
ID | BT-128 | Invoice line object identifier (incl. scheme) |
DocumentTypeCode | — | Document type code |
AllowanceCharge sub-fields (BG-27 / BG-28 — Invoice line allowances / charges):
| Sub-field | BT | Description |
|---|---|---|
ChargeIndicator | — | true for charge, false for allowance |
AllowanceChargeReasonCode | BT-140 / BT-145 | Reason code |
AllowanceChargeReason | BT-139 / BT-144 | Reason text |
MultiplierFactorNumeric | BT-138 / BT-143 | Percentage |
Amount | BT-136 / BT-141 | Amount |
BaseAmount | — | Base amount |
Item sub-fields (BG-31 — Item information):
| Sub-field | BT | Description |
|---|---|---|
Name | BT-153 | Item name |
Description | BT-154 | Item description |
SellersItemIdentification.ID | BT-155 | Item seller's identifier |
BuyersItemIdentification.ID | BT-156 | Item buyer's identifier |
StandardItemIdentification.ID | BT-157 | Item standard identifier (incl. scheme BT-157-1) |
OriginCountry.IdentificationCode | BT-159 | Item country of origin |
CommodityClassification | BT-158 | Item classification identifier |
ClassifiedTaxCategory | BG-30 | false or object — see sub-fields below |
AdditionalItemProperty | BG-32 | Item attributes (name/value pairs) |
ClassifiedTaxCategory sub-fields (BG-30 — Line VAT information):
| Sub-field | BT | Description |
|---|---|---|
ID | BT-151 | Invoiced item VAT category code |
Percent | BT-152 | Invoiced item VAT rate |
TaxScheme | — | Object with ID (boolean) |
Price sub-fields (BG-29 — Price details):
| Sub-field | BT | Description |
|---|---|---|
PriceAmount | BT-146 | Item net price |
BaseQuantity | BT-149 / BT-150 | Item price base quantity / unit code |
AllowanceCharge | — | false or object — see sub-fields below |
Price.AllowanceCharge sub-fields:
| Sub-field | BT | Description |
|---|---|---|
ChargeIndicator | — | Should be false (discount) |
Amount | BT-147 | Item price discount |
BaseAmount | BT-148 | Item gross price |
Response
200 — Success
Returns a binary PDF download.
Content-Type: application/pdf400 — Bad request
{
"error": "string"
}Returned when the file is missing, the XML is invalid, or the document type is not supported.
401 — Unauthorized
{
"error": "string"
}Returned when the API key is missing or invalid.
Examples
Basic — download PDF
curl -X POST "https://api.peppolpdf.eu/api/v1/generate-pdf" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "file=@invoice.xml" \
-o invoice.pdfimport fs from "fs";
const form = new FormData();
form.append("file", new Blob([fs.readFileSync("invoice.xml")], { type: "application/xml" }), "invoice.xml");
form.append("config", JSON.stringify({ locale: "en" }));
const res = await fetch("https://api.peppolpdf.eu/api/v1/generate-pdf", {
method: "POST",
headers: { "Authorization": `Bearer ${process.env.PEPPOLPDF_API_KEY!}` },
body: form,
});
if (!res.ok) {
const { error } = await res.json();
throw new Error(error);
}
fs.writeFileSync("invoice.pdf", Buffer.from(await res.arrayBuffer()));import os
import requests
with open("invoice.xml", "rb") as f:
response = requests.post(
"https://api.peppolpdf.eu/api/v1/generate-pdf",
headers={"Authorization": f"Bearer {os.environ['PEPPOLPDF_API_KEY']}"},
files={"file": ("invoice.xml", f, "application/xml")},
)
response.raise_for_status()
with open("invoice.pdf", "wb") as f:
f.write(response.content)<?php
$curl = curl_init('https://api.peppolpdf.eu/api/v1/generate-pdf');
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('PEPPOLPDF_API_KEY')],
CURLOPT_POSTFIELDS => [
'file' => new CURLFile('invoice.xml', 'application/xml', 'invoice.xml'),
],
]);
$pdf = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($httpCode !== 200) {
throw new RuntimeException('API error: ' . $pdf);
}
file_put_contents('invoice.pdf', $pdf);package main
import (
"bytes"
"io"
"mime/multipart"
"net/http"
"os"
)
func main() {
file, _ := os.Open("invoice.xml")
defer file.Close()
var body bytes.Buffer
writer := multipart.NewWriter(&body)
part, _ := writer.CreateFormFile("file", "invoice.xml")
io.Copy(part, file)
writer.Close()
req, _ := http.NewRequest(http.MethodPost, "https://api.peppolpdf.eu/api/v1/generate-pdf", &body)
req.Header.Set("Authorization", "Bearer " + os.Getenv("PEPPOLPDF_API_KEY"))
req.Header.Set("Content-Type", writer.FormDataContentType())
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
out, _ := os.Create("invoice.pdf")
defer out.Close()
io.Copy(out, resp.Body)
}using var fileStream = File.OpenRead("invoice.xml");
using var content = new MultipartFormDataContent
{
{ new StreamContent(fileStream), "file", "invoice.xml" },
};
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + Environment.GetEnvironmentVariable("PEPPOLPDF_API_KEY"));
var response = await client.PostAsync("https://api.peppolpdf.eu/api/v1/generate-pdf", content);
response.EnsureSuccessStatusCode();
var pdf = await response.Content.ReadAsByteArrayAsync();
await File.WriteAllBytesAsync("invoice.pdf", pdf);import okhttp3.*;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
var client = new OkHttpClient();
var body = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("file", "invoice.xml",
RequestBody.create(new File("invoice.xml"), MediaType.parse("application/xml")))
.build();
var request = new Request.Builder()
.url("https://api.peppolpdf.eu/api/v1/generate-pdf")
.addHeader("Authorization", "Bearer " + System.getenv("PEPPOLPDF_API_KEY"))
.post(body)
.build();
try (var response = client.newCall(request).execute()) {
if (!response.isSuccessful()) throw new IOException("API error: " + response);
Files.write(Path.of("invoice.pdf"), response.body().bytes());
}With locale and preset
curl -X POST "https://api.peppolpdf.eu/api/v1/generate-pdf" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "file=@invoice.xml" \
-F 'config={"preset":"administration","locale":"nl"}' \
-o invoice.pdfimport fs from "fs";
const form = new FormData();
form.append("file", new Blob([fs.readFileSync("invoice.xml")], { type: "application/xml" }), "invoice.xml");
form.append("config", JSON.stringify({ preset: "administration", locale: "nl" }));
const res = await fetch("https://api.peppolpdf.eu/api/v1/generate-pdf", {
method: "POST",
headers: { "Authorization": `Bearer ${process.env.PEPPOLPDF_API_KEY!}` },
body: form,
});
if (!res.ok) {
const { error } = await res.json();
throw new Error(error);
}
fs.writeFileSync("invoice.pdf", Buffer.from(await res.arrayBuffer()));import os
import json
import requests
with open("invoice.xml", "rb") as f:
response = requests.post(
"https://api.peppolpdf.eu/api/v1/generate-pdf",
headers={"Authorization": f"Bearer {os.environ['PEPPOLPDF_API_KEY']}"},
files={"file": ("invoice.xml", f, "application/xml")},
data={"config": json.dumps({"preset": "administration", "locale": "nl"})},
)
response.raise_for_status()
with open("invoice.pdf", "wb") as f:
f.write(response.content)<?php
$curl = curl_init('https://api.peppolpdf.eu/api/v1/generate-pdf');
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('PEPPOLPDF_API_KEY')],
CURLOPT_POSTFIELDS => [
'file' => new CURLFile('invoice.xml', 'application/xml', 'invoice.xml'),
'config' => json_encode(['preset' => 'all', 'locale' => 'nl']),
],
]);
$pdf = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($httpCode !== 200) {
throw new RuntimeException('API error: ' . $pdf);
}
file_put_contents('invoice.pdf', $pdf);package main
import (
"bytes"
"io"
"mime/multipart"
"net/http"
"os"
)
func main() {
file, _ := os.Open("invoice.xml")
defer file.Close()
var body bytes.Buffer
writer := multipart.NewWriter(&body)
part, _ := writer.CreateFormFile("file", "invoice.xml")
io.Copy(part, file)
writer.WriteField("config", `{"preset":"administration","locale":"nl"}`)
writer.Close()
req, _ := http.NewRequest(http.MethodPost, "https://api.peppolpdf.eu/api/v1/generate-pdf", &body)
req.Header.Set("Authorization", "Bearer " + os.Getenv("PEPPOLPDF_API_KEY"))
req.Header.Set("Content-Type", writer.FormDataContentType())
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
out, _ := os.Create("invoice.pdf")
defer out.Close()
io.Copy(out, resp.Body)
}using var fileStream = File.OpenRead("invoice.xml");
using var content = new MultipartFormDataContent
{
{ new StreamContent(fileStream), "file", "invoice.xml" },
{ new StringContent("""{ \"preset\":\"administration\",\"locale\":\"nl\"}"""), "config" },
};
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + Environment.GetEnvironmentVariable("PEPPOLPDF_API_KEY"));
var response = await client.PostAsync("https://api.peppolpdf.eu/api/v1/generate-pdf", content);
response.EnsureSuccessStatusCode();
var pdf = await response.Content.ReadAsByteArrayAsync();
await File.WriteAllBytesAsync("invoice.pdf", pdf);import okhttp3.*;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
var client = new OkHttpClient();
var body = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("file", "invoice.xml",
RequestBody.create(new File("invoice.xml"), MediaType.parse("application/xml")))
.addFormDataPart("config", "{\"preset\":\"administration\",\"locale\":\"nl\"}")
.build();
var request = new Request.Builder()
.url("https://api.peppolpdf.eu/api/v1/generate-pdf")
.addHeader("Authorization", "Bearer " + System.getenv("PEPPOLPDF_API_KEY"))
.post(body)
.build();
try (var response = client.newCall(request).execute()) {
if (!response.isSuccessful()) throw new IOException("API error: " + response);
Files.write(Path.of("invoice.pdf"), response.body().bytes());
}With granular field control
curl -X POST "https://api.peppolpdf.eu/api/v1/generate-pdf" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "file=@invoice.xml" \
-F 'config={"locale":"en","fields":{"ID":true,"IssueDate":true,"DueDate":true,"LegalMonetaryTotal":true,"InvoiceLine":true}}' \
-o invoice.pdfimport fs from "fs";
const config = {
locale: "en",
fields: {
ID: true,
IssueDate: true,
DueDate: true,
AccountingSupplierParty: {
Party: { PartyName: true, PostalAddress: true, PartyTaxScheme: true },
},
AccountingCustomerParty: {
Party: { PartyName: true, PostalAddress: true },
},
LegalMonetaryTotal: true,
InvoiceLine: true,
},
};
const form = new FormData();
form.append("file", new Blob([fs.readFileSync("invoice.xml")], { type: "application/xml" }), "invoice.xml");
form.append("config", JSON.stringify(config));
const res = await fetch("https://api.peppolpdf.eu/api/v1/generate-pdf", {
method: "POST",
headers: { "Authorization": `Bearer ${process.env.PEPPOLPDF_API_KEY!}` },
body: form,
});
if (!res.ok) {
const { error } = await res.json();
throw new Error(error);
}
fs.writeFileSync("invoice.pdf", Buffer.from(await res.arrayBuffer()));import os
import json
import requests
config = {
"locale": "en",
"fields": {
"ID": True,
"IssueDate": True,
"DueDate": True,
"AccountingSupplierParty": {
"Party": {"PartyName": True, "PostalAddress": True, "PartyTaxScheme": True}
},
"AccountingCustomerParty": {
"Party": {"PartyName": True, "PostalAddress": True}
},
"LegalMonetaryTotal": True,
"InvoiceLine": True,
},
}
with open("invoice.xml", "rb") as f:
response = requests.post(
"https://api.peppolpdf.eu/api/v1/generate-pdf",
headers={"Authorization": f"Bearer {os.environ['PEPPOLPDF_API_KEY']}"},
files={"file": ("invoice.xml", f, "application/xml")},
data={"config": json.dumps(config)},
)
response.raise_for_status()
with open("invoice.pdf", "wb") as f:
f.write(response.content)<?php
$config = [
'locale' => 'en',
'fields' => [
'ID' => true,
'IssueDate' => true,
'DueDate' => true,
'AccountingSupplierParty' => [
'Party' => ['PartyName' => true, 'PostalAddress' => true, 'PartyTaxScheme' => true],
],
'AccountingCustomerParty' => [
'Party' => ['PartyName' => true, 'PostalAddress' => true],
],
'LegalMonetaryTotal' => true,
'InvoiceLine' => true,
],
];
$curl = curl_init('https://api.peppolpdf.eu/api/v1/generate-pdf');
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('PEPPOLPDF_API_KEY')],
CURLOPT_POSTFIELDS => [
'file' => new CURLFile('invoice.xml', 'application/xml', 'invoice.xml'),
'config' => json_encode($config),
],
]);
$pdf = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($httpCode !== 200) {
throw new RuntimeException('API error: ' . $pdf);
}
file_put_contents('invoice.pdf', $pdf);package main
import (
"bytes"
"encoding/json"
"io"
"mime/multipart"
"net/http"
"os"
)
func main() {
config, _ := json.Marshal(map[string]any{
"locale": "en",
"fields": map[string]any{
"ID": true, "IssueDate": true, "DueDate": true,
"LegalMonetaryTotal": true, "InvoiceLine": true,
},
})
file, _ := os.Open("invoice.xml")
defer file.Close()
var body bytes.Buffer
writer := multipart.NewWriter(&body)
part, _ := writer.CreateFormFile("file", "invoice.xml")
io.Copy(part, file)
writer.WriteField("config", string(config))
writer.Close()
req, _ := http.NewRequest(http.MethodPost, "https://api.peppolpdf.eu/api/v1/generate-pdf", &body)
req.Header.Set("Authorization", "Bearer " + os.Getenv("PEPPOLPDF_API_KEY"))
req.Header.Set("Content-Type", writer.FormDataContentType())
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
out, _ := os.Create("invoice.pdf")
defer out.Close()
io.Copy(out, resp.Body)
}var config = new {
locale = "en",
fields = new {
ID = true, IssueDate = true, DueDate = true,
AccountingSupplierParty = new { Party = new { PartyName = true, PostalAddress = true, PartyTaxScheme = true } },
AccountingCustomerParty = new { Party = new { PartyName = true, PostalAddress = true } },
LegalMonetaryTotal = true,
InvoiceLine = true,
},
};
using var fileStream = File.OpenRead("invoice.xml");
using var content = new MultipartFormDataContent
{
{ new StreamContent(fileStream), "file", "invoice.xml" },
{ new StringContent(JsonSerializer.Serialize(config)), "config" },
};
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + Environment.GetEnvironmentVariable("PEPPOLPDF_API_KEY"));
var response = await client.PostAsync("https://api.peppolpdf.eu/api/v1/generate-pdf", content);
response.EnsureSuccessStatusCode();
var pdf = await response.Content.ReadAsByteArrayAsync();
await File.WriteAllBytesAsync("invoice.pdf", pdf);import okhttp3.*;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
var config = """
{"locale":"en","fields":{"ID":true,"IssueDate":true,
"DueDate":true,"LegalMonetaryTotal":true,"InvoiceLine":true}}
""";
var client = new OkHttpClient();
var body = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("file", "invoice.xml",
RequestBody.create(new File("invoice.xml"), MediaType.parse("application/xml")))
.addFormDataPart("config", config)
.build();
var request = new Request.Builder()
.url("https://api.peppolpdf.eu/api/v1/generate-pdf")
.addHeader("Authorization", "Bearer " + System.getenv("PEPPOLPDF_API_KEY"))
.post(body)
.build();
try (var response = client.newCall(request).execute()) {
if (!response.isSuccessful()) throw new IOException("API error: " + response);
Files.write(Path.of("invoice.pdf"), response.body().bytes());
}