How can i set the printing size (width and height) by code without showing a dialog? Thanks
What exactly do you mean by "printing size"? Do you mean that you want to select the type of paper to print on, if your printer is loaded with papers of different format? Then I do not know.
If you just want to alter the margins, this is easy, but depends on how you print.
If you are printing manually (using Printer.BeginDoc
etc.), then you simply draw on the priter's canvas further from the edges! If you are printing using a TRichEdit
, you can change the PageRect
property.
there's a lot to this...
here's one little piece that helps get the font size correct:
Printer.Canvas.Font.PixelsPerInch:=GetDeviceCaps(Printer.Canvas.Handle,LOGPIXELSY);
See the MSDN documentation for GetPrinter and SetPrinter. You can find basic examples of their use in Delphi here and here. The second example has specific code for setting paper size.
From your comments to other answers, it seems like you want to select the type of paper (A4, Legal, etc) - is that right?
This page states that to select the paper type, you need to use the Printer.GetPrinter
function to get a device handle for the printer, then use GlobalLock
to get a pointer you can access, cast to a PDeviceMode. There is then a PaperSize
member of the TDeviceMode
that pointer points to which can be A4, legal, etc.
This was all just turned up via Google. Scroll to 'Printer Properties' on this page for where I got this info. This page mentions changing the tray too.
Meta-note
By the way, from all the answers and your comments - eg, one quote:
This is not what i want. thanks – Armin
@Armin: Then perhaps you should more clearly state what you do want. – Ken White
it's clear you need to learn how to ask clear questions. When you first asked a question on SO, you would have been directed to this page. If you skipped past it, go back and read it. If you did read it, you may find this 'Asking better questions' page useful to read too.
This is for your benefit - if you want a solution, and we assume you do because you asked about it, then it's in your benefit to do what you can to make your problem clear, non-confusing, and easy for someone to understand so that they can answer. No-one is obliged to answer - we just do it because we want to for whatever reason. Don't make it hard or put unnecessary obstacles in the way.
For example, you wrote "printing size" and "I mean (as i told) format of paper. I wonna change it (change paper width and height)". These could mean several things. The size of the margins? The resolution, or changing the units you print to? The type of paper, ie the physical size of the paper you will print on, if the printer supports several options? You need to be clear what you want. It might seem clear to you, but that's because you've been thinking about it - the only knowledge we have about your problem is what you wrote, so you need to include in what you write everything we need to know, from scratch, to understand the problem.