Printer

Hi, all. How can I print bitmap, and text?

Cheers, Zeko
zekoAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
RBertoraConnect With a Mentor Commented:
Straight from the delphi help:

To print the contents of a memo component,

1.      Assign a text-file variable to the printer by calling AssignPrn.
2.      Create and open the output file by calling Rewrite.
      Any Write or Writeln statements sent to the file variable are then written on the Canvas of the printer object.

The AssignPrn procedure is declared in the Delphi Printers unit, so you must add Printers to the uses clause of the unit that calls AssignPrn.

When the printer is ready for input, you can write the contents (Lines property) of the memo to the printer.

Example

The following example prints the contents of a Memo field when the user chooses File|Print.

procedure TForm1.Print1Click(Sender: TObject);
var
  Line: Integer;
  PrintText: TextFile;   {declares a file variable}
begin
  if PrintDialog1.Execute then
  begin
    AssignPrn(PrintText);   {assigns PrintText to the printer}
    Rewrite(PrintText);     {creates and opens the output file}
    Printer.Canvas.Font := Memo1.Font;  {assigns Font settings to the canvas}
    for Line := 0 to Memo1.Lines.Count - 1 do

      Writeln(PrintText, Memo1.Lines[Line]);      {writes the contents of the Memo1 to the printer object}
    CloseFile(PrintText); {Closes the printer variable}
  end;
end;


Printing graphic images from a Delphi application is a simple task. The only requirement for printing is that you add the Printers unit to the uses clause of the form that will call the printer. The Printers unit declares a printer object called Printer that has a canvas that represents the printed page.

To print a graphic image,

Copy the image to the printer's canvas.


Example

The following code copies the image of a form to the printer in response to a click on a button named PrintButton:

procedure TForm1.PrintButtonClick(Sender: TObject);
begin
  with Printer do
  begin
    BeginDoc;      { start printing }
    Canvas.Draw(0, 0, Image);      { draw Image at top left corner of printed page }
    EndDoc;      { finish printing }
  end;
end;


You can use the printer's canvas just as you would any other canvas. In particular, that means you can copy the contents of a graphic object, such as a bitmap, to the printer directly.

Rob
0
 
zekoAuthor Commented:
Thanks
0
All Courses

From novice to tech pro — start learning today.