Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

Send pdf report from nav to api

(1) ShareShare
ReportReport
Posted on by 543

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

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 993 Super User 2024 Season 1 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!

  • Morten Steengaard Profile Picture
    Morten Steengaard 543 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
    Inge M. Bruvik 993 Super User 2024 Season 1 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
    Morten Steengaard 543 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
    YUN ZHU Profile Picture
    YUN ZHU 75,673 Super User 2024 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

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 993 Super User 2024 Season 1 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
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 993 Super User 2024 Season 1 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

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,661 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,379 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans