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 :
Finance | Project Operations, Human Resources, ...
Answered

Print memoryStream to screen or any printer

(0) ShareShare
ReportReport
Posted on by 260

Hello guys,

The title is pretty straight forward. 
Let`s assume I have a Base64 string which came from a PDF.
How do I send it directly to the screen or to any printer?
Right now, I have a code that convert this Base64 to PDF and send the file to the user, but I want to print it directly.

    public void convertBase64ToPdf()
    {
        System.IO.MemoryStream memoryStream = Binary::constructFromContainer(BinData::loadFromBase64(
            base64Label)).getMemoryStream() as System.IO.MemoryStream;

        File::SendFileToUser(memoryStream, 'test.pdf');
    }


Any ideas?

Thanks

I have the same question (0)
  • Verified answer
    Mea_ Profile Picture
    60,284 on at

    In my blog here MSDyn365FO. How-to send PDF document to a printer from X++ – ievgen's ax blog (wordpress.com) I show how to print a file from the attachments to a printer, to do this you need to convert it to a stream so you can reause this code. 

  • bois0155 Profile Picture
    260 on at

    Hello ievgen,

    I tried your code it works and it send to the printers using document routing.

    Do you have any idea how can I send it directly to the d365 screen?

    I tried to change your code to use printMediumType(SRSPrintMediumType::Screen)

    but didn't work

  • Suggested answer
    Mea_ Profile Picture
    60,284 on at

    Try

    Browser br = new Browser();

           str downloadUrl = File::SendFileToTempStore(_stream, _fileName, classstr(FileUploadTemporaryStorageStrategy), true);

           if (downloadUrl != '')

           {

               br.navigate(downloadUrl, true, false);

           }

  • bois0155 Profile Picture
    260 on at

    Just tried it, and it download the pdf file instead of opening a pdf preview or something to show on screen.

    I'm not sure what I want to do is possible though

    I'll keep with the printer option only for now

    Thanks

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    How your web browser deals with PDF files isn't the reponsibility of the web application. If you want to open PDF files in the browser rather then downloading them, configure your browser accordingly.

    For example, if you're using Firefox, open Settings, scroll down to Applications, put PDF to Search file types or applications, select Portable Document Format (PDF) and set Action to Open in Firefox.

  • bois0155 Profile Picture
    260 on at

    Thank you guys.

    I was expecting a way to open it like a SSRS report using the Pdf viewer from d365 or something related.

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Aha, then "send it directly to the screen" means "showing the content of the file inside an F&O form", right?

    SrsReportViewerForm uses a special type of control (Report Viewer) for this purpose.

    A similar approach is used in document management, where DocuView form utilizes Document Viewer Container control. Maybe you would be able to reuse it.

  • bois0155 Profile Picture
    260 on at

    Yes, sorry to not be clearly enough.

    Thank you Martin I'll check it out

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 592 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 478 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 305 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans