Skip to content

TTMSFNCPrinter

To get started with the lowest level of implementation for the print library, add the FMX.TMSFNCPrinters, VCL.TMSFNCPrinters, LCLTMSFNCPrinters or WEBLib.TMSFNCPrinters unit depending on the chosen framework. The code is shareable between the four supported frameworks.

This allows you to print files similar to the basic printer class of the framework.

Instead of Printer you will need to use the instance of TMSFNCPrinter, it is important to place all your drawing in the callback event OnDrawContent and end this procedure with an EndDoc to close the printing!

This way of working is necessary because the printing works asynchronous in Android. After starting a new document with BeginDoc, the code is not executed sequential, but once ready it will trigger the OnDrawContent callback.

Important for Android implementation

It is necessary to add the FNCPrintDocumentAdapter.jar or the combined FNC JAR file to your project libraries! This file can be found in the Android Support folder in your installation directory.

Methods

Method name Description
BeginDoc Start the request for a new document to print.
EndDoc Ends the creation of a new document and will start the printing.
New Page Add a new page to the document.

Callback Event

Event name Description
OnDrawContent TTMSFNCPrinterDrawContentCallBack procedure without any parameters. Whitin this event it is expected to define your drawing calls for the document. (Is mandatory in Android.)

Properties

Property name Description
Device Returns the active printer’s name as a string. (Is not used in TMS WEB Core, Android, and iOS.)
DPI Returns the selected dpi of the active printer as an integer. (Is settable in TMS WEB Core and Android.)
Graphics The TTMSFNCGraphics property can be used to draw on the printer canvas.
Orientation Can be used to set the TPrinterOrientation of the paper to poPortrait or poLandscape.
PageHeight Returns the height of the document in pixels as an integer. (Is settable in TMS WEB Core.)
PageNumber Returns the index as an integer of the current page that you are working on
PageWidth Returns the width of the document in pixels as an integer. (Is settable in TMS WEB Core.)

Platform Specific Properties

Property name Description
PrintCompleted Boolean that can be used in iOS, that indicates if the print is completed.
PrintJobName String used to define the printjob in Android.
PrintSize TPrintSize property to select the paper size in Android.

Example

uses
  , FMX.TMSFNCPrinters, FMX.TMSFNCGraphicsTypes;
procedure Click(Sender: TObject);
begin
  TMSFNCPrinter.OnDrawContent :=
  procedure
  begin
    TMSFNCPrinter.Graphics.Font.Color := gcBlue;
    TMSFNCPrinter.Graphics.Font.Size := 40;
    TMSFNCPrinter.Graphics.DrawText(0, 20, TMSFNCPrinter.PageWidth, 100, 'Hello', False, 
      gtaCenter, gtaCenter);
    TMSFNCPrinter.Graphics.Fill.Color := gcRed;
    TMSFNCPrinter.Graphics.DrawEllipse(100,200, TMSFNCPrinter.PageWidth - 100, 300);
    TMSFNCPrinter.Graphics.DrawBitmap(50,400, TMSFNCPrinter.PageWidth - 50, 
    TMSFNCPrinter.PageHeight - 50, Image1.Bitmap, True, True);
    TMSFNCPrinter.EndDoc;
  end;
  TMSFNCPrinter.BeginDoc;
end;

TTMSFNCPrinters