Scale RTF to fit to one page

General TRichView support forum. Please post your questions here
Post Reply
Bulvaye
Posts: 10
Joined: Wed Oct 12, 2005 2:08 pm

Scale RTF to fit to one page

Post by Bulvaye »

Hello,

here I come with another question/problem:

I get any RTF file (which I can load via RichView or RichViewHelper). How can I scale this to fit to one page for my print out (via RVPrinter)?

Thank you for any hints. :wink:
Sergey Tkachenko
Site Admin
Posts: 17602
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

To fit vertically or horizontally?
Bulvaye
Posts: 10
Joined: Wed Oct 12, 2005 2:08 pm

Post by Bulvaye »

Vertically!

I have to scale the document as far as it fits to exactly one page, if the content of the rtf is larger than one page. If the content is smaller, fitting will not be nescessary.
Bulvaye
Posts: 10
Joined: Wed Oct 12, 2005 2:08 pm

Post by Bulvaye »

I think following is to do:

1) Determin the screen device size (for preview) and printer device size (selected printer and paper size for printing)

2) Determin the "virtual" page height, the page should have to render the whole RichView content into only ONE page

3) Scale the large page proportional to
3a) a screen device for print preview and
3b) to the selected printing device's paper size for printing

Can you give me some hints, how to implement this? Or is there any easier/quicker way?
Sergey Tkachenko
Site Admin
Posts: 17602
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

You cannot print a scaled document using TRVPrint. Use TRVReportHelper instead.

First, format RVReportHelper (Init + FormatNextPage).
Let PageWidth is a width specified in Init, PageHeight := RVReportHelper.GetLastPageHeight (I assume that the document has only one page).
Let DestRect is a rectangle where you can print.

(i.e., the document originally has the size PageWidth x PageHeight. You print it scaled inside DestRect)

Code: Select all

SetMapMode(Canvas.Handle,MM_ANISOTROPIC);
SetWindowExtEx(Canvas.Handle, PageWidth, PageHeight, nil);
with DestRect do begin
  SetViewportExtEx(Canvas.Handle, Right-Left, Bottom-Top,nil);
  SetViewportOrgEx(Canvas.Handle,Left,Top,nil);
end;
rv.DrawPage(1, Canvas, False, False, PageHeight);
SetMapMode(Canvas.Handle,MM_TEXT);
SetViewportOrgEx(Canvas.Handle,0,0,nil);
In this code, Canvas is a Printer.Canvas. Do not forget to call Printer.BeginDoc and EndDoc.

See the demo Demos\Delphi\Assorted\Printing\ReportHelper\ for additional information about printing with TRVReportHelper.
HighTower
Posts: 11
Joined: Wed Oct 12, 2005 8:46 am
Location: Putins-Burg

Post by HighTower »

Sergey Tkachenko wrote:I assume that the document has only one page
and how about scaled printing of several pages?

(originally, for example, 2.5 pages scale to 2 pages)
Sergey Tkachenko
Site Admin
Posts: 17602
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Scale by which ratio?
HighTower
Posts: 11
Joined: Wed Oct 12, 2005 8:46 am
Location: Putins-Burg

Post by HighTower »

scale by user defined ratio.

if you know product "1C" - it has scale printing - very usefull feature and I (we) wonna smth like this.
Sergey Tkachenko
Site Admin
Posts: 17602
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Well, you need
1) Repaginate RVReportHelper taking the scaling ratio into account (for example, if you want to shrink the image by half in dimensions, multiply the page wifsh and height by 2 when calling Init and FormatNextPage)
2) Use the code from this topic for scaled printing.
Post Reply