Navigation: TextEd > Extension and Scripts >

Printer object

 

 

 

 

Returns a global instance of TPrinter to manage interaction with the printer.
 

Use the methods in the Printer object to print some text of graphics.
 

 

Properties and methods



procedure Abort;

Terminates the printing of a print job, dropping all unprinted data.


procedure BeginDoc;

Call BeginDoc to initiate a print job. If the print job is sent successfully, the application calls EndDoc to end the print job. The print job won't actually start printing until EndDoc is called.

 

Ex.

Printer.BeginDoc;

  ...

Printer.EndDoc;


property TCanvas Canvas;

Represents the surface of the currently printing page. Canvas represents the printing surface of a page. Use the Brush, Font, and Pen properties of the Canvas object to determine how drawing or text appears on the page.

 

Ex.

Printer.BeginDoc;

Printer.Canvas.Font = memo.Font;

for (int i = 0; i < memo.Lines.Count - 1; i++) {

   Printer.Canvas.TextOut(0, line, memo.Lines[i]);

   line = line + (-Printer.Canvas.Font.Height);

   if (line >= Printer.PageHeight) {

     Printer.NewPage;

   }

}

Printer.EndDoc;
 

property int Copies;

Specifies the number of copies to print.
 

procedure EndDoc;

Ends the current print job and closes the text file variable.
 

procedure NewPage;

Starts a new page and increments the PageNumber property.
 

property int PageHeight;

Indicates the height (in pixels) of the currently printing page.
 

property int PageNumber;

Indicates the number of the page currently printing.
 

property int PageWidth;

Indicates the value of width (in pixels) of the currently printing page.
 


Usage



C++ example
 

TForm f;

TButton btnPrint;

TMemo memo;

 

/////////////////////////////////////

// Open a print dialog and print

// the memo text.

/////////////////////////////////////

void btnPrintClick(TObject Sender) {

   TPrintDialog printDlg = TPrintDialog.Create(f);

   if (printDlg.Execute) {

      int line = 0;

      Printer.BeginDoc;

      Printer.Canvas.Font = memo.Font;

      for (int i = 0; i < memo.Lines.Count - 1; i++) {

         Printer.Canvas.TextOut(0, line, memo.Lines[i]);

         line = line + (-Printer.Canvas.Font.Height);

         if (line >= Printer.PageHeight) {

           Printer.NewPage;

         }

      }

      Printer.EndDoc;

   }

   printDlg.Free;

}

 

// Main procedure

{

   // Create a new window (form)

   f = new TForm(nil);

   f.Caption = "Print memo text";

   f.Position = poScreenCenter;

   f.Width = 400;

   f.Height = 300;

  

   // Add a button to the window

   btnPrint = new TButton(f);

   btnPrint.Name = "btnPrint";

   btnPrint.Parent = f;

   btnPrint.SetBounds(10, 20, 75, 25);

   btnPrint.Anchors = akLeft+akTop;

   btnPrint.Caption = "Print...";

   btnPrint.OnClick = &btnPrintClick;

 

   // Add a text edit control (memo) to the window

   memo = new TMemo(f);

   memo.Name = "memoLorem";

   memo.Parent = f;

   memo.SetBounds(10, 50, 360, 200);

   memo.Anchors = akLeft+akTop;

   memo.Lines.Text = "Lorem Ipsum iaculis audire mi moderatius\r\ncorpora dictumst turpis."; 

  

   // Show the window

   f.ShowModal;

   f.Free;

}

 

 

 

 

 

 


 

 

 

 

Copyright © 2024 Rickard Johansson