Solved

Printer.PageWidth/Height

Posted on 1998-07-29
14
526 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

737 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