Printing Blob Field

I have pasted this text from Word Document to a NAV Blob Field: ~!@#$%^&*() ‘something’ “something more” end

And printed this blob fields through a NAV report as pdf, it looks like this:
hnjqohi8nmha.png

It could not decode the Left Single Quotation, Right Single Quotation, Left Double Quotation, Right Double Quotation when printing.

This is my code.

CALCFIELDS("Additional Comments");
"Additional Comments".CREATEINSTREAM(iStream,TEXTENCODING::UTF8);
Encoding:=Encoding.UTF8;
StreamReader := StreamReader.StreamReader(iStream,Encoding,TRUE);


Here,
StreamReader is a DotNet variable of subtype System.IO.StreamReader.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
and Encoding is a DotNet variable of subtype System.Text.Encoding.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

Your suggestion will be very much appreciated to resolve the issue.

Answers

  • txerifftxeriff Member Posts: 492
    edited 2021-11-17
    Hi,

    Not sure why you are using dotnets to read from a blob, NAV can handle this.

    Can you try something like:
    //no length takes all the text. vTextline should be text with no length or in old nav versions you may need to use bigtext.addtext etc.      
    repeat
        vInStr.READTEXT(vtextLine);                       
    until vInstr.EOS;
    

    Also, I recall if you are about to read BLOBs from SQL query etc, you need to set BLOB properties compressed=false. Even if you do that, some characters are not well recognised etc.
  • PurpleHazePurpleHaze Member Posts: 42
    Perhaps this one:
    CALCFIELDS(Description);
    Description.CREATEINSTREAM(InStr);
    BinaryReader := BinaryReader.BinaryReader(InStr,Encoding.UTF8);
    IF NOT ISNULL(BinaryReader) THEN BEGIN   //read value from BLOB field
      IF BinaryReader.BaseStream.Length > 0 THEN
        MyText := BinaryReader.ReadString;
      BinaryReader.Close;
    END;
    

    https://andreilungu.com/read-write-text-from-to-blob-field-nav/
  • txerifftxeriff Member Posts: 492
    ah, now I realise you want to upload a blob file (word document), not the text itself.

    Then yes, you can do something like this, I used for reading an image
      vChars: Byte;
      repeat
                    pInStream.Read(vChars, 1);
                    vOutStr.Write(vChars, 1);
                until pInStream.EOS;
    
  • fazlehasanfazlehasan Member Posts: 62
    edited 2021-11-17
    I go this error when I tried to utilize one of the suggestions using Binary Reader, probable it could not decode the Left/Right Single/Double quotation marks (U+2018, U+2019,U+201C,U+201D) and got the error:
    jedhzh912ag8.png

    Thanks txeriff and PurpleHaze for your help. You are awesome.
  • fazlehasanfazlehasan Member Posts: 62
    edited 2021-11-17
    Finally this code worked: thanks for your help.

    "Additional Comments".CREATEINSTREAM(iStream1);
    binRdr:=binRdr.BinaryReader(iStream1,Encoding.UTF8);
    IF NOT ISNULL(binRdr) THEN BEGIN //read value from BLOB field
    length:=binRdr.BaseStream.Length;
    IF length > 0 THEN BEGIN
    WHILE i<length DO BEGIN
    var_char:=binRdr.ReadByte();
    TokenText+=FORMAT(var_char);
    i+=1;
    END;
    END;
    MESSAGE('text %1',TokenText);
    binRdr.Close;
    END;
Sign In or Register to comment.