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 :
Microsoft Dynamics NAV (Archived)

Convert PDF to Base64 using OutStream

(0) ShareShare
ReportReport
Posted on by

Hi Experts, 

I have a requirement wherein I have to convert the saved PDF to Base64. I have written the following code but that doesn't seem to work and there are hardly any blogs regarding it.

Filename := 'C:\NAV\Service Invoices\PSI0000081.pdf';
MyFile.OPEN(Filename);
MyFile.CREATEINSTREAM(IStream);
MemoryStream := MemoryStream.MemoryStream();
COPYSTREAM(MemoryStream,IStream);
Byte := MemoryStream.GetBuffer();
locOutFile.ADDTEXT(Convert.ToBase64String(Byte));
MESSAGE(FORMAT(locOutFile));
MyFile.CLOSE; 

Can anybody suggest me how than can be done or where did I go wrong? Your suggestions are welcomed. 

Thanks in advance. 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    I Gusti Made Ari Profile Picture
    3,600 on at

    You can use File Management codeunit and TempBlob record

    FileName :=  'C:\NAV\Service Invoices\PSI0000081.pdf';

    FileManagement.BLOBImportFromServerFile(TempBlob,FileName);

    MESSAGE('%1',TempBlob.ToBase64String);

    Since you are using MESSAGE prompt , try to convert PDF file with size smaller than 20 KB since the converted base64 text can be too long and cannot show in message prompt.

    Alternatively save the base64 text in blob field or text file instead.

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 > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans