Attachments
Supporting documents (BG-24) such as a timesheet or a drawing travel with the invoice, embedded as base64, or are referenced by URL. Each needs a reference (BT-122). The snippets extend the base invoice.
Embed a file
The content is base64 text with a MIME code from the list Peppol allows and a file name. Encode it with btoa(), which every runtime has; the libraries never use Buffer.
ts
// btoa() exists in Node.js, Bun, Deno and browsers; no Buffer needed.
function toBase64(bytes: Uint8Array): string {
let binary = '';
for (const byte of bytes) {
binary += String.fromCharCode(byte);
}
return btoa(binary);
}
const csv = new TextEncoder().encode('date,hours\n2017-11-01,7.5\n');
const embedded: InvoiceInput['additionalDocumentReference'] = [
{
id: 'TS-2017-11',
documentDescription: 'Timesheet November 2017',
attachment: {
embeddedDocumentBinaryObject: {
value: toBase64(csv),
mimeCode: 'text/csv', // one of the MIME codes Peppol allows
filename: 'timesheet.csv',
},
},
},
];Link to a file
ts
const external: InvoiceInput['additionalDocumentReference'] = [
{
id: 'DRAWING-7',
documentDescription: 'Technical drawing',
attachment: { externalReference: { uri: 'https://supplier.example/drawings/7.pdf' } },
},
];A document reference holds either an embedded file or a link, not both.