Solved

Printer.PageWidth/Height

Posted on 1998-07-29
14
510 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:Matvey
  • 6
  • 3
  • 3
  • +1
14 Comments
 
LVL 3

Expert Comment

by:mirek071497
ID: 1359000
Why you can't use canvas ?
0
 
LVL 3

Author Comment

by:Matvey
ID: 1359001
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...
0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1359002
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.
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 3

Author Comment

by:Matvey
ID: 1359003
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.
0
 
LVL 4

Expert Comment

by:jeurk
ID: 1359004
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.
0
 
LVL 3

Author Comment

by:Matvey
ID: 1359005
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
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359006
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.

0
 
LVL 3

Author Comment

by:Matvey
ID: 1359007
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???
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359008
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.
0
 
LVL 3

Author Comment

by:Matvey
ID: 1359009
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...)
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359010
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.
0
 
LVL 4

Accepted Solution

by:
jeurk earned 40 total points
ID: 1359011
And the winner is ?
Just jeurking :)
I'm happy your problem is solved. I know that many times the points are hard to
distribute, because this is a group work.

Zif:
I remember the mirror problem. I was working on doing a workable solution using
metafiles when you came out with the good solution. That's the life ;)

Matvey : I sent you another component that shows how to load a
4000 x 4000 x 256 colour bitmap.

Regards



0
 
LVL 3

Author Comment

by:Matvey
ID: 1359012
Thanks again jeurk...
0
 
LVL 4

Expert Comment

by:jeurk
ID: 1359013
You're welcome.
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question