Page 1 of 2

loading html to non-empty rve - possible?

Posted: Wed Nov 29, 2017 1:30 pm
by elGringo
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!

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

Posted: Wed Nov 29, 2017 2:40 pm
by Sergey Tkachenko
Call
HTMLViewer1.LoadFromFile
then
RVHtmlViewImporter1.AppendHtmlViewer
It adds HTML content to the end of TRichView.

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

Posted: Wed Nov 29, 2017 3:05 pm
by elGringo
Thank you very much!

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

Posted: Wed Nov 29, 2017 3:27 pm
by elGringo
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;

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

Posted: Thu Nov 30, 2017 9:03 am
by elGringo
Now problem with russian text encoding (((
Somewhere in this chain i should point that i use utf-8 but where?

Regards,

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

Posted: Thu Nov 30, 2017 9:07 am
by elGringo
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;

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

Posted: Thu Nov 30, 2017 9:24 am
by elGringo
or maybe srichview can change encoding after loading?
now a having
Интерпретация

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

Posted: Thu Nov 30, 2017 9:37 am
by Sergey Tkachenko
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?

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

Posted: Thu Nov 30, 2017 9:41 am
by elGringo
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

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

Posted: Thu Nov 30, 2017 9:42 am
by Sergey Tkachenko
LoadFromFile always erases all content before loading.
AppendHtmlViewer never erases.

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

Posted: Thu Nov 30, 2017 9:52 am
by elGringo
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;

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

Posted: Thu Nov 30, 2017 9:55 am
by elGringo
called like this

Code: Select all

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

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

Posted: Thu Nov 30, 2017 10:22 am
by Sergey Tkachenko
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);

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

Posted: Thu Nov 30, 2017 10:33 am
by elGringo
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?

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

Posted: Thu Nov 30, 2017 10:35 am
by elGringo
also this variant

Code: Select all

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