Dynamics 365 Business Central: previewing PDF files in web client using the new ExtendedDataType = Document.

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:

  1. Load the PDF file content into an Instream (using the PDF Document codeunit).
  2. Convert the PDF document in an image by calling the ConvertToImage method. This procedure is used to convert a PDF file to an image and wants the stream of the PDF file, the image format to convert the PDF to and the page number of the PDF to convert as image preview. Please note that at the time of writing this post you need to always pass 1 to the ConvertToImage function as the page number to preview. An update to support passing a different page number is in rollout in these days.
  3. Load the PDF into the Media field.

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;
}
}
}
}

Original Post https://demiliani.com/2025/10/14/dynamics-365-business-central-previewing-pdf-files-in-web-client-using-the-new-extendeddatatype-document/

0 Votes: 0 Upvotes, 0 Downvotes (0 Points)

Leave a reply

Follow
Search
Popular Now
Loading

Signing-in 3 seconds...

Signing-up 3 seconds...