Delphi/CB
•  Greatis •  Security •  AppDatabase •  Utilities •  Visual Basic • .NET •  just4fun
Delphi / C++ Builder
Components, utilities and tips for Delphi and C++ Builder developers
More info
Print Suite FAQ
Print Suite Home
Delphi Components
See also
Products
Form Designer
Object Inspector
Runtime Fusion
Commented Image
Image Editor  new!
Delphi Toys
Ultimate Pack  hot!

FAQs
Form Designer FAQ
Object Inspector FAQ
Image Editor FAQ

Links
Software for .NET
Software for VB 6
Delphi Tips & Tricks

Services
Outsourcing
Printing exact size
TPrintJob component has many useful methods those allow to transfer the units between pixels, inches and millimeters.
function InchToMm(Inches: Double): Double;
function MmToInch(Millimeters: Double): Double;
function InchToPix(Inches: Double; Direction: TDirection): Double;
function MmToPix(Millimeters: Double; Direction: TDirection): Double;
function PixToMm(Pixels: Double; Direction: TDirection): Double;
function PixToInch(Pixels: Double; Direction: TDirection): Double;
All functions related to pixels has an additional Direction parameter of the TDirection type.
TDirection = (dirHorizontal,dirVertical);
This parameter is used for retreiving the vertical or horizontal resolution of the printer to correct calculation, because the vertical and horizontal resultions can be different.

TPrintJob has the ConvertUnits method that can convert the values between any units.

type
  TUnits = (unPixels,unPercents,unInches,unMillimeters);

function ConvertUnits(
  Source: Double;              // source value
  FromUnits,ToUnits: TUnits;   // source and target units
  Dir: TDirection;             // direction
  FullRange: Double): Double;  // full range for percent units,
                               // usually page size
Any of these functions can be used for printing the graphic objects with the exact size. TCanvas and WinAPI functions receves all sizes in pixels, so to print the inch square just get the pixel size of such square using the InchToPix function.
procedure TForm1.PrintJob1Draw(Sender: TObject; TheCanvas: TCanvas;
  PageIndex: Integer; TheRect: TRect; Area: TDrawArea;
  Target: TDrawTarget);
begin
  with Sender as TPrintJob,TheCanvas,TheRect do
    if Area=daPage then
    begin
      Rectangle(
        Left,
        Top,
        Left+Trunc(InchToPix(1,dirHorizontal)),
        Top+Trunc(InchToPix(1,dirVertical)));
    end;
end;

Greatis Software Greatis | Security | AppDatabase | Utilities | Delphi/CB | Visual Basic | .NET | just4fun

Contacts | Add to Favorites | Recommend to a Friend | Privacy Policy | Copyright © 1998-2008 Greatis Software