Options

Send pdf report from nav to api

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

Answers

  • Options
    ShaiHuludShaiHulud Member Posts: 228
    You could convert the blob to Base64-encoded string and send that back. In NAV 2015 there are no standard codeunit for it, so you'd need to use the "System.Convert" class from mscorlib.

    In newer versions, the "Base64 Convert" codeunit implements "ToBase64" from InStream as such:
    procedure ToBase64(InStream: InStream; InsertLineBreaks: Boolean): Text
        var
            Convert: DotNet Convert;
            MemoryStream: DotNet MemoryStream;
            InputArray: DotNet Array;
            Base64FormattingOptions: DotNet Base64FormattingOptions;
            Base64String: Text;
        begin
            MemoryStream := MemoryStream.MemoryStream();
            CopyStream(MemoryStream, InStream);
            InputArray := MemoryStream.ToArray();
    
            if InsertLineBreaks then
                Base64String := Convert.ToBase64String(InputArray, Base64FormattingOptions.InsertLineBreaks)
            else
                Base64String := Convert.ToBase64String(InputArray);
    
            MemoryStream.Close();
            exit(Base64String);
        end;
    
    
    I have a feeling with small adjustments, this could work for NAV 2015 as well
  • Options
    MortenSteengaardMortenSteengaard Member Posts: 131
    Hi ShaiHulud.

    Thank you very much for your reply.

    I have implemented something like this, but before it worked, we decided to have NAV createing the pdf file in Windows and then return the filename to the C# program. Then the C# program can get the pdf file directly from Windows.

    Thank you for your time.

    Best regards,

    Morten
Sign In or Register to comment.