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

# Pdf - Stationery

Codeunit `5523673` `bdev.Pdf - Stationery` applies a stationery - a PDF document that is laid under the pages of another PDF - to a document of your own. It is what the app itself uses when a report selection carries a stationery configuration, so a document you process this way looks exactly like one the app processed.

There are two ways to state which stationery to apply:

- **a stationery document**, passed as a `Temp Blob`. It is laid under every page.
- **a stationery configuration**, a `bdev.Pdf Stationery Config.` record. The configuration states a PDF file per page position - first page, following pages, second last page, last page, or all pages - and whether it applies to the print intent at hand.

```pascal
    pdfStationery: Codeunit "bdev.Pdf - Stationery";
```

## ApplyStationeryToDocument(Codeunit, Codeunit)

Applies a stationery document to every page of a PDF document.

```pascal
    procedure ApplyStationeryToDocument(var document: Codeunit "Temp Blob"; stationery: Codeunit "Temp Blob")
```

| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `document` | Codeunit "Temp Blob" | The PDF document. It is replaced by the result. |
| `stationery` | Codeunit "Temp Blob" | The stationery document. |

### Example

```pascal
    procedure ApplyStationery(var document: Codeunit "Temp Blob")
    var
        mySetup: Record "My Setup";
        pdfStationery: Codeunit "bdev.Pdf - Stationery";
        stationery: Codeunit "Temp Blob";
    begin
        mySetup.Get();

        stationery.FromRecord(mySetup, mySetup.FieldNo("Stationery Document"));

        pdfStationery.ApplyStationeryToDocument(document, stationery);
    end;
```

## ApplyStationeryToDocument(Codeunit, Record)

Applies the page settings of a stationery configuration to a PDF document, with the print intent `Print`.

```pascal
    procedure ApplyStationeryToDocument(var document: Codeunit "Temp Blob"; pdfStationeryConfig: Record "bdev.Pdf Stationery Config.")
```

| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `document` | Codeunit "Temp Blob" | The PDF document. It is replaced by the result. |
| `pdfStationeryConfig` | Record "bdev.Pdf Stationery Config." | The stationery configuration to apply. |

### Example

```pascal
    procedure ApplyStationery(var document: Codeunit "Temp Blob"; stationeryConfigCode: Code[20])
    var
        pdfStationeryConfig: Record "bdev.Pdf Stationery Config.";
        pdfStationery: Codeunit "bdev.Pdf - Stationery";
    begin
        if (not pdfStationeryConfig.Get(stationeryConfigCode)) then
            exit;

        pdfStationery.ApplyStationeryToDocument(document, pdfStationeryConfig);
    end;
```

Letting the user pick the configuration works the same way as anywhere else:

```pascal
    procedure SelectAndApplyStationery(var document: Codeunit "Temp Blob")
    var
        pdfStationeryConfig: Record "bdev.Pdf Stationery Config.";
        pdfStationery: Codeunit "bdev.Pdf - Stationery";
        pdfStationeryConfigList: Page "bdev.Pdf Stat. Config. List";
    begin
        pdfStationeryConfigList.LookupMode(true);
        if (pdfStationeryConfigList.RunModal() <> Action::LookupOK) then
            exit;
        pdfStationeryConfigList.GetRecord(pdfStationeryConfig);

        pdfStationery.ApplyStationeryToDocument(document, pdfStationeryConfig);
    end;
```

## ApplyStationeryToDocument(Codeunit, Record, Code)

Applies the page settings of a stationery configuration in a given language, with the print intent `Print`.

```pascal
    procedure ApplyStationeryToDocument(var document: Codeunit "Temp Blob"; pdfStationeryConfig: Record "bdev.Pdf Stationery Config."; languageCode: Code[10])
```

| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `document` | Codeunit "Temp Blob" | The PDF document. It is replaced by the result. |
| `pdfStationeryConfig` | Record "bdev.Pdf Stationery Config." | The stationery configuration to apply. |
| `languageCode` | Code[10] | The language of the stationery. |

The language decides which PDF file the configuration resolves to. A PDF file marked as `All Languages` is used regardless of the language code, and so is the default file when no translation exists for the language - see [Pdf - File](pdf-file.mdx).

## ApplyStationeryToDocument(Codeunit, Record, Enum)

Applies the page settings of a stationery configuration for a given print intent.

```pascal
    procedure ApplyStationeryToDocument(var document: Codeunit "Temp Blob"; pdfStationeryConfig: Record "bdev.Pdf Stationery Config."; documentPrintIntent: Enum "bdev.Pdf Document Print Intent")
```

| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `document` | Codeunit "Temp Blob" | The PDF document. It is replaced by the result. |
| `pdfStationeryConfig` | Record "bdev.Pdf Stationery Config." | The stationery configuration to apply. |
| `documentPrintIntent` | Enum "bdev.Pdf Document Print Intent" | `Print`, `Preview`, `Download` or `Save`. |

## ApplyStationeryToDocument(Codeunit, Record, Enum, Code)

The full overload: a stationery configuration, a print intent and a language.

```pascal
    procedure ApplyStationeryToDocument(var document: Codeunit "Temp Blob"; pdfStationeryConfig: Record "bdev.Pdf Stationery Config."; documentPrintIntent: Enum "bdev.Pdf Document Print Intent"; languageCode: Code[10])
```

| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `document` | Codeunit "Temp Blob" | The PDF document. It is replaced by the result. |
| `pdfStationeryConfig` | Record "bdev.Pdf Stationery Config." | The stationery configuration to apply. |
| `documentPrintIntent` | Enum "bdev.Pdf Document Print Intent" | `Print`, `Preview`, `Download` or `Save`. |
| `languageCode` | Code[10] | The language of the stationery. |

## The print intent decides whether anything happens

A stationery configuration carries a `Perform on ...` switch per print intent. When the switch of the intent you pass is off, the method returns **without applying anything and without an error** - the same behavior the app shows when a user previews a document whose stationery is configured for printing only.

<Callout type="caution" title="A silent return is not a failure">
The overloads that take a configuration return nothing, and a disabled configuration is indistinguishable from an applied one at the call site. If your process depends on the stationery having been applied, read the `Perform on ...` field of the configuration before you call, or compare the document size afterwards.
</Callout>

The overload that takes a stationery document rather than a configuration has no such switch and always applies the stationery.

## See also

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