Solved

Printer.PageWidth/Height

Posted on 1998-07-29
14
500 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

758 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now