Recent

Author Topic: getting printer resolution (winApi) problem  (Read 18989 times)

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1933
Re: getting printer resolution (winApi) problem
« Reply #15 on: June 26, 2009, 12:59:41 am »
What if you do this? Are there two rectangles? Is one of them at the right place?
It works for me on a real printer. CUPS-PDF has no margins.

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
begin
 if PrintDialog1.Execute then
  begin
   Caption:=Inttostr(TPrinterCanvas(Printer.Canvas).LeftMargin)+' '+Inttostr(TPrinterCanvas(Printer.Canvas).TopMargin);
   Printer.BeginDoc;
    Printer.Canvas.Rectangle(
    round(2*Printer.XDPI / 2.54),
    round(2*Printer.YDPI / 2.54),
    round(3*Printer.XDPI / 2.54),
    round(3*Printer.YDPI / 2.54));

    Printer.Canvas.Rectangle(
    round(2*Printer.XDPI / 2.54)-TPrinterCanvas(Printer.Canvas).LeftMargin,
    round(2*Printer.YDPI / 2.54)-TPrinterCanvas(Printer.Canvas).TopMargin,
    round(3*Printer.XDPI / 2.54)-TPrinterCanvas(Printer.Canvas).LeftMargin,
    round(3*Printer.YDPI / 2.54)-TPrinterCanvas(Printer.Canvas).TopMargin);

   Printer.EndDoc;
  end;
end;   

Probably you can get these values also in a more "official" way by using
Printer.PaperSize.PaperRect
I don't know. Please test.
« Last Edit: June 26, 2009, 01:02:06 am by theo »

alanphys

  • Jr. Member
  • **
  • Posts: 57
Re: getting printer resolution (winApi) problem
« Reply #16 on: June 26, 2009, 08:41:16 am »
Having battled with this problem myself, I have discovered that under linux and windows Lazarus handles printing differently. Under linux everything is converted to postscript. XDPI and YDPI always give 72 dpi no matter which printer you are using. Under windows the printer is queried directly and this can lead to some strange results particularly for the cheaper ink jet printers.

The other problem is that different printers have differing non-printing margins. Some printers seem to include these margins in their positioning information and others don't. Some printers seem to specify a fixed top and left offset margin by which everything is shifted.

If your application does not require absolute positioning the easiest is to tweak your printing until you get something that is reasonably consistent and try it on as many printers as possible.

Cheers
Alanphys
Alanphys
Fedora 34 + KDE/QT5, Tinycore 8, Windows XP-10
https://github.com/alanphys

ensimek

  • Jr. Member
  • **
  • Posts: 55
Re: getting printer resolution (winApi) problem
« Reply #17 on: June 26, 2009, 12:28:31 pm »
I found the problem. Getting X/Y DPI works well i forgot i put papersize to A5, thats why text was in different distance from 0,0 uising the same DPI.

Got another problem, is there any way to get selected item from LixtBox?
Lets say i got:
1: Chicago
2. New York
3. Las Vegas
4. Wyoming

multiselect:= false;

how can i get selected by user value?

ensimek

  • Jr. Member
  • **
  • Posts: 55
Re: getting printer resolution (winApi) problem
« Reply #18 on: June 26, 2009, 02:06:15 pm »
and how can I specify margin?

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2673
Re: getting printer resolution (winApi) problem
« Reply #19 on: June 26, 2009, 05:00:01 pm »
Got another problem, is there any way to get selected item from LixtBox?
Listbox.ItemIndex
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

ensimek

  • Jr. Member
  • **
  • Posts: 55
Re: getting printer resolution (winApi) problem
« Reply #20 on: June 26, 2009, 09:11:17 pm »
this will get the Index of item, how can i get name of the selected item lets say 'Chicago'

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2673
Re: getting printer resolution (winApi) problem
« Reply #21 on: June 27, 2009, 03:02:52 am »
Code: [Select]
if Listbox.ItemIndex = -1
then Result := ''
else Result := Listbox.Items[Listbox.ItemIndex];
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

 

TinyPortal © 2005-2018