Solved

How to Choose A4 or Letter paper

Posted on 2008-06-24
10
870 Views
Last Modified: 2011-04-14
My Delphi application will be used (hopefully) anywhere in the world. I would like reports to automatically default to either Letter or A4 paper depending on what would normally be the correct default for the user's location.

In Delphi, how can I determine if Letter or A4 is the more sensible default for any given user?
0
Comment
Question by:plumothy
  • 5
  • 4
10 Comments
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 21854599
this is a setting of the printer,
not of the application
0
 

Author Comment

by:plumothy
ID: 21854648
Yes, I realise that.

I want my application to be able to determine what paper size to use for its reports (perhaps by interrogating the default paper size on the default printer?), but I don't know how to do this.

Some countries prefer Letter paper, others prefer A4. If my application can make a sensible guess which one is best for the user so much the better.  My application will then generate print previews using the correct size - the user won't have to change it before clicking on Print.

So, I am after some code that will tell me "this user normally uses A4" or "this user normally uses Letter"
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 21854727
you could ask the printer what it's current paper size is with
Printer.PageWidth  
and
Printer.PageHeight

generally what happens here is:
certain applications must print with certain settings like an invoice:
original : A4 color, drawer 1
copy 1 : A4 black/white, drawer 2
copy 2: A5 black/white, drawer 3

how to solve this :
create a printer driver for each setting and give each a unique name
in your application specify what type of document you want to send to what printer
that way you can define a printer for A4
and one for Letter and ...

This is usually done by the printer/network adminstrator
and gives a lot more flexibility


0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 21854739
some printer drivers have scaling built in so they can print an A3 document on a Letter paper ...
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 21854858
Personally I would have thought that this wouldnt matter.
If the usual default of the persons PC is Letter then it will just print Letter size, if its A4 then it will print to their default A4.

Why would you have to make a decision on this when really the decision should have already been made for you?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:plumothy
ID: 21855120
In portrait, Letter paper is wider than A4 paper.  In landscape, A4 is wider than Letter.

If my application did not know in advance which paper size to use (or the user does not tell it) then it would draw some items outside the printable area of the paper. To put a realistic print preview on the screen you need to know what the paper size is.

Not all printers can do scaling.

Printer.PageHeight and Printer.PageWidth are nearly right, but they are in pixels. The number of pixels across the page will vary with the resolution of the printer.

If there was a property like Printer.PageSize (eg A4, Letter, etc) that would be great, but there isn't.

I have seen some applications which assume the shorter dimensions of both Letter and A4 to ensure never printing outside the printable area. The downside of that is there is then always some of the paper that doesn't get used whichever physical size is in the printer.
0
 
LVL 37

Accepted Solution

by:
Geert Gruwez earned 500 total points
ID: 21855991
this is some ancient code i found from my good old days
it gets the page size and density and converts it...

maybe you can find in here what you are lookin for
procedure TfrmCamGrid.PrintNewLayout(OnPrinter: Boolean; AStartPage: Integer; APrintPreviewForm: TFrmPrintPreview);

var BorderOffset: Integer;

  frm: TfrmPrintPreview;

  PhysicalPaperSize, Printing_Offset: TPoint;

  PageRect: TRect;

begin

  BorderOffset := 5;

  if Escape(Printer.Handle, GETPHYSPAGESIZE, 0, nil, @PhysicalPaperSize) <= 0 then

    MessageDlg('Internal error - cannot get physical paper size', mtError, [mbOK], 0);

  if Escape(Printer.Handle, GETPRINTINGOFFSET, 0, nil, @Printing_Offset) <= 0 then

    MessageDlg('Internal error - cannot get printing offset', mtError, [mbOK], 0);

  { *********************************************************** }

  { pixels per mm }

  if Printer.Orientation = poPortrait then

    mm_Pixel_Scale := PhysicalPaperSize.x / 210  { A4 }

  else

    mm_Pixel_Scale := PhysicalPaperSize.x / 297;

  { Distance in mm should be multiplied by this scale to get the corresponding number of pixels }
 

  ;

  ;

  PageRect := Rect(0, 0, Printer.PageWidth, Printer.PageHeight);

  if OnPrinter then

    PrintPageNew(Printer.Canvas, PageRect, OnPrinter, AStartPage)

  else

  begin

    if APrintPreviewForm = Nil then

    begin

      frm := TfrmPrintPreview.Create(Self, AStartPage, 0, PrintNewLayout, ChangeLayout, DoPrintFromPreview);

      try

        frm.imPreview.Width := Round(Printer.PageWidth / GetDeviceCaps(Printer.Handle, LOGPIXELSX) * PixelsPerInch)+5;

        frm.imPreview.Height := Round(Printer.PageHeight / GetDeviceCaps(Printer.Handle, LOGPIXELSY) * PixelsPerInch)+5;

        frm.imPreview.Picture.Bitmap.Width := Round(Printer.PageWidth / GetDeviceCaps(Printer.Handle, LOGPIXELSX) * PixelsPerInch);

        frm.imPreview.Picture.Bitmap.Height := Round(Printer.PageHeight / GetDeviceCaps(Printer.Handle, LOGPIXELSY) * PixelsPerInch);

        frm.Show;

        frm.Update;

        Application.ProcessMessages;

        frm.MaxPages := PrintPageNew(

          frm.imPreview.Picture.Bitmap.Canvas,

          Rect(

            BorderOffset,

            BorderOffset,

            frm.imPreview.Picture.Bitmap.Width-BorderOffset,

            frm.imPreview.Picture.Bitmap.Height-BorderOffset),

            False, AStartPage);

        frm.Hide;

        frm.Update;

        frm.ShowModal;

      finally

        frm.Free;

      end;

    end else

    begin

      frm := APrintPreviewForm;

      PrintPageNew(

        frm.imPreview.Picture.Bitmap.Canvas,

        Rect(

          BorderOffset,

          BorderOffset,

          frm.imPreview.Picture.Bitmap.Width-BorderOffset,

          frm.imPreview.Picture.Bitmap.Height-BorderOffset),

        False, AStartPage);

    end;

  end;

end;

Open in new window

0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 21856015
I got this new printer about a month ago.
It's a KODAK MP220 printer.
It's got a checkbox to "USE COMPLETE PAGE TO PRINT"
This overrides the setting for the border a printer can not print on
Just a setting on my printer, but probably other printer may have this setting too

It lets me print photos on the complete page without a white border.
0
 

Author Comment

by:plumothy
ID: 21856123
Thanks Geert_Gruwez, I have been able to use the relevant parts of your code.
0
 

Author Closing Comment

by:plumothy
ID: 31470068
Many thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Thread safe  opinion 7 126
How to fill array with TArray.Create? 14 79
How to debug For loops? 3 45
control image tags in a string ? 12 110
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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 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

25 Experts available now in Live!

Get 1:1 Help Now