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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Send pdf report from nav to api

(1) ShareShare
ReportReport
Posted on by 555

Hi experts,

The task is to create a web service that creates a report as a pdf file and returns the file.

This must be done in NAV 2015.

I have made a web service that saves the wanted report as pdf in a blob field in the table "Temp Blob".

How do I return the blob field to the api?

Best regards,

Morten

I have the same question (0)
  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,161 Moderator on at

    You need to convert the content of your blob into a Base64 encoded string and then return the base64 encoded string through your API.

    I do not have a 2015 version installed and I can not remember if there is a base64 encoder available there like there is in the newest version.

    You find find a DLL to help you with the base64 encoding.

    Maybe this can be helpful for you:

    forum.mibuso.com/.../post-of-code-base64-encoding-and-decoding

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,161 Moderator on at

    The newest version have it's own base 64 encoding codeunit.

    I am not sure if you will find that in NAV 2015

    learn.microsoft.com/.../system-application-codeunit-base64-convert

  • Suggested answer
    YUN ZHU Profile Picture
    98,507 Super User 2026 Season 1 on at

    Hi, Here's a simple example that hopefully gives you some hints.

    https://dynamics.is/?p=443

    Thanks

    ZHU

  • Morten Steengaard Profile Picture
    555 on at

    Hi Inge and YOU ZHU.

    Thank you very much, both!

    I have found out that it is going to be made in NAV 2016 and not NAV 2015.

    The base64 codeunit is not available in these old versions.

    I have made a procedure that has a VAR parameter of type BigText. The pdf file is saved in Windows and then I use the dll files to copy the file into the VAR parameter. Afterwards the VAR parameter has the length of more than 200000, so it should be right.

    When I call the procedure from a C# program or from the Google Chrome extension Wizdler, I get this error:

    Microsoft Dynamics NAV Business Web Services attempted to issue a client callback to download a file: Invoice.pdf (CodeUnit 50000 myCodeUnitName). Client callbacks are not supported on Microsoft Dynamics NAV Business Web Services.

    When I ran my code in NAV development environment, it asked the first time, if it should use the dlls. I selected "always". Now that popup does not come anymore, so I don't know what "client callback" there is.

    Here is my code:

    TempBlob.RESET();

    TempBlob.Blob.CREATEOUTSTREAM(OutS);

    REPORT.SAVEAS(206, TempText, REPORTFORMAT::Pdf, OutS);

    TempBlob.INSERT();

    TempBlob.CALCFIELDS(Blob);

    TempBlob.Blob.CREATEINSTREAM(InS);

    NewFileName := 'Invoice.pdf';

    DOWNLOADFROMSTREAM(InS,'','<TEMP>', '', NewFileName);

    CREATE(Document, FALSE, TRUE);

    Element := Document.createNode('element', 'ImageFile', 'whatIsThis');

    Element.dataType := 'bin.base64';

    CREATE(Stream, FALSE, TRUE);

    Stream.Type := 1;

    Stream.Open;

    Stream.LoadFromFile(NewFileName);

    Element.nodeTypedValue := Stream.Read;

    Stream.Close;

    Invoice.ADDTEXT(Element.text);

    CLEAR(Stream);

    CLEAR(Element);

    CLEAR(Document);

    //message('%1', Invoice.LENGTH);

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,161 Moderator on at

    I do not have these old versions up running.

    But I assume the client call back is caused by the report generation.

    So maybe you have to split the process into to stept.

    First generate the report and save it as a blob filed in a table so that your webservice do not have to do report generation, but only handle the value in a blob field.

  • Morten Steengaard Profile Picture
    555 on at

    Hi Inge.

    Thanks for that idea. That may be a solution.

    For now, we use the webservice to generate the pdf file in Windows and then send the filename to the C# program. Then the C# program can get the pdf file directly without asking NAV.

    Thank you for your time!

    Best regards,

    Morten

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,161 Moderator on at

    You are welcome!

    Good to hear that you found a solution that is working for you!

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,821 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,122 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 959 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans