Link to home
Start Free TrialLog in
Avatar of Matvey
Matvey

asked on

Printer.PageWidth/Height

Bitmap1.Height := Printer.PageHeight
Bitmap1.Width := Printer.PageWidth

Will create a bitmap with enormous sizes, especially if you have a high resolution printer. (I hope you can already see my problem... ) In other words: I want to make a bitmap that will serve as a virtual printer page (not the same amount of pixels, but proportional). I think I need to get the DPI for the printer or something. I didn’t find any specific shmAPI...

Big thanks if you can help me with this one
Avatar of mirek071497
mirek071497

Why you can't use canvas ?
Avatar of Matvey

ASKER

Printer.Canvas.Font.Assign(Form1.Canvas.Font);
Form1.canvas.TextHeight('A');
Printer.canvas.TextHeight('A');

-Give different values!
Hmm, that leads me somewhere! Thank you already, I have a good idea now - divide the two values... yeah, that might help. I'll find the resolution then or something...
I think, (but this can be created in other way) so the Printer.Canvas is created with scale depends from assigned printer to them so you can try to read printer dpi, screen dpi and in this way compute the scale.

sorry for my english.
Avatar of Matvey

ASKER

I have a problem with printer fonts. Specific fonts will show normally on the bitmap canvas, but not on the printer canvas. I want to draw to the bitmap canvas, and then copy it to the printer.
Hello matvey,
I suggest you use metafiles, it's the only good solution you have I think.
If you want to make such thing I think that you can easely find and already made component.
I have a component called tpagePrinter by bill menees.
About the metafile stuff here is an example from the delphi help :
metafile are not working like usual stuff.

MyMetafile := TMetafile.Create;

with TMetafileCanvas.Create(MyMetafile, 0) do
try
  Brush.Color := clRed;
  Ellipse(0,0,100,100);
  ...
finally
  Free;

end;
Form1.Canvas.Draw(0,0,MyMetafile); {1 red circle }

To add something to a metafile after it has been created you have to do
something like create first a canvas.

with TMetafileCanvas.Create(MyMetafile, 0) do

try
  Draw(0,0,MyMetafile);
  Brush.Color := clBlue;
  Ellipse(100,100,200,200);
.
finally
  Free;

end;

Form1.Canvas.Draw(0,0,MyMetafile);

When your stuff is done you can draw things to the printer canvas.
I hope this will help you.
Avatar of Matvey

ASKER

Thanks. It works fine with a BMP too, so I don't really need any metafiles. I was just searching for "scaling things", you know, I have a problem with the scaling.

I would love to see any existing components. Please do email me whatever on your mind: bosism@netvision.net.il
Matvey,

here it is :

ScaleX := GetDeviceCaps(Printer.Handle, logPixelsX) div PixelsPerInch;
         ScaleY := GetDeviceCaps(Printer.Handle, logPixelsY) div PixelsPerInch;
         (* Convert printer dimensions to screen dimensions *)
         PageWidth := Printer.PageWidth div ScaleX;
         PageHeight := Printer.PageHeight div ScaleY;
Regards, Zif.

Avatar of Matvey

ASKER

Hi Zif, the funny thing is that I tried DeviceCaps, but I used Printer.Canvas.Handle instead :-)

I'll be right here in a sec...
BTW why to use the PixelPerInch of the form???
Hi Matvey,

 b'cos :

LOGPIXELSX : Number of pixels per logical inch along the screen width (in our case printer).
LOGPIXELSY : Number of pixels per logical inch along the screen height (in our case printer).

Zif.
Avatar of Matvey

ASKER

Zif your answere works fine. It was hard to decide, but I want to give the points Jeurk, because he gave me a much better idea. I didn't treat the metafile idea in the beginning, but as I saw the bitmap idea is very slow and uncomfy becuase of the size a 3000x3000 pixel pitmap takes. So I decided to use a metafile.
I didn't use the component though, but it also has some nice ideas (want to see it Zif?).
So thanks guys. You all gave me three working ideas (mirek, Jeurk and Zif), but I followed Jeurk's idea so I want to give him the points.
Big thanks, and c u soon. (Post an answere Jeurk...)
Hi Matvey, no prob. I know of the component, because I've use it myself... I once answered here a question about printing a mirrored page. I modefied this component so it worked like this.
Zif.
ASKER CERTIFIED SOLUTION
Avatar of jeurk
jeurk

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Matvey

ASKER

Thanks again jeurk...
You're welcome.