loading html to non-empty rve - possible?

General TRichView support forum. Please post your questions here
elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

loading html to non-empty rve - possible?

Post by elGringo » Wed Nov 29, 2017 1:30 pm

good time, Sergey!
-dynamically composing my docs from different sources to rveMain
1-st loading from blob field
2-d loading html from other field and going to paste in to doc - for this going to create new rveAdditional- load html like this...

Code: Select all

   
   ...
   RVAControlPanel.InitImportPictures(nil, nil);
          rve.OnImportPicture := RVAControlPanel.DoImportPicture;
          RVHTMLViewImporter.LoadFromFile(randomFilePath, rve);

          RVAControlPanel.DoneImportPictures;
          rve.OnImportPicture := nil;
                          //RvHtmlImporter.LoadHtml(randomFilePath);
          rve.FormatAll;
          ..
          
then going to select all and paste in rveMain

but this workaround seems to me not simple - is there any way to import some html content in document which is not empty to position of caret or next page?

Thanks in advance!

Sergey Tkachenko
Site Admin
Posts: 14212
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: loading html to non-empty rve - possible?

Post by Sergey Tkachenko » Wed Nov 29, 2017 2:40 pm

Call
HTMLViewer1.LoadFromFile
then
RVHtmlViewImporter1.AppendHtmlViewer
It adds HTML content to the end of TRichView.

elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

Re: loading html to non-empty rve - possible?

Post by elGringo » Wed Nov 29, 2017 3:05 pm

Thank you very much!

elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

Re: loading html to non-empty rve - possible?

Post by elGringo » Wed Nov 29, 2017 3:27 pm

final working decision is

(concerning to this http://www.trichview.com/forums/viewtopic.php?t=7138)

Code: Select all

    SRichViewEditTemp := TSRichViewEdit.Create(Self);
    try
    //copy content to another rve
      RVHTMLViewImporter.LoadFromFile(randomFilePath, SRichViewEditTemp.ActiveEditor);
      RVHTMLViewImporter.LoadFromClipboard(SRichViewEditTemp.ActiveEditor, HtmlViewer);
      RVHTMLViewImporter.AppendHtmlViewer(HtmlViewer, SRichViewEdit.ActiveEditor);
    //load back
    finally
      SRichViewEditTemp.Free();
    end;

elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

Re: loading html to non-empty rve - possible?

Post by elGringo » Thu Nov 30, 2017 9:03 am

Now problem with russian text encoding (((
Somewhere in this chain i should point that i use utf-8 but where?

Regards,

elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

Re: loading html to non-empty rve - possible?

Post by elGringo » Thu Nov 30, 2017 9:07 am

my full code to append html is

Code: Select all

procedure TReportViewerForm.AppendHTMLContent(AHtml: string);
var
  tempDir: string;
  randomFilePath: string;
  clientTempDir: string;
  i: Integer;
  SRichViewEditTemp: TSRichViewEdit;
begin
  try
    tempDir := ExtractFilePath(Application.ExeName) + 'files\temp';
    TDirectory.CreateDirectory(tempDir);
    randomFilePath := tempDir + '\' + inttostr(Random(1000000)) + '.html';
    TFile.AppendAllText(randomFilePath, AHtml, TEncoding.UTF8);
    RVAControlPanel.InitImportPictures(nil, nil);
    SRichViewEdit.ActiveEditor.OnImportPicture := RVAControlPanel.DoImportPicture;

    // appending content
    SRichViewEditTemp := TSRichViewEdit.Create(Self);
    SRichViewEditTemp.ActiveEditor.OnImportPicture := RVAControlPanel.DoImportPicture;
    try
    //copy content to another rve
      RVHTMLViewImporter.LoadFromFile(randomFilePath, SRichViewEditTemp.ActiveEditor);
      RVHTMLViewImporter.LoadFromClipboard(SRichViewEditTemp.ActiveEditor, HtmlViewer);
      RVHTMLViewImporter.AppendHtmlViewer(HtmlViewer, SRichViewEdit.ActiveEditor);
    //load back
    finally
      SRichViewEditTemp.Free();
    end;

    RVAControlPanel.DoneImportPictures;
    SRichViewEdit.ActiveEditor.OnImportPicture := nil;
    SRichViewEdit.ActiveEditor.FormatAll();
  finally
    if TFile.Exists(randomFilePath) then
      TFile.Delete(randomFilePath);
  end;
  end;
end;

elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

Re: loading html to non-empty rve - possible?

Post by elGringo » Thu Nov 30, 2017 9:24 am

or maybe srichview can change encoding after loading?
now a having
Интерпретация

Sergey Tkachenko
Site Admin
Posts: 14212
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: loading html to non-empty rve - possible?

Post by Sergey Tkachenko » Thu Nov 30, 2017 9:37 am

Make HTMLViewer and SRichViewEdit visible. Is the text corrupted in HtmlViewer? If the text corrupted in SRichViewEdit?
And I do not understand, why do you call LoadFromClipboard?

elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

Re: loading html to non-empty rve - possible?

Post by elGringo » Thu Nov 30, 2017 9:41 am

clipboard 'cause if not - it erases all content before
the same as in this topic
http://www.trichview.com/forums/viewtopic.php?t=7138

ok, i will make them visible and test

Sergey Tkachenko
Site Admin
Posts: 14212
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: loading html to non-empty rve - possible?

Post by Sergey Tkachenko » Thu Nov 30, 2017 9:42 am

LoadFromFile always erases all content before loading.
AppendHtmlViewer never erases.

elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

Re: loading html to non-empty rve - possible?

Post by elGringo » Thu Nov 30, 2017 9:52 am

result
https://yadi.sk/i/OKUzGmEO3QBiUT

in both cases
Русский текст



i just loaded...

Code: Select all

procedure TReportViewerForm.LoadHTMLContent(AHtml: string);
var
  tempDir: string;
  randomFilePath: string;
  clientTempDir: string;
  i: Integer;
begin
  try
    tempDir := ExtractFilePath(Application.ExeName) + 'files\temp';
    TDirectory.CreateDirectory(tempDir);
    randomFilePath := tempDir + '\' + inttostr(Random(1000000)) + '.html';
    TFile.AppendAllText(randomFilePath, AHtml, TEncoding.UTF8);
    RVAControlPanel.InitImportPictures(nil, nil);
    SRichViewEdit.ActiveEditor.OnImportPicture := RVAControlPanel.DoImportPicture;
    RVHTMLViewImporter.LoadFromFile(randomFilePath, SRichViewEdit.ActiveEditor); // <<<
    RVAControlPanel.DoneImportPictures;
    SRichViewEdit.ActiveEditor.OnImportPicture := nil;
    SRichViewEdit.ActiveEditor.FormatAll();
  finally
    if TFile.Exists(randomFilePath) then
      TFile.Delete(randomFilePath);
  end;
  end;
end;

elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

Re: loading html to non-empty rve - possible?

Post by elGringo » Thu Nov 30, 2017 9:55 am

called like this

Code: Select all

  rv := TReportViewerForm.Create(Self);
  rv.LoadHTMLContent('<b>Русский текст</b>');
  rv.Show;

Sergey Tkachenko
Site Admin
Posts: 14212
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: loading html to non-empty rve - possible?

Post by Sergey Tkachenko » Thu Nov 30, 2017 10:22 am

As you can see, the garbage is already in THTMLViewer. It does not detected that your HTML has UTF-8 encoding.

Possible solutions
1) Specify UTF-8 encoding in HTML:

Code: Select all

  LoadHTMLContent(
    '<head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"></head>'+
    '<b>Привет</b>');
2) Adding UTF-8 byte order mark in the beginning of the file (I did not try it, though)

3) Use TEncoding.Unicode instead of TEncoding.UTF8:

Code: Select all

TFile.AppendAllText(randomFilePath, AHtml, TEncoding.Unicode);
Actually, you can implement this function without using files:

Code: Select all

    HtmlViewer1.LoadFromString(AHtml);
    RVHTMLViewImporter1.AppendHtmlViewer(HtmlViewer1, SRichViewEdit1.ActiveEditor);

elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

Re: loading html to non-empty rve - possible?

Post by elGringo » Thu Nov 30, 2017 10:33 am

You are just brilliant !
used 3) and it worked an then used last advice of 2 strings without files and it also worked

but as for 3) not clear to me why when we change to TEncoding.Unicode it begins work? Because of initial text in UniCode?

elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

Re: loading html to non-empty rve - possible?

Post by elGringo » Thu Nov 30, 2017 10:35 am

also this variant

Code: Select all

HtmlViewer1.LoadFromString(AHtml);
    RVHTMLViewImporter1.AppendHtmlViewer(HtmlViewer1, SRichViewEdit1.ActiveEditor);
won't load pics as i understand?

Post Reply