Huy Pham
Huy Pham

Reputation: 493

Printing in Firemonkey

TPrinter* prn = Printer::Printer();

TCanvas* Canvas = prn->Canvas;
String text = "Long live the king";

TFillTextFlags fTextFlag = TFillTextFlags();
prn->BeginDoc();
    TRectF rect{100, 100, 800, 800};
    Canvas->FillText(rect, text, false, 1, fTextFlag, TTextAlign::Leading, TTextAlign::Leading);
prn->EndDoc();

ShowMessage("Done Printing!");

The Text coming out is very tiny (as if no scaling was done with respect to DPI... like it was printing to a Screen, not a printer)... I tried the above (similar) codes in VCL, and it comes out fine...

Upvotes: 0

Views: 304

Answers (1)

user186876
user186876

Reputation: 301

The DocWiki help reminds that you need to set up the printing resolution (DPI) in your app. In the help it says:

Each printer has its own list of printing resolutions in DPI (dots per inch). The DPICount property gives you the number of resolutions that the printer supports. The DPI property is an indexed property that can be traversed to find out the actual resolutions. ActiveDPIIndex is a zero-based index for the DPI indexed property that represents the printing resolution on the printing device.

http://docwiki.embarcadero.com/RADStudio/Rio/en/Printing_from_a_FireMonkey_Application#About_DPI_and_Driver_Support

There is a C++Builder example in the help for printing an Image bitmap on a printer. It shows you how to set up the DPI and then to set the rectangle you want to print.

http://docwiki.embarcadero.com/CodeExamples/Rio/en/FMXPrinting_(C%2B%2B)

I tried this example using 10.4 Sydney to print out a bitmap of the Beatles Sgt Peppers Hearts Club Band album cover. When I set the rectangle size to the full printer page width and height, the album cover fit to the full page. When I set the rectangle size to 800 x 800 the album cover printed about an inch n the upper left of the page.

Printer->ActivePrinter->SelectDPI(1200, 1200);

// DestRect = TRectF(0, 0, Printer->PageWidth, Printer->PageHeight);
DestRect = TRectF(0, 0, 800, 800);

Check it out :D

Upvotes: 0

Related Questions