0

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?

LU RD
  • 34,438
  • 5
  • 88
  • 296
dearn44
  • 3,198
  • 4
  • 30
  • 63
  • 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 Oct 01 '14 at 10:33

1 Answers1

2

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.

mg30rg
  • 1,311
  • 13
  • 24
  • Thats what I am doing as you can see from the code above, but it is not working all that great until now as I explain in my question. – dearn44 Oct 01 '14 at 11:41
  • Then how about reading my other comment and trying the solution i came up with? _"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 Oct 01 '14 at 13:24
  • I tried that by creating a destination canvas that starts from 0,0 but nothing changed. – dearn44 Oct 02 '14 at 06:41
  • After searching a while I believe it is something to do with this, [link](http://stackoverflow.com/questions/24769644/image-canvas-drawing-ends-up-on-form-instead) I think I am drawing in the form instead of may TImage component. – dearn44 Oct 02 '14 at 08:16