import { Callout } from "zudoku/ui/Callout";

# Pdf API (obsolete)

Codeunit `5523590` `bdev.Pdf API` was the single entry point of the app before version 20.5. It has been split into one codeunit per capability and is obsolete since then.

```pascal
    ObsoleteState = Pending;
    ObsoleteReason = 'Use Pdf - Stationery, Pdf - Concatenate, Pdf - Sign codeunit instead.';
    ObsoleteTag = '20.5';
```

<Callout type="caution" title="Do not write new code against this codeunit">
`ObsoleteState = Pending` means the codeunit still compiles, with a warning. It will be removed in a future major version. New code belongs on the codeunits listed below.
</Callout>

## What to use instead

| `bdev.Pdf API` method | Replacement |
| --- | --- |
| `ApplyStationeryToDocument` (all five overloads) | [`bdev.Pdf - Stationery`](pdf-stationery.mdx), same signatures |
| `ConcatenateDocument(Codeunit, Codeunit)` | [`bdev.Pdf - Concatenate`](pdf-concatenate.mdx), same signature |
| `ConcatenateDocument(List of [Text])` | [`bdev.Pdf - Concatenate`](pdf-concatenate.mdx), same signature |
| `SignDocument` | No replacement yet - see below |
| `CreateZUGFeRDInvoice`, `CreateZUGFeRDInvoiceXml` | No replacement yet - see below |

The stationery and concatenate methods forward to the same implementation as their replacements, so moving a call over is a change of the variable declaration and nothing else.

## The methods without a replacement

The obsolete reason names a `Pdf - Sign` codeunit, but it does not exist yet. Until it does, `bdev.Pdf API` remains the only way to reach the following from AL.

### SignDocument

Signs a PDF document digitally with a certificate of your own.

```pascal
    procedure SignDocument(var document: Codeunit "Temp Blob"; certificate: Codeunit "Temp Blob"; certificatePin: Text)
```

| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `document` | Codeunit "Temp Blob" | The PDF document. It is replaced by the signed document. |
| `certificate` | Codeunit "Temp Blob" | The certificate file. |
| `certificatePin` | Text | The PIN of the certificate. |

```pascal
    procedure SignDocument(var document: Codeunit "Temp Blob")
    var
        mySetup: Record "My Setup";
        pdfApi: Codeunit "bdev.Pdf API";
        certificate: Codeunit "Temp Blob";
    begin
        mySetup.Get();

        certificate.FromRecord(mySetup, mySetup.FieldNo("Certificate File"));

        pdfApi.SignDocument(document, certificate, mySetup."Certificate PIN");
    end;
```

<Callout type="caution" title="The certificate leaves Business Central">
The certificate and its PIN are sent to the PDF service to perform the signature. Signing through a `PDF Signing Configuration` rather than through this method keeps the certificate in the app, where it is stored as part of the configuration and referenced by the report selection.
</Callout>

### CreateZUGFeRDInvoice and CreateZUGFeRDInvoiceXml

Produce the ZUGFeRD / Factur-X representation of a posted sales invoice: the XML alone, or a PDF with the XML embedded.

```pascal
    procedure CreateZUGFeRDInvoice(var document: Codeunit "Temp Blob"; invoice: Record "Sales Invoice Header")
    procedure CreateZUGFeRDInvoiceXml(invoice: Record "Sales Invoice Header"): Codeunit "Temp Blob"
```

| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `document` | Codeunit "Temp Blob" | The PDF of the invoice. It is replaced by the PDF with the ZUGFeRD XML embedded. |
| `invoice` | Record "Sales Invoice Header" | The posted sales invoice the XML is built from. |

`CreateZUGFeRDInvoiceXml` returns the XML as a `Temp Blob` codeunit.

`CreateZUGFeRDInvoiceXml` builds the XML in Business Central and needs nothing else. `CreateZUGFeRDInvoice` embeds it into the PDF through the PDF service and needs the separately licensed **ZUGFeRD** feature of the app; the service call is made with a `PDF A/3-U` conformance level and version `V2_1`.

There is no counterpart for credit memos on this codeunit, although the app produces them during report processing.

## See also

- [365 business PDF - Overview](readme.mdx)
- [Pdf - Stationery](pdf-stationery.mdx)
- [Pdf - Concatenate](pdf-concatenate.mdx)
- [Documentation - Signing](../../en-us/365-business-pdf/signing.md)
