Print a defined rtf

General TRichView support forum. Please post your questions here
Post Reply
pjensen
Posts: 2
Joined: Thu Aug 16, 2007 2:07 pm
Location: Flensburg / Germany

Print a defined rtf

Post by pjensen »

Hi,

at first: sorry for my bad english.

I'm a trichview nebie. It seems not too be too simple to work with trichview, espezially if one has not too much experience with object-orientated programming.

A very-beginner-question: How to print a given file.

I have the file /home/peter/test.rtf. I just want to print this file to the printer named "HP-Weiss". Therefore i have the Button "Print". I'm missing a beginner-code in the examples for this or did i overlook it?

I have a Form1 with a Button1:TButton and the RVPrint1:TRVPrint. Now i need the code to print the file.

// print the file /home/peter/test.rtf
procedure TForm1.Button1Click(Sender: TObject);
begin

????????

end;

Please fill in...
Maybe it would help others to get fast succes with trichview.

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

Post by Sergey Tkachenko »

Place on form:
RichView1: TRichView,
RVStyle1: TRVStyle;
RVPrint1: TRVPrint.
Assign (at designtime) RichView1.Style := RVStyle1.

Loading RTF file:

Code: Select all

RichView1.Clear;
RichView1.LoadRTF('/home/peter/test.rtf');
RichView1.Format;
Next, you need to choose printer.
RVPrint uses the application printer settings, so, by default, it prints on the system default printer.
You can use TPrintDialog or TPrinterSetupDialog to allow user to choose printer.
If you want to do it in code:

Code: Select all

uses Printers;
...
var PrinterIndex: Integer;
begin
  PrinterIndex := Printer.Printers.IndexOf('HP-Weiss');
  if PrinterIndex>=0 then
    Printer.PrinterIndex := PrinterIndex;
end;
Printing:

Code: Select all

RVPrint1.AssignSource(RichView1);
RVPrint1.FormatPages(rvdoAll);
RVPrint1.Print('Test', 1, False);
pjensen
Posts: 2
Joined: Thu Aug 16, 2007 2:07 pm
Location: Flensburg / Germany

Post by pjensen »

Hello Sergey,

thanks for the fast answer.

But something goes wrong:
1) RichView1.LoadRTF => no memeber LoadRTF
2) RVPrint1.FormatPages => no identifier rvdoAll

What i did:
In the objektinspektor on RichView1 i choosed RVStyle1 for Style.
Then i made the code as seen below.

But i get the both errors which you can see in the code.
This example leastwise prints a blank page. The second error i found when comented out the first error-line.

But where do the errors come from ?

I don't think that i failed to install RichView in my lazarus because it prints a blank page. I tookm lazrichview-0.5.2.2.tar.gz from sourgeforge.

---------

procedure TForm1.Button1Click(Sender: TObject);

var PrinterIndex: Integer;

begin
RichView1.Clear;
// RichView1.LoadRTF('/home/peter/test.rtf'); //Error: identifier idents no member "LoadRTF"
RichView1.Format;
PrinterIndex := Printer.Printers.IndexOf('HP-Weiss');
if PrinterIndex>=0 then Printer.PrinterIndex := PrinterIndex;
RVPrint1.AssignSource(RichView1);
// RVPrint1.FormatPages(rvdoAll); // Identifier not found "rvdoAll"
RVPrint1.Print('Test', 1, False);
end;
Sergey Tkachenko
Site Admin
Posts: 17310
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

You use Lazarus version of TRichView. This is a port of the old freeware version of TRichView. It cannot load RTF.
As for printing, [rvdoImages, rvdoComponents, rvdoBullets] must be used instead of rvdoAll.
Post Reply