Page breaks in HTML

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

Page breaks in HTML

Post by elGringo » Sat Nov 25, 2017 9:59 am

Hello, Sergey!
Saving 2 pages to html, having following code below

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
body {
  margin: 94px 57px 94px 132px;
  background-color: #ffffff;
}
/* ========== Text Styles ========== */
hr { color: #000000}
body, table, span.rvts0 /* Normal text */
{
 font-size: 10pt;
 font-family: 'Arial', 'Helvetica', sans-serif;
 font-style: normal;
 font-weight: normal;
 color: #000000;
 text-decoration: none;
}
span.rvts1 /* Heading */
{
 font-weight: bold;
 color: #0000ff;
}
span.rvts2 /* Subheading */
{
 font-weight: bold;
 color: #000080;
}
span.rvts3 /* Keywords */
{
 font-style: italic;
 color: #800000;
}
a.rvts4, span.rvts4 /* Jump 1 */
{
 color: #008000;
 text-decoration: underline;
}
a.rvts5, span.rvts5 /* Jump 2 */
{
 color: #008000;
 text-decoration: underline;
}
span.rvts6
{
 color: #000000;
}
span.rvts7
{
 font-size: 22pt;
 font-family: 'calibri';
 color: #000000;
}
span.rvts8
{
 font-size: 14pt;
 color: #000000;
}
span.rvts9
{
 font-size: 14pt;
 color: #969696;
}
span.rvts10
{
 color: #808080;
}
span.rvts11
{
 font-size: 16pt;
 color: #333333;
}
span.rvts12
{
 color: #333333;
}
/* ========== Para Styles ========== */
p,ul,ol /* Paragraph Style */
{
 text-align: left;
 text-indent: 0px;
 padding: 0px 0px 0px 0px;
 margin: 0px 0px 0px 0px;
}
.rvps1 /* Centered */
{
 text-align: center;
}
--></style>
</head>
<body>
<p><span class=rvts6><br></span></p>
<p class=rvps1><span class=rvts6><br></span></p>
<p class=rvps1><span class=rvts6><br></span></p>
<p class=rvps1><span class=rvts6><br></span></p>
<p class=rvps1><span class=rvts6><br></span></p>
<p class=rvps1><span class=rvts6><br></span></p>
<p class=rvps1><span class=rvts6><br></span></p>
<p class=rvps1><span class=rvts6><br></span></p>
<p class=rvps1><span class=rvts6><br></span></p>
<p class=rvps1><span class=rvts6><br></span></p>
<p class=rvps1><span class=rvts6><br></span></p>
<p class=rvps1><span class=rvts6><br></span></p>
<p class=rvps1><span class=rvts6><br></span></p>
<p class=rvps1><span class=rvts6><br></span></p>
<p class=rvps1><span class=rvts6><br></span></p>
<p class=rvps1><span class=rvts7>Отчет по элементу события пользователя</span></p>
<p class=rvps1><span class=rvts8><br></span></p>
<p class=rvps1><span class=rvts11>{{0}}</span></p>
<p class=rvps1><span class=rvts9><br></span></p>
<p class=rvps1><span class=rvts11>{{1}}</span></p>
<p class=rvps1><span class=rvts6><br></span></p>
<p class=rvps1><span class=rvts12>{{2}}</span></p>
<p class=rvps1 style="page-break-before: always;"><span class=rvts12>123</span></p>
<p class=rvps1><span class=rvts10><br></span></p>
<p class=rvps1><span class=rvts6><br></span></p>
</body></html>
it has link to css style style="page-break-before: always;" but no style in code...
so when loading back to srichview - all content on one page - could you advice something?

save html

Code: Select all

procedure TReportTemplatesConstructor.SaveHTMLContent();
begin
  with qSelectReportTemplate do
  begin
    try
      connection := MainModule.FDConnection;
      CachedUpdates := true;
      Params.ParamValues['id'] := FReportTemplateID;
      Disconnect();
      Open();
      trWrite.Connection := MainModule.FDConnection;
      trWrite.StartTransaction();
      Edit();

      FieldByName('htmlContentHeader').AsString := getHtmlFromRVE(SRichViewEdit.RVHeader);
      FieldByName('htmlContentBody').AsString := getHtmlFromRVE(SRichViewEdit.RichViewEdit);
      FieldByName('htmlContentFooter').AsString := getHtmlFromRVE(SRichViewEdit.RVFooter);

      if ApplyUpdates <> 0 then
        raise Exception.Create(RowError.Message);
      trWrite.Commit();
      //Close();
    except
      on E: Exception do
        raise Exception.Create('Error Message ' + E.Message);
    end;
  end;
end;
load html

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;
 // normalizing table borders
  for i := 0 to SRichViewEdit.ActiveEditor.ItemCount - 1 do
  begin
    if ((SRichViewEdit.ActiveEditor.GetItem(i).StyleNo = -60)) then
    begin
      SRichViewEdit.ActiveEditor.SetItemTag(i, i.ToString());
      FTableListSL.Add(i.ToString());
      NormalizeTableBorders(i);
    end;
  end;
end;
Questions
1) how to split correctly on pages when save load from html?
2) how to save header and footer of each page and then load it? For the moment i just doing sometging like this

Code: Select all

FieldByName('htmlContentHeader').AsString := getHtmlFromRVE(SRichViewEdit.RVHeader);
but not sure it is correct

Thanks in advance!

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

Re: Page breaks in HTML

Post by Sergey Tkachenko » Sat Nov 25, 2017 11:34 am

TRvHtmlViewImporter does not read page break properties from HTML.
I checked, it looks like THTMLViewer supports them, so import is possible. I'll try to implement it in one of future updates.

I do not understand your question about headers and footers. Do you save them as separate HTML documents?

In older version of ScaleRichView, a header and a footer were really always stored in RVHeader and RVFooter.
In the new version, SRV.RVHeader/RVFooter contains header/footer only if a header/footer is being edited. Otherwise, they are in SRV.SubDocuments.
It is possible to use SubDocuments[].SaveHTMLToStreamEx, however, there are some complication, so I can suggest this code:

Code: Select all

      SRichViewEdit.CanUpdate := False;
      SRichViewEdit.StartEditing(srvrveHeader);
      FieldByName('htmlContentHeader').AsString := getHtmlFromRVE(SRichViewEdit.RVHeader);
      SRichViewEdit.StartEditing(srvrveFooter);
      FieldByName('htmlContentFooter').AsString := getHtmlFromRVE(SRichViewEdit.RVFooter);
      SRichViewEdit.StartEditing(srvrveMain);
      FieldByName('htmlContentBody').AsString := getHtmlFromRVE(SRichViewEdit.RichViewEdit);
      SRichViewEdit.CanUpdate := True;

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

Re: Page breaks in HTML

Post by elGringo » Sat Nov 25, 2017 2:43 pm

thank you, but how can i use THTMLViewer to import HTML to sRichView? Could you give a small piece of code?
Regards, Stanislav

I just need to show report created in SrichViewEdit with pages...

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

Re: Page breaks in HTML

Post by Sergey Tkachenko » Sat Nov 25, 2017 7:36 pm

If you use RichViewActions, you can use TRvHtmlViewImporter without writing any code (some code is needed only to download external CSS files, it is described in this topic: http://www.trichview.com/forums/viewtop ... f=5&t=8784 , but it is available only for registered users).

Without RichViewActions:

Code: Select all

  if OpenDialog1.Execute then 
  begin
    HTMLViewer1.LoadFromFile(OpenDialog1.FileName);
    RVHTMLViewImporter1.ImportHtmlViewer(HTMLViewer1, SRichViewEdit1.RichViewEdit,
      ExtractFilePath(OpenDialog1.FileName));
    SRichViewEdit1.RichViewEdit.RVData.NormalizeDocument(0, True);
    SRichViewEdit1.Format;
  end;
If you want to download remote images, you need to process SRichViewEdit1.OnImportPicture. RichViewActions do it automatically, if RVAControlPanel.DownloadInterface is assigned.

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

Re: Page breaks in HTML

Post by elGringo » Sat Nov 25, 2017 8:50 pm

Sergey, thank you! I will try !

Post Reply