web
You’re offline. This is a read only version of the page.
close
Skip to main content
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,045 Moderator on at
    RE: Send pdf report from nav to api

    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,045 Moderator on at
    RE: Send pdf report from nav to api

    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
    93,208 Super User 2025 Season 2 on at
    RE: Send pdf report from nav to api

    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
    RE: Send pdf report from nav to api

    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,045 Moderator on at
    RE: Send pdf report from nav to api

    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
    RE: Send pdf report from nav to api

    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,045 Moderator on at
    RE: Send pdf report from nav to api

    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

Responsible AI policies

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

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 2,828

#2
Sumit Singh Profile Picture

Sumit Singh 2,617

#3
YUN ZHU Profile Picture

YUN ZHU 1,861 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans