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?

1
  • 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.) Commented Oct 1, 2014 at 10:33

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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.
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."
I tried that by creating a destination canvas that starts from 0,0 but nothing changed.
After searching a while I believe it is something to do with this, link I think I am drawing in the form instead of may TImage component.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.