RichTextBox is not displaying embedded image

Posted by: roman.mueller on 17 June 2020, 6:41 pm EST

    • Post Options:
    • Link

    Posted 17 June 2020, 6:41 pm EST

    I have a report with a RichTextBox in the detail section. Unfortunately, the embedded image of the raw RTF is not displayed. The data is loaded from the database and when I’m in the OnFormat method of the detail, the raw RTF looks as the attachment.

    It seems not to work, when I assign the raw RTF to the RTF property of the RichTextBox. Even when I convert the raw RTF to a stream and use the Load method of the RichTextBox, it’s not working. The RTF, which is in the RTF property of the control, is a way shorter and the image is lost.

    How can I fix that?

  • Posted 17 June 2020, 7:03 pm EST

    Hello,

    Could you please rtf text with us so that I can replicate the issue at my end. Please share the file in the ZIP format.

    Thanks,

    Mohit

  • Posted 17 June 2020, 7:07 pm EST

    Oops… sorry. Just realized that the .rtf file was not uploaded.

    RtfTest_Raw.zip

  • Posted 17 June 2020, 7:23 pm EST

    Hello,

    Can you please try with the attached RTF text:

    test.zip

    I just opened your RTF in WordPad and resave it.

    Thanks,

    Mohit

  • Posted 18 June 2020, 1:26 am EST - Updated 30 September 2022, 8:05 am EST

    The image is now displayed, but the control on the report is not resized as it should and after your save, the format of the RTF seems a bit different now (text indented). You can see the two images in the my grid.



    and in the report



    I also tried to “simplify” the RTF by inserting it into a common .NET Framework RichTextBox and save it from there to a stream. But that’s a bit awful and doesn’t work either. Any suggestions?

  • Posted 18 June 2020, 8:41 pm EST - Updated 30 September 2022, 8:05 am EST

    Hello,

    but the control on the report is not resized as it should

    Can you try after Setting the “CanGrow” property of the RichTextBox control to “True”?

    the format of the RTF seems a bit different now (text indented).

    I am unable to reproduce the issue at my end. Please refer to the attached report and image.

    Could you please share the exact version that you are using at your end.

    Thanks,

    Mohit

    Untitled.zip

  • Posted 20 June 2020, 9:04 pm EST

    Ok, but that’s not a solution that I save each RTF within my application with WordPad. How would you do that? Even when I load my original RTF into a .NET Framework RichTextBox and save it there (the RTF changes slightly), the images are still not visible.

  • Posted 22 June 2020, 12:46 am EST

    Hello,

    Did you try with the following lines of code;

    this.richTextBox1.LoadFile(@"D:\Wyn_Data\file-1829c683-db0c-445c-9247-2ac282bb57e8\RtfTest_Raw.rtf");
              System.IO.MemoryStream ms = new System.IO.MemoryStream();
              this.richTextBox1.SaveFile(ms, RichTextBoxStreamType.RichText);
              ms.Position = 0;
              SectionReport1 rpt = new SectionReport1();
              (rpt.Sections[1].Controls[0] as GrapeCity.ActiveReports.SectionReportModel.RichTextBox).Load(ms, GrapeCity.ActiveReports.SectionReportModel.RichTextType.Rtf);
              viewer1.LoadDocument(rpt);
    

    Thanks,

    Mohit

  • Posted 22 June 2020, 1:01 am EST

    Also, refer to the attached sample.

    rpt_PAgeBreak.zip

  • Posted 2 July 2020, 1:01 am EST

    I created a sample of my report (any improvements are welcome). Unfortunately, the RTF with the image is still cut. RtfReport.zip

    Any help is appreciated.

  • Posted 2 July 2020, 11:36 pm EST

    Hello,

    Please use the following lines of code in the script section of “DocumentPositionSubReport”

    
    public void detail_Format()
    {
    	this.richTextBoxRtfText.RTF = s;
    	if(s.Length>=1000)
    		this.richTextBoxRtfText.Height = 1.8F;
    	//this.richTextBoxRtfText.RTF= this.richTextBoxRtfText.RTF;
    }
    
    string s;
    
    
    
    
    public bool ActiveReport_FetchData(bool eof)
    {
    	s = (string)rpt.Fields["RtfText"].Value;
    	return eof;
    }
    
    

    Also, set the “CanShrink” property of the “richTextBoxRtfText” to “False” in the “DocumentPositionSubReport” report.

    Please refer to the attached modified report.

    Thanks,

    Mohit

    DocumentPositionSubReport.zip

  • Posted 5 July 2020, 7:13 pm EST

    CanShrink to False? But in that case, the size remains at the 1.8F.

    I quickly checked it in my productive environment. Unfortunately, the height remains at the fixed height and does not shrink to the required height.

    I would like to have the row just as high as effectively needed and not a fixed height. How can I achieve this?

  • Posted 5 July 2020, 8:42 pm EST

    Hello,

    Can you try with the following line of code:

    public void detail_Format()
    {
    	this.richTextBoxRtfText.RTF = s;
    	if(s.Length>=1000)
    		this.richTextBoxRtfText.Height = 1.8F;
             else
    		this.richTextBoxRtfText.Height = 0.2F;
    	//this.richTextBoxRtfText.RTF= this.richTextBoxRtfText.RTF;
    }
    
    string s;
    
    
    
    
    public bool ActiveReport_FetchData(bool eof)
    {
    	s = (string)rpt.Fields["RtfText"].Value;
    	return eof;
    }
    

    Thanks,

    Mohit

  • Posted 6 July 2020, 12:55 am EST

    Should there be any difference between the solution from 5 July 8:42 PM EST and 2 July 11:36 PM EST?

    When the height is set to 1.8F I get a lot of white space at the bottom of the row. I would like to have it shrinked to the required height or the height must be set to the height of the RichTextBox.

    It seems that ActiveReports has problems with the images. In the attachment Examples.zip you get the original RTF file, the RTF file which was saved in WordPad and a print screen of WordPad as well as the output in ActiveReports.

  • Posted 9 July 2020, 1:54 am EST

    Hello,

    You can see in the following code that I changed the height of the RichTextBox using the If Else conditon

    if(s.Length>=1000)

    this.richTextBoxRtfText.Height = 1.8F;

    else

    this.richTextBoxRtfText.Height = 0.2F;

    You can change the condtion and height acoording to your application. I know it is workaround but can you please try at your end.

    the RTF file which was saved in WordPad and a print screen of WordPad as well as the output in ActiveReports.

    I am not able to reproduce the issue with the above workaround. could you please try at your end.

    Sorry for the inconvenience caused to you.

    Thanks,

    Mohit

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels