Scale in TRichView (Pictures in Tables)
Scale in TRichView (Pictures in Tables)
I read HTML emails into TRiChView. That works so far. Now I want to archive the emails as an extension and have thought about saving them in PDF format and printing them out. The problem is that sometimes there are very large images in the emails that we want to reduce in size. This is a problem for us in tables, because the tables can have several sub-tables, which then determine the final width, depending on the total number of columns in the document. If it is a empty column or a cell, this would also have to be taken into account. Is there a workflow, algorithm or demo for this?
-
- Site Admin
- Posts: 17724
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Scale in TRichView (Pictures in Tables)
What do you want to do exactly?
Do I understand correctly:
You define some width value W.
If the image is inside the root table, its width must not exceed (W / table.ColCount)?
If it is in the nested table, its width must not exceed W / (roottable.ColCount * nestedtable.ColCount)?
Do I understand correctly:
You define some width value W.
If the image is inside the root table, its width must not exceed (W / table.ColCount)?
If it is in the nested table, its width must not exceed W / (roottable.ColCount * nestedtable.ColCount)?
Re: Scale in TRichView (Pictures in Tables)
The point is, I want to automatically edit the content of the TRichView so that the width of the TRichView is no larger than, for example, 700 px. For example, if I reduce the images to 300 px - and there is still text next to them, TrichView does not use the width any further, but instead reduces the TRichView to a value of less than 700 - perhaps bestwidth is the right keyword. I tried that, but didn't really get anywhere. I will send another email with example files in rvf
-
- Site Admin
- Posts: 17724
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Scale in TRichView (Pictures in Tables)
Sorry, TRichView does not know the final width of document on the step of document creation. It can be calculated only after formatting.
And, for complex tables, it's hard to predict how the image width will affect the table width.
It is possible to do the following.
Format the document, then check TRichView.RVData.DocumentWidth. If it exceeds the limit, reduce the image(s) size by some percent, reformat and check TRichView.RVData.DocumentWidth again. If it still exceeds the limit, but it is smaller than the document width at the previous step, repeat.
Do it until you get the desired width or until the document width stops decreasing.
And, for complex tables, it's hard to predict how the image width will affect the table width.
It is possible to do the following.
Format the document, then check TRichView.RVData.DocumentWidth. If it exceeds the limit, reduce the image(s) size by some percent, reformat and check TRichView.RVData.DocumentWidth again. If it still exceeds the limit, but it is smaller than the document width at the previous step, repeat.
Do it until you get the desired width or until the document width stops decreasing.
Re: Scale in TRichView (The Right Way to Reduce)
Thank you,
I'm trying to implement this and search the document recursively through the many tables. It's not clear to me how exactly I reduce the size of the images (percentage-wise in height and width).
"GetExtraIntProperty(rvepImageWidth,Extra_Width);"GetExtra..." always returns the value 0 for the current width.
and Image.Width reduces the size of the image by cropping it. And I have the impression that the image is reduced in size, but the space in the TrichView is not reduced, I'm not sure about that. What is the efficient way to reduce the size of the images in tables?
aitem.GetExtraIntProperty(rvepImageWidth,Extra_Width) is allways 0, too
I'm trying to implement this and search the document recursively through the many tables. It's not clear to me how exactly I reduce the size of the images (percentage-wise in height and width).
"GetExtraIntProperty(rvepImageWidth,Extra_Width);"GetExtra..." always returns the value 0 for the current width.
and Image.Width reduces the size of the image by cropping it. And I have the impression that the image is reduced in size, but the space in the TrichView is not reduced, I'm not sure about that. What is the efficient way to reduce the size of the images in tables?
aitem.GetExtraIntProperty(rvepImageWidth,Extra_Width) is allways 0, too
Code: Select all
procedure TFTestRichView.CollectImagesFromTable(aTable: TRVTableItemInfo);
var
aCell: TRVTableCellData;
aItem: TCustomRVItemInfo;
z: integer;
aItemType: integer;
anewTable: TRVTableItemInfo;
aRow: Integer;
aCol: integer;
aGraphicItem : TRVGraphicItemInfo;
extra_width: integer;
begin
for arow := 0 to aTable.Rows.Count - 1 do
begin
for acol := 0 to aTable.Rows[arow].Count - 1 do
begin
aCell := aTable.Cells[arow,acol];
for z := 0 to aCell.ItemCount - 1 do
begin
aitem := aCell.GetItem(z);
aitemtype := aitem.StyleNo;
if (aitemType = rvsPicture) or (aitemtype = rvsHotPicture) then
begin
aitem.GetExtraIntProperty(rvepImageWidth,Extra_Width);
showmessage('Item-ExtraIntProp-Width: ' + inttostr(Extra_Width));
//is always 0
if aItem is TRVGraphicItemInfo then
begin
aGraphicItem := TRVGraphicItemInfo(aitem);
aGraphicitem.GetExtraIntProperty(rvepImageWidth,Extra_Width);
// ----> Extra_Width is allways 0
end;
end;
if aitemtype = rvsTable then
begin
aNewTable := TRVTableItemInfo(aitem);
CollectImagesFromTable(aNewTable,arv_itemindex);
end;
end;
end;
end;
end;
Code: Select all
procedure TFTestRichView.ScaleImage2(aGraphicItem: TRVGraphicItemInfo;
aScale_Art: integer);
var
aold_width:integer;
aold_height: integer;
anew_width: integer;
anew_height: integer;
ascale_factor: double;
begin
//agraphicItem.GetItemExtraIntProperty(rvepImageWidth,aold_width);
//agraphicItem.GetExtraIntProperty(rvepImageHeight,aold_Height);
//is Allways 0
aold_width := agraphicItem.Image.Width;
aold_height := agraphicItem.Image.Height;
ascale_factor := 0.8; //For Example
if ascale_Factor > 0 then
begin
anew_width := round(aold_width * ascale_factor);
anew_height := round(aold_height * ascale_factor);
agraphicItem.Image.Width := anew_width;
agraphicItem.Image.Height := anew_height;
end;
end;