web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

CONVERT REPORT PDF TO BASE64 USING BIGTEXT

(2) ShareShare
ReportReport
Posted on by 281
Hi, 
I want to convert a base report pdf to BASE64 string without using blob field, & while using big big text datatype only.
 
Plz help me with the code here 
 
 
I have the same question (0)
  • Suggested answer
    Suresh Kulla Profile Picture
    50,247 Super User 2025 Season 2 on at
    Are you on OnPrem or Saas version? if you are using OnPrem you can use File DataType to create Instream and then convert to base64 string.
     
     
  • Suggested answer
    CU22100733-0 Profile Picture
    281 on at
    Not able to use file datatype procedure, Plz suggest something else
  • Suresh K Profile Picture
    54 on at
    You didnt answer my question, are you on Saas or OnPrem ?
  • Suggested answer
    Sami Ullah Profile Picture
    315 Moderator on at
    Hi,
    Please try this code.
     
    var
        ReportSelections: Record "Report Selections"; 
        TempReportSelections: Record "Report Selections" temporary; 
        TempBlob: Codeunit "Temp Blob"; 
        Base64Convert: Codeunit "Base64 Convert"; 
        outStreamReport: OutStream; 
        inStreamReport: InStream; 
        ReportUsage: Enum "Report Selection Usage"; 
        DocumentPrint: Codeunit "Document-Print"; 
        SourceRecordRef: RecordRef; 
        SalesHeader: Record "Sales Header"; 
        DocumentBase64: Text; 
    begin
        // If you already have a RecordRef, you can skip the next four lines.
        if not SalesHeader.FindFirst() then 
            // For testing purposes, retrieving the first record of the Sales Header.
            // In your real scenario, replace this with the necessary conditions.
            exit; 
    
        SalesHeader.SetRecFilter(); 
        // Set the filter on SalesHeader to be used for the RecordRef.
    
        SourceRecordRef.GetTable(SalesHeader); 
        // Assign the SalesHeader record to the SourceRecordRef.
    
        ReportUsage := DocumentPrint.GetSalesDocTypeUsage(SalesHeader); 
        // Determine the report usage based on the document type of the Sales Header.
    
        ReportSelections.FindReportUsageForCust(ReportUsage, SalesHeader."No.", TempReportSelections); 
        // Find the appropriate report selection for the customer based on the report usage and Sales Header number.
        // Store the result in a temporary Report Selections record (TempReportSelections).
    
        TempBlob.CreateOutStream(outStreamReport); 
        // Create an output stream in the TempBlob to store the generated report.
    
        ReportSelections.SaveReportAsPDFInTempBlob(
            TempBlob, TempReportSelections."Report ID", 
            SourceRecordRef, TempReportSelections."Custom Report Layout Code", ReportUsage
        ); 
        // Save the selected report as a PDF into TempBlob using the specified report ID, 
        // custom report layout, and report usage.
    
        TempBlob.CreateInStream(inStreamReport); 
        // Create an input stream from the TempBlob to read the PDF report data.
    
        DocumentBase64 := Base64Convert.ToBase64(inStreamReport, false);
        // Convert the report data from the input stream to a Base64-encoded string 
        // and assign it to the DocumentBase64 variable.
    end;
     
  • Suggested answer
    YUN ZHU Profile Picture
    95,748 Super User 2025 Season 2 on at
    Hi, hope the following helps.
    Dynamics 365 Business Central: How to save a report as encoded text (Base64 String) via AL
     
    Thanks.
    ZHU
  • CU22100733-0 Profile Picture
    281 on at
    Hello @Suresh K, I am not able to use file datatype functions as it showed that it is for OnPrem only, so I guess I have saas version
  • Gerardo Rentería García Profile Picture
    25,373 Most Valuable Professional on at

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,092

#2
YUN ZHU Profile Picture

YUN ZHU 663 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 515

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans