Doc Thumbnail

General TRichView support forum. Please post your questions here
Post Reply
standay
Posts: 272
Joined: Fri Jun 18, 2021 3:07 pm

Doc Thumbnail

Post by standay »

Hi Sergey,

Is there a "built-in" or simple way to generate a small thumbnail image of a given rvf file? I've searched and so far have not discovered anything for this. I'd like to be able to generate a small thumbnail that I could insert into the rve I'm using.

Thanks Sergey

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

Re: Doc Thumbnail

Post by Sergey Tkachenko »

Sorry for the delay.

You can use TRVReportHelper to draw a document into bitmap of the specified size.

Like this:

Code: Select all

function MakeBitmap(const FileName: String; Width, Height: Integer): TBitmap;
var rvh: TRVReportHelper;
    Stream: TFileStream;
    bmp : TBitmap;
begin
  Result := nil;
  bmp := nil;
  try
    bmp := TBitmap.Create;
    bmp.Width := Width;
    bmp.Height := Height;
    rvh := TRVReportHelper.Create(nil);
    try
      rvh.RichView.Style := TRVStyle.Create(rvh);
      rvh.RichView.RVFTextStylesReadMode := rvf_sInsertMerge;
      rvh.RichView.RVFParaStylesReadMode := rvf_sInsertMerge;
      rvh.RichView.RVFOptions := rvh.RichView.RVFOptions + [rvfoIgnoreUnknownPicFmt,
        rvfoIgnoreUnknownCtrls, rvfoConvUnknownStylesToZero,
        rvfoConvLargeImageIdxToZero, rvfoLoadBack, rvfoLoadLayout];
      Stream := TFileStream.Create(FileName, fmOpenRead);
      try
        rvh.RichView.LoadRVFFromStream(Stream)
      finally
        Stream.Free;
      end;
      rvh.Init(bmp.Canvas, Width);
      rvh.FormatNextPage(Height);
      if rvh.Finished and (rvh.GetLastPageHeight<Height) then 
      begin
        // remove this code if you need a bitmap exactly Width x Height
        Height := rvh.GetLastPageHeight;
        bmp.Height := Height;
      end;
      rvh.DrawPage(1, bmp.Canvas, True, Height);
    finally
      rvh.Free;
    end;
    Result := bmp;
  except
    bmp.Free;
  end;
end;
Probably, it makes sense to create this bitmap larger than the thumbnail size, and stretch-draw it to thumbnail.
You can use RVThumbnailMaker object from RVThumbMaker unit.

Code: Select all

function MakeThumbnail(const FileName: String; Width, Height: Integer): TBitmap;
var
  bmp: TBitmap;
const
  Ratio = 3;
begin
  Result := nil;
  bmp := MakeBitmap('c:\Docs\test.rvf', Width * Ratio, Height * Ratio);
  if bmp = nil then
    exit;
  Result := RVThumbnailMaker.MakeThumbnail(bmp, bmp.Width div Ratio, bmp.Height div Ratio);
  bmp.Free;
end;
standay
Posts: 272
Joined: Fri Jun 18, 2021 3:07 pm

Re: Doc Thumbnail

Post by standay »

Thanks Sergey, I'll give this a try. No problem on the delay, not an urgent thing.

Stan
standay
Posts: 272
Joined: Fri Jun 18, 2021 3:07 pm

Re: Doc Thumbnail

Post by standay »

Sergey,

I finally had a chance to implement this and it works. I use some rvf files as "covers" (i.e., a little text with a big central image) in my app. Creating thumbnails of the files in my covers folder lets me select files visually in the open dialog which is much better than just seeing filenames.

Any chance of a system DLL that would let Windows explorer show previews of rvf files in all explorer windows?

Thanks again Sergey!

Stan
Post Reply