Peppolpdf Docs

PDF genereren

POST /api/v1/generate-pdf — upload een Peppol BIS 3.0 XML-bestand en ontvang een binaire PDF-download.

PDF genereren

POST /api/v1/generate-pdf

Accepteert een multipart/form-data-verzoek met een Peppol BIS 3.0 XML-bestand en geeft een binaire PDF-download terug.

Verzoek

Headers

HeaderWaardeVerplicht
AuthorizationBearer <jouw_api_sleutel>Ja

Formuliervelden

VeldTypeVerplichtBeschrijving
filebestandJaPeppol BIS 3.0 XML-bestand om te converteren
configstringNeeJSON-object met generatieopties (zie hieronder)

Het config-veld moet als JSON-string worden meegegeven. Als het ontbreekt, wordt standaard {"locale":"en"} gebruikt.

Configuratieopties

{
  "locale": "nl",
  "preset": "accountant",
  "fields": { ... }
}
VeldTypeStandaardBeschrijving
localestringenLocalecode voor labelvertaling. Ondersteund: en, nl, fr
presetstringVoorgedefinieerde veldmapping. Één van accountant of administration. Wederzijds exclusief met fields
fieldsobjectGedetailleerde veldcontrole. Wederzijds exclusief met preset

Presets

PresetBeschrijving
accountantVelden relevant voor boekhouddoeleinden
administrationVelden relevant voor administratieve doeleinden

Velden

Gebruik fields om afzonderlijke Peppol BIS 3.0-gegevensvelden in de gegenereerde PDF te tonen of te verbergen. Elke sleutel komt overeen met een Peppol-element en accepteert een boolean (true om op te nemen, false om uit te sluiten). Geneste objecten bieden gedetailleerde controle over subvelden.

Documentheader

VeldBT / BGBeschrijving
CustomizationIDBT-24Specificatie-identifier
ProfileIDBT-23Bedrijfsprocestype
IDBT-1Factuurnummer
IssueDateBT-2Factuurdatum
DueDateBT-9Vervaldatum betaling
InvoiceTypeCodeBT-3Factuurtype (bijv. 380)
NoteBT-22Factuurnotitie
TaxPointDateBT-7Datum btw-punt
DocumentCurrencyCodeBT-5Factuurvalutacode
TaxCurrencyCodeBT-6Btw-boekhoudingsvalutacode
AccountingCostBT-19Boekhoudingsreferentie koper
BuyerReferenceBT-10Koperreferentie
PaymentTermsBT-20Betalingsvoorwaarden

Documentreferenties

VeldBT / BGBeschrijving
BillingReferenceBG-3Verwijzingen naar voorgaande facturen
DespatchDocumentReferenceBT-16Leveringsadviesreferentie
ReceiptDocumentReferenceBT-15Ontvangstadviesreferentie
OriginatorDocumentReferenceBT-17Offerte- of lotreferentie
ContractDocumentReferenceBT-12Contractreferentie
AdditionalDocumentReferenceBG-24Aanvullende ondersteunende documenten
ProjectReferenceBT-11Projectreferentie
InvoicePeriod

BG-14 — Factuurperiode

InvoicePeriod accepteert false of een object met subvelden:

SubveldBTBeschrijving
StartDateBT-73Startdatum factuurperiode
EndDateBT-74Einddatum factuurperiode
DescriptionCodeBT-8Datum btw-puntcode
OrderReference

OrderReference accepteert false of een object:

SubveldBTBeschrijving
IDBT-13Inkooporderreferentie
SalesOrderIDBT-14Verkooporderreferentie

Partijen

AccountingSupplierParty / AccountingCustomerParty

BG-4 — Verkoper / BG-7 — Koper

AccountingSupplierParty (BG-4 — Verkoper) en AccountingCustomerParty (BG-7 — Koper) accepteren elk false of een object met een Party-subobject met de volgende velden:

SubveldBTBeschrijving
EndpointIDBT-34 / BT-49Elektronisch adres (incl. schema)
PartyIdentificationBT-29 / BT-46Identificator(s) (incl. schema)
PartyNameBT-27 / BT-44Naam / handelsnaam
PostalAddressfalse of object — zie subvelden hieronder
PartyTaxSchemeBT-31 / BT-48Btw-identificator / belastingregistratie
PartyLegalEntityfalse of object — zie subvelden hieronder
ContactBG-6 / BG-9false of object — zie subvelden hieronder

Subvelden PostalAddress:

SubveldBeschrijving
StreetNameStraatnaam
AdditionalStreetNameAanvullende straatnaam
CityNamePlaatsnaam
PostalZonePostcode
CountrySubentityProvincie of regio
AddressLine.LineExtra adresregel
Country.IdentificationCodeLandcode

Subvelden PartyLegalEntity:

SubveldBTBeschrijving
RegistrationNameBT-27 / BT-44Wettelijke handelsnaam
CompanyIDBT-30 / BT-47Wettelijke registratie-identifier
CompanyLegalFormBT-33 (alleen verkoper)Aanvullende wettelijke informatie

Subvelden Contact:

SubveldBeschrijving
NameContactnaam
TelephoneTelefoonnummer
ElectronicMailE-mailadres
PayeeParty

BG-10 — Begunstigde

PayeeParty accepteert false of een object:

SubveldBTBeschrijving
PartyIdentificationBT-60Begunstigde-identifier (incl. schema)
PartyNameBT-59Naam begunstigde
PartyLegalEntityBT-61Wettelijke registratie-identifier begunstigde
TaxRepresentativeParty

BG-11 — Btw-vertegenwoordiger verkoper

TaxRepresentativeParty accepteert false of een object:

SubveldBTBeschrijving
PartyNameBT-62Naam btw-vertegenwoordiger verkoper
PostalAddressfalse of object — zelfde subvelden als PostalAddress hierboven
PartyTaxSchemefalse of object — zie subvelden hieronder

Subvelden PartyTaxScheme:

SubveldBTBeschrijving
CompanyIDBT-63Btw-identificator btw-vertegenwoordiger verkoper
TaxSchemeObject met ID (boolean)

Levering

Delivery

BG-13 — Leveringsinformatie

Delivery accepteert false of een object:

SubveldBTBeschrijving
ActualDeliveryDateBT-72Werkelijke leveringsdatum
DeliveryPartyBT-70Naam afleverende partij
DeliveryLocationBG-15false of object — zie subvelden hieronder

Subvelden DeliveryLocation:

SubveldBTBeschrijving
IDBT-71Locatie-identifier afleveradres (incl. schema BT-71-1)
Addressfalse of object — zelfde subvelden als PostalAddress hierboven

Betaling

PaymentMeans

BG-16 — Betaalinstructies

PaymentMeans accepteert false of een object:

SubveldBTBeschrijving
PaymentMeansCodeBT-81Betalingsmiddelcode (incl. BT-82 naam)
PaymentIDBT-83Betalingskenmerk
PayeeFinancialAccountBG-17Overboeking (IBAN, banknaam, enz.)
CardAccountBG-18Kaartbetalingsinformatie
PaymentMandateBG-19Automatische incasso (mandaatreferentie, belaste rekening)
AllowanceCharge

BG-20 — Kortingen op documentniveau / BG-21 — Toeslagen op documentniveau

AllowanceCharge accepteert false of een object:

SubveldBTBeschrijving
AllowanceChargeReasonCodeBT-98/BT-140Redenscode
AllowanceChargeReasonBT-97/BT-139Redenstekst
MultiplierFactorNumericBT-94/BT-138Percentage
AmountBT-92/BT-137Bedrag
BaseAmountBT-93/BT-138Basisbedrag
TaxCategoryfalse of object — zie subvelden hieronder

Subvelden TaxCategory:

SubveldBTBeschrijving
IDBT-95/BT-102Btw-categoriecode
PercentBT-96/BT-103Btw-tarief
TaxSchemeObject met ID (boolean)

Belasting en totalen

TaxTotal

BG-22 — Btw-uitsplitsing

TaxTotal accepteert false of een object:

SubveldBTBeschrijving
TaxAmountBT-110/BT-111Totaal btw-bedrag factuur
TaxSubtotalBG-23false of object — zie subvelden hieronder

Subvelden TaxSubtotal (BG-23 — Btw-uitsplitsingsrij):

SubveldBTBeschrijving
TaxableAmountBT-116Belastbaar bedrag btw-categorie
TaxAmountBT-117Btw-bedrag btw-categorie
TaxCategoryfalse of object — zie subvelden hieronder

Subvelden TaxSubtotal.TaxCategory:

SubveldBTBeschrijving
IDBT-118Btw-categoriecode
PercentBT-119Btw-tarief categorie
TaxExemptionReasonCodeBT-121Code reden btw-vrijstelling
TaxExemptionReasonBT-120Redentekst btw-vrijstelling
TaxSchemeObject met ID (boolean)
LegalMonetaryTotal

BG-22 — Documenttotalen

LegalMonetaryTotal accepteert false of een object:

SubveldBTBeschrijving
LineExtensionAmountBT-106Som van nettobedragen factuurregels
AllowanceTotalAmountBT-107Som van kortingen op documentniveau
ChargeTotalAmountBT-108Som van toeslagen op documentniveau
TaxExclusiveAmountBT-109Factuurtotaal excl. btw
TaxInclusiveAmountBT-112Factuurtotaal incl. btw
PrepaidAmountBT-113Vooruitbetaald bedrag
PayableRoundingAmountBT-114Afrondingsbedrag
PayableAmountBT-115Te betalen bedrag

Factuurregels

InvoiceLine

BG-25 — Factuurregel

InvoiceLine accepteert false of een object:

SubveldBTBeschrijving
IDBT-126Factuurregelidentificator
NoteBT-127Factuurregelnotitie
InvoicedQuantityBT-129 / BT-130Gefactureerde hoeveelheid / maateenheid
LineExtensionAmountBT-131Nettobedrag factuurregel
AccountingCostBT-133Boekhoudingsreferentie koper voor factuurregel
InvoicePeriodBG-26false of object — zie subvelden hieronder
OrderLineReferencefalse of object — zie subvelden hieronder
DocumentReferencefalse of object — zie subvelden hieronder
AllowanceChargeBG-27 / BG-28false of object — zie subvelden hieronder
ItemBG-31false of object — zie subvelden hieronder
PriceBG-29false of object — zie subvelden hieronder

Subvelden InvoicePeriod (BG-26 — Factuurregelperiode):

SubveldBTBeschrijving
StartDateBT-134Startdatum factuurregelperiode
EndDateBT-135Einddatum factuurregelperiode

Subvelden OrderLineReference:

SubveldBTBeschrijving
LineIDBT-132Referentie inkooporderregel

Subvelden DocumentReference:

SubveldBTBeschrijving
IDBT-128Object-identifier factuurregel (incl. schema)
DocumentTypeCodeDocumenttypecode

Subvelden AllowanceCharge (BG-27 / BG-28 — Kortingen en toeslagen factuurregel):

SubveldBTBeschrijving
ChargeIndicatortrue voor toeslag, false voor korting
AllowanceChargeReasonCodeBT-140 / BT-145Redenscode
AllowanceChargeReasonBT-139 / BT-144Redenstekst
MultiplierFactorNumericBT-138 / BT-143Percentage
AmountBT-136 / BT-141Bedrag
BaseAmountBasisbedrag

Subvelden Item (BG-31 — Artikelinformatie):

SubveldBTBeschrijving
NameBT-153Artikelnaam
DescriptionBT-154Artikelomschrijving
SellersItemIdentification.IDBT-155Verkopersidentificator artikel
BuyersItemIdentification.IDBT-156Kopersidentificator artikel
StandardItemIdentification.IDBT-157Standaardidentificator artikel (incl. schema BT-157-1)
OriginCountry.IdentificationCodeBT-159Land van oorsprong artikel
CommodityClassificationBT-158Classificatie-identifier artikel
ClassifiedTaxCategoryBG-30false of object — zie subvelden hieronder
AdditionalItemPropertyBG-32Artikelkenmerken (naam/waarde-paren)

Subvelden ClassifiedTaxCategory (BG-30 — Btw-informatie factuurregel):

SubveldBTBeschrijving
IDBT-151Btw-categoriecode gefactureerd artikel
PercentBT-152Btw-tarief gefactureerd artikel
TaxSchemeObject met ID (boolean)

Subvelden Price (BG-29 — Prijsdetails):

SubveldBTBeschrijving
PriceAmountBT-146Nettoprijsbedrag artikel
BaseQuantityBT-149 / BT-150Basishoeveelheid prijs / maateenheid
AllowanceChargefalse of object — zie subvelden hieronder

Subvelden Price.AllowanceCharge:

SubveldBTBeschrijving
ChargeIndicatorMoet false zijn (korting)
AmountBT-147Prijskorting artikel
BaseAmountBT-148Brutoprijsbedrag artikel

Respons

200 — Geslaagd

Geeft een binaire PDF-download terug.

Content-Type: application/pdf

400 — Ongeldig verzoek

{
  "error": "string"
}

Wordt geretourneerd als het bestand ontbreekt, de XML ongeldig is of het documenttype niet wordt ondersteund.

401 — Niet geautoriseerd

{
  "error": "string"
}

Wordt geretourneerd als de API-sleutel ontbreekt of ongeldig is.

Voorbeelden

Basis — PDF downloaden

curl -X POST "https://api.peppolpdf.eu/api/v1/generate-pdf" \
  -H "Authorization: Bearer JOUW_API_SLEUTEL" \
  -F "file=@factuur.xml" \
  -o factuur.pdf
genereer-pdf.ts
import fs from "fs";

const form = new FormData();
form.append("file", new Blob([fs.readFileSync("factuur.xml")], { type: "application/xml" }), "factuur.xml");
form.append("config", JSON.stringify({ 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("factuur.pdf", Buffer.from(await res.arrayBuffer()));
genereer_pdf.py
import os
import requests

with open("factuur.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": ("factuur.xml", f, "application/xml")},
    )

response.raise_for_status()

with open("factuur.pdf", "wb") as f:
    f.write(response.content)
genereer_pdf.php
<?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('factuur.xml', 'application/xml', 'factuur.xml'),
    ],
]);

$pdf      = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);

if ($httpCode !== 200) {
    throw new RuntimeException('API fout: ' . $pdf);
}

file_put_contents('factuur.pdf', $pdf);
main.go
package main

import (
	"bytes"
	"io"
	"mime/multipart"
	"net/http"
	"os"
)

func main() {
	file, _ := os.Open("factuur.xml")
	defer file.Close()

	var body bytes.Buffer
	writer := multipart.NewWriter(&body)
	part, _ := writer.CreateFormFile("file", "factuur.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("factuur.pdf")
	defer out.Close()
	io.Copy(out, resp.Body)
}
GenereerPdf.cs
using var fileStream = File.OpenRead("factuur.xml");
using var content = new MultipartFormDataContent
{
    { new StreamContent(fileStream), "file", "factuur.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("factuur.pdf", pdf);
GenereerPdf.java
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", "factuur.xml",
        RequestBody.create(new File("factuur.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 fout: " + response);
    Files.write(Path.of("factuur.pdf"), response.body().bytes());
}

Met locale en preset

curl -X POST "https://api.peppolpdf.eu/api/v1/generate-pdf" \
  -H "Authorization: Bearer JOUW_API_SLEUTEL" \
  -F "file=@factuur.xml" \
  -F 'config={"preset":"administration","locale":"nl"}' \
  -o factuur.pdf
genereer-pdf.ts
import fs from "fs";

const form = new FormData();
form.append("file", new Blob([fs.readFileSync("factuur.xml")], { type: "application/xml" }), "factuur.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("factuur.pdf", Buffer.from(await res.arrayBuffer()));
genereer_pdf.py
import os
import json
import requests

with open("factuur.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": ("factuur.xml", f, "application/xml")},
        data={"config": json.dumps({"preset": "administration", "locale": "nl"})},
    )

response.raise_for_status()

with open("factuur.pdf", "wb") as f:
    f.write(response.content)
genereer_pdf.php
<?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('factuur.xml', 'application/xml', 'factuur.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 fout: ' . $pdf);
}

file_put_contents('factuur.pdf', $pdf);
main.go
package main

import (
	"bytes"
	"io"
	"mime/multipart"
	"net/http"
	"os"
)

func main() {
	file, _ := os.Open("factuur.xml")
	defer file.Close()

	var body bytes.Buffer
	writer := multipart.NewWriter(&body)
	part, _ := writer.CreateFormFile("file", "factuur.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("factuur.pdf")
	defer out.Close()
	io.Copy(out, resp.Body)
}
GenereerPdf.cs
using var fileStream = File.OpenRead("factuur.xml");
using var content = new MultipartFormDataContent
{
    { new StreamContent(fileStream), "file", "factuur.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("factuur.pdf", pdf);
GenereerPdf.java
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", "factuur.xml",
        RequestBody.create(new File("factuur.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 fout: " + response);
    Files.write(Path.of("factuur.pdf"), response.body().bytes());
}

Met gedetailleerde veldcontrole

curl -X POST "https://api.peppolpdf.eu/api/v1/generate-pdf" \
  -H "Authorization: Bearer JOUW_API_SLEUTEL" \
  -F "file=@factuur.xml" \
  -F 'config={"locale":"nl","fields":{"ID":true,"IssueDate":true,"DueDate":true,"LegalMonetaryTotal":true,"InvoiceLine":true}}' \
  -o factuur.pdf
genereer-pdf.ts
import fs from "fs";

const config = {
  locale: "nl",
  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("factuur.xml")], { type: "application/xml" }), "factuur.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("factuur.pdf", Buffer.from(await res.arrayBuffer()));
genereer_pdf.py
import os
import json
import requests

config = {
    "locale": "nl",
    "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("factuur.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": ("factuur.xml", f, "application/xml")},
        data={"config": json.dumps(config)},
    )

response.raise_for_status()

with open("factuur.pdf", "wb") as f:
    f.write(response.content)
genereer_pdf.php
<?php

$config = [
    'locale' => 'nl',
    '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('factuur.xml', 'application/xml', 'factuur.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 fout: ' . $pdf);
}

file_put_contents('factuur.pdf', $pdf);
main.go
package main

import (
	"bytes"
	"encoding/json"
	"io"
	"mime/multipart"
	"net/http"
	"os"
)

func main() {
	config, _ := json.Marshal(map[string]any{
		"locale": "nl",
		"fields": map[string]any{
			"ID": true, "IssueDate": true, "DueDate": true,
			"LegalMonetaryTotal": true, "InvoiceLine": true,
		},
	})

	file, _ := os.Open("factuur.xml")
	defer file.Close()

	var body bytes.Buffer
	writer := multipart.NewWriter(&body)
	part, _ := writer.CreateFormFile("file", "factuur.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("factuur.pdf")
	defer out.Close()
	io.Copy(out, resp.Body)
}
GenereerPdf.cs
var config = new {
    locale = "nl",
    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("factuur.xml");
using var content = new MultipartFormDataContent
{
    { new StreamContent(fileStream), "file", "factuur.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("factuur.pdf", pdf);
GenereerPdf.java
import okhttp3.*;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;

var config = """
    {"locale":"nl","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", "factuur.xml",
        RequestBody.create(new File("factuur.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 fout: " + response);
    Files.write(Path.of("factuur.pdf"), response.body().bytes());
}

Op deze pagina