Pdf - File
Codeunit 5523672 bdev.Pdf - File reads a PDF file that is stored in the app. PDF Files is where a user uploads the documents a stationery or a concatenate configuration refers to - a letterhead, a terms and conditions page, a leaflet - and the same documents are available to your extension.
Code
How a PDF file is resolved
A PDF Files record holds one document and, optionally, one translation per language in PDF File Translations. Which document is returned for a language code follows three rules:
- the record is marked as All Languages, or no language code is asked for - the document of the record itself is returned;
- a translation exists for the language code - the document of the translation is returned;
- no translation exists for the language code - the document of the record itself is returned as the fallback.
A language that has no translation therefore never fails; it falls back to the default document. That is what makes it safe to pass the language of a sales document straight through.
GetPdfFile(Code, Code)
Returns the document of the PDF file with the given code, in the given language.
Code
| Parameter | Type | Description |
|---|---|---|
pdfFileCode | Code[20] | Code of the PDF file, as set up in PDF Files. |
languageCode | Code[10] | The language of the PDF file. An empty code returns the document of the default language. |
Returns the PDF file as a Temp Blob codeunit.
The method raises an error naming the code when no PDF file is set up for it. A language without a translation is not an error - it falls back to the default document, as described above.
Version
GetPdfFile(Code[20], Code[10]) has been introduced with 365 business PDF 20.6. The two overloads it replaces - GetPdfFile() and GetPdfFile(Code[10]) - never stated which PDF file to read and returned an empty document. They are obsolete as of 20.6; move calls over to the overload above.
Example
Code
The document the codeunit returns is the one a stationery configuration would use for the same language, so a letterhead you apply yourself through Pdf - Stationery matches the one the app applies during report processing.
PdfFileExists(Code)
States whether a PDF file is set up for the code.
Code
| Parameter | Type | Description |
|---|---|---|
pdfFileCode | Code[20] | Code of the PDF file. |
Returns true when the PDF file exists.
Use it where a missing PDF file is an expected state rather than an error - to hide an action, or to fall back to a document of your own - instead of catching the error of GetPdfFile.
