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 »

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: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

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

Post by Sergey Tkachenko »

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 »

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 »

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 »

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 »

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 »

or maybe srichview can change encoding after loading?
now a having
Интерпретация
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

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

Post 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?
elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

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

Post 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
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

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

Post by Sergey Tkachenko »

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 »

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 »

called like this

Code: Select all

  rv := TReportViewerForm.Create(Self);
  rv.LoadHTMLContent('<b>Русский текст</b>');
  rv.Show;
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

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

Post 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);
elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

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

Post 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?
elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

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

Post by elGringo »

also this variant

Code: Select all

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