With the new Dynamics 365 Business Central 2025 Wave 2 release (v27) and AL Language version 16.x, Microsoft introduced the support for a new ExtendedDataType
value (for Media
and MediaSet
fields) called Document.
This new ExtendedDataType allows the client to render elements such as PDF files and images in FactBoxes (ListPart and CardPart page types). With this new property you can upload a PDF file to a Media field and then display it as a preview in web client.
To show how to do that in AL, I’ve added the following Media field (called PDF Document) to the Customer table:
Then I’ve created a FactBox to show the preview of the uploaded file in the Customer Card page:
And here is the code to upload the PDF file into the Media field and preview it in the UI of our CardPart page:
As you can see from the above code, you need to:
Result in the UI will be the following:
Full code (for reference) is the following:
page 50102 "SD PDF Preview"
{
Caption = 'SD PDF Preview Demo';
DeleteAllowed = false;
InsertAllowed = false;
LinksAllowed = false;
PageType = CardPart;
SourceTable = Customer;
layout
{
area(content)
{
field("PDF Document"; Rec."PDF Document")
{
ApplicationArea = All;
ShowCaption = false;
}
}
}
actions
{
area(processing)
{
action(ImportPDF)
{
ApplicationArea = All;
Caption = 'Import PDF';
Image = Import;
trigger OnAction()
var
FileManagement: Codeunit "File Management";
FileName: Text;
InStr, ImgStream : InStream;
TempBlob: Codeunit "Temp Blob";
PDFDocument: Codeunit "PDF Document";
lblConfirmReplace: Label 'Do you want to replace the existing PDF file?';
lblDialogUpload: Label 'Select a PDF file to upload';
begin
if Rec."PDF Document".HasValue() then
if not Confirm(lblConfirmReplace) then
exit;
UploadIntoStream(lblDialogUpload, '', '', FileName, InStr);
TempBlob.CreateInStream(ImgStream);
PDFDocument.Load(InStr);
PDFDocument.ConvertToImage(ImgStream, Enum::"Image Format"::Png, 1);
Clear(Rec."PDF Document");
Rec."PDF Document".ImportStream(ImgStream, FileName);
if not Rec.Modify(true) then
Rec.Insert(true);
end;
}
}
}
}