0
votes

I am using RAD Studio XE6 and I have a simple fire monkey form that I use to print an image. I thought it would be a good idea if I managed to create a preview functionality for displaying the final image before it is printed. To do that I tried using a TImage component and instead of sending my data to the printer canvas send it to the image canvas by using something like tho code below.

ImageViewer1.Canvas.Font.Size := 15;
ImageViewer1.Canvas.Font.Family   := 'Arial';
ImageViewer1.Canvas.Font.Style  := [TFontStyle.fsbold];
ImageViewer1.Canvas.Fill.Color  := claBlack;
ImageViewer1.Canvas.Fill.Kind := TBrushKind.Solid;

s := 'Test Print';
l := Round((ImageViewer1.Width - ImageViewer1.Canvas.TextWidth(s)) / 99);
t := Round(ImageViewer1.Canvas.TextHeight(s)*3/100);
r := l + Round(ImageViewer1.Canvas.TextWidth(s));
b := t + Round(ImageViewer1.Canvas.TextHeight(s));

ImageViewer1.Canvas.FillText(TRectF.Create(l, t, r, b), s, false, 1,
  [TFillTextFlag.RightToLeft], TTextAlign.Leading, TTextAlign.Leading);

The thing is that in the end nothing gets displayed in my TImage component. Have I done something wrong?

1
You know that you are not creating a print preview here, right? You are creating a data preview for print data. A print preview contains print information gathered from the printer like DPI, margins, page sizes, orientation etc. (Also, your problem might be that you are creating your data preview outside the ImageViewer. try using (0, 0) as the origin of your canvas.) - mg30rg

1 Answers

2
votes

What you are creating is not a print preview.

Print previews show orientation, margins and such. If you wish to create a print preview, you should do this:


You can create your own print-preview of anything that you send to the printer. Just replace Printer.Canvas by the Canvas of a TImage component, that is placed on an otherwise empty form.

In other words: create a new form, place a TImage on it (set it to alClient) and just modify your printing routine to accept a TCanvas as a paramenter. That way you can use the same routine for both the printer and the TImage canvas.