Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Printer.PageWidth/Height

Posted on 1998-07-29
14
Medium Priority
?
543 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 160 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

963 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