Copyright: Copyright © 1996, Eminent Domain Software


Additional Printing Routines

Included are a few printing routines which are often needed for Delphi applications.

SetPixelsPerInch insures that the Printer.Canvas.Font.PixelsPerInch property is set properly.  This routine should be called before every Printer.BeginDoc call to insure that the printed text is sized correctly.  Without a call to this routine (or one similar) your application will not be guaranteed of correct text sizing.  This is a Delphi oversight.

To duplicate this bug, print a document on your default printer, then, without exiting, print on a different printer with a different resolution.

CanvasTextOutAngle() allows rotated text to be displayed on any Canvas (Printer or screen).

GetResolution returns the printing resolution of the current printer.

ResetPrinterDialogs overcomes a Delphi bug by resetting the internal printer structures.  This symptons of this bug are that the PrintDialog and/or PrinterSetupDialog no longer function.  Calling the provided routine prior to PrintDialog1.Execute or PrinterSetupDialog1.Execute insures that they both run correctly.

To duplicate this bug:

1) Run the PrintDialog1.Execute

2) Select the Setup button

3) Select Ok

4) Select Cancel

5) Do this one more time

The PrintDialog will no longer work (at all).

In version 3.0, ResetPrinterDialogs is a PrintSet component method.

PrintMemo allows you to print a memo within a given rectangle.


BinIndex Property

Applies to

TPrintSet component

Declaration

property BinIndex: Byte;

Description

The currently selected bin source from the bin list which may be obtained from the GetBinSourceList method.


CanvasTextOutAngle

Declaration

procedure CanvasTextOutAngle (OutputCanvas: TCanvas; X, Y: integer;

Angle: Word; St: String);

Description

Allows rotated text to be displayed on any Canvas (Printer or screen).


Color Property

Example

Applies to

TPrintSet component

Declaration

property Color: Integer;

Description

Specifies whether a color printer is to render color or monochrome output.  Possible values as defined in the WinTypes.INT file are: dmcolor_Color (1) or dmcolor_Monochrome (2).


Contents

"Custom Software Development For Your Domain"

EDSPrint(Set) Component v4.0

(c) Copyright 1995-1998, Eminent Domain Software

Formerly known as the PrintObj unit, EDSPrint enables the Delphi developer to programmatically set several printer properties including page size (i.e. Legal, Letter), printer resolution, and more.  The unit is now published as a component which can be dropped onto a form as you would any other component.  Like other components you must first follow the Installation Instructions to add the PrintSet component onto the Delphi Component Palette.  The installation instructions will also show you how to add this new online help which can be easily integrated into the Delphi help subsystem.

Why do you need EDSPrint?

Version 2.2 adds three new additional printing routines often requested by Delphi developers.

Version 3.0 now adds support for Delphi 2.0

Version 4.0 now adds support for Delphi 4.0.

EDSPrint has become a very popular component (maybe we should'a charged for this thing?).  I have had a number of requests to update it with several features and the variety of programs that it is being used in is very diverse.  Because of this EDSPrint is now a shareware product.  	You can now register it for $29 (CIS SWREG#10105).  Once registered you will receive notices of upgrade/feature enhancements/bug fixes as well as free support.  If you intend on using EDSPrint in any of your prorgams you must register it.

Just drop EDS an e-mail with your address so that we can notify you of subsequent updates.  You can always download the latest EDSPrint from the Delphi VCL Library on Compuserve or on the net at: http://www.OneDomain.com

See Also

Installation Instructions

The PrintSet Component

Additional Printing Routines

Other EDS Components

Contacting Eminent Domain Software


Copies Property

Example

Applies to

TPrintSet component

Declaration

property Copies: Integer;

Description

The number of copies to be printed if the printer supports mulitple page printing.


CustomPageSetup
CustomPageSetup Method

Example

Applies to

TPrintSet component

Declaration

procedure CustomPageSetup (Width, Height: Double);

Description

Sets up a custom page.  See the label printing example.


DefaultSource Property

Example

Applies to

TPrintSet component

Declaration

property DefaultSource: Integer;

Description

Selects the default paper source for the current printer.  Possible values contain the prefix dmbin (e.g. dmbin_Upper) and are defined in the WinTypes.INT file in the DELPHI\DOC directory.


DriverSetupDialog Method

Applies To

TPrintSet

Declaration

procedure DriverSetupDialog;

Description

Executed the current printer driver's setup dialog.  Same as running the PrinterSetupDialog and clicking on the Options button.


Duplex Property

Example

Applies to

TPrintSet component

Declaration

property Duplex: Integer;

Description

Specifies duplex (double-sided) printing for printers capable of duplex printing.  This member as defined in the WinTypes.INT file can be dmdup_Simplex (1), dmdup_Horizontal (2), and dmdup_Vertical (3).


EDSPrint Unit

The EDSPrint unit contains the TPrintSet class which encapsulates the windows TDevMode structure.

When you add a component declared in this unit to a form, the unit is automatically added to the uses clause of that form's unit.

Components

TPrintSet

Constansts

CCHBinName

CBinMax

CPaperNames


Eminent Domain Software

"Custom Software Development For Your Domain"

Address:	Eminent Domain Software

200 Springs

Ste. 1326

Birmingham, Texas 35242

Phone:	(205) 437-0951

Fax:	(205) 437-0951

CIS:	70600,3451

Internet:	eds@onedomain.com


ExCustomPageSetup
The following code prints on a 3.5" x 1" label.  Note: When measuring printer labels, measure from the top of one label to the top of the next.  This gives you the true page height.

procedure TForm1.PrintLabel1Click(Sender: TObject);

var

  PrnFile: TextFile;

begin

  PrintSet1.ResetPrinterDialogs;

  if PrintDialog1.Execute then

  begin

    PrintSet1.SetDeviceMode (FALSE);  {in case printer changed in PrintDialog}

    PrintSet1.CustomPageSetup (3.5, 1);

    Printer.Canvas.Font.Name := 'Courier New';

    Printer.Canvas.Font.Size := 11;

    SetPixelsPerInch;

    {now print the label}

    AssignPrn (PrnFile);

    Rewrite (PrnFile);

    WriteLn (PrnFile, 'Customer Name');

    WriteLn (PrnFile, 'Address');

    WriteLn (PrnFile, 'City, State  ZipCode);

    CloseFile (PrnFile);

  end;  { if... }

end;


GetBinSourceList Method

Applies To

TPrintSet

Declaration

function GetBinSourceList: TStringList;

Description

Returns a string list of the available paper sources.


GetPaperList Method

Applies To

TPrintSet

Declaration

function GetPaperList: TStringList;

Description

Returns a string list of the available page types.


GetResolution

Declaration

function GetResolution: TPoint;

Description

Returns the resolution of the Printer in X (Horizontal) and Y (Vertical) dpi.


InchesDown
InchesDown Method

Applies To

TPrintSet

Declaration

function InchesDown (Inches: Double): integer;

Description

Returns the dot position of the specified location along the y-axis.


InchesOver
InchesOver Method

Applies To

TPrintSet

Declaration

function InchesOver (Inches: Double): integer;

Description

Returns the dot position of the specified location along the x-axis.


Installation Instructions

See Also

Installing the EDSSpell Help

The install program copies a help files and a keyword files to the EDSVCL directory.  To install the EDSPrint integrated help into Delphi, copy the EDSPRINT.HLP file into the DELPHI\BIN directory and copy the EDSPRINT.KWF file into the DELPHI\HELP directory.

Install EDSPRINT.KWF by running Delphi's HelpInst utility (do not do this while Delphi is running).  Select File|Open from the menu and open DELPHI.HDX in the DELPHI\BIN directory.  A list of current *.KWF files is shown.  Select the Keywords|Add option from the menu and add the EDSPRINT.KWF file.  Select File|Save and exit HelpInst.

Adding the component to Delphi's Component Palette

The files for Eminent Domain Software's EDSPrint Component for Borland's Delphi programming environment have been copied to your hard disk.  Before you can use EDSPrint, you must add the PrintSet component to the Delphi component palette.  Follow the instructions below to complete the installation:

2)  Execute Delphi.

2)  In Delphi select Options|Install Components|Add and browse the EDSVCL directory.

5)  Select EDSPR16.PAS Delphi (1.0) or EDSPR32.PAS (Delphi 2.0)

After the component library is rebuilt, you will notice the PrintSet component the Domain tab of your component palette.


Orientation Property

Example

Applies to

TPrintSet component

Declaration

property Orientation: Integer;

Description

Sets the orientation of the printer.  This member as defined in the WinTypes.INT file can be dmorient_Portrait (1), or dmorient_Landscape (2).


Other EDS Components

The EDSSpell Checking Component for Delphi allows developers to add a fast spell checking engine to their Delphi applications.  Simply drop the SpellDlg component from the Delphi Component Palette as you would an OpenDialog or PrintDialog.  You may then spell check a memo:

  procedure TForm1.SpellCheck1Click (Sender: TObject);

  begin

    SpellDlg1.SpellCheck (Memo1);

  end;  { TForm1.SpellCheck1Click }

You can also spell check all components on a form:

  procedure TForm1.SpellCheck1Click (Sender: TObject);

  begin

    SpellDlg1.CheckAllFields (Form1, TRUE);

  end;  { TForm1.SpellCheck1Click }

Version 3.0 of EDSSpell now supports TurboPower's powerful Orpheus components.  See the EDSSPELL.HLP file for more information.

The EDS Execute Delphi utility automatically unclutters the Delphi desktop by minimizing all Windows applications prior to running Delphi.

Version 2.0 now restores the Windows desktop after you exit Delphi.  And hey, it's free!

Ordering from Eminent Domain Software


PaperIndex Property

Applies to

TPrintSet component

Declaration

property PaperIndex: Byte;

Description

The currently selected paper from the paper list which may be obtained from the GetPaperList method.


PaperLength Property

Example

Applies to

TPrintSet component

Declaration

property PaperLength: Integer;

Description

A paper length, in tenths of a millimeter. This parameter overrides the paper length specified by the PaperSize property, either for custom paper sizes or for such devices as dot-matrix printers that can print on a variety of page sizes.


PaperSize Property

Example

Applies to

TPrintSet component

Declaration

property PaperSize: Integer;

Description

Specifies the paper size for the printer.  Possible values start with a prefix of dmpaper (e.g. dmpaper_Legal) and are defined in the WinTypes.INT.


PaperWidth Property

Example

Applies to

TPrintSet component

Declaration

property PropertyWidth: Integer;

Description

Specifies the paper width, in tenths of a millimeter.  This value overrides the paper width specified by the PaperSize property.


PrintMemo

Example

Declaration

procedure PrintMemo (TheMemo: TMemo; Rect: TRect);

Description

Prints the specified memo within the desired rectangle.


PrintQuality Property

Example

Applies to

TPrintSet component

Declaration

property PrintQuality: Integer;

Description

Specifies the the printer resolution. The four predefined device-independent values as defined in the WinTypes.INT file are dmres_high (-4), dmres_Medium (-3), dmres_Low (-2), and dmres_Draft (-1).  If a positive value is given, it specifies the number of dots per inch (DPI) and is therefore device-dependent. If the printer initializes the YResolution property, the PrintQuality property specifies the x-resolution of the printer, in dots per inch.


PrinterDriver Property

Applies to

TPrintSet component

Declaration

property PrinterDriver: String;

Description

The current printer's driver.

Type

Runtime, ReadOnly


PrinterName Property

Applies to

TPrintSet component

Declaration

property PrinterName: String;

Description

The current printer's name.

Type

Runtime, ReadOnly


PrinterPort Property

Applies to

TPrintSet component

Declaration

property PrinterPort: String;

Description

The current printer's port.

Type

Runtime


ReadFromIniFile
ReadFromIniFile Method

Example

Applies To

TPrintSet

Declaration

function ReadFromIniFile (IniFileName, Section: String): Boolean;

Description

Reads and sets the printer settings from the specified INI file's section as saved using the SaveToIniFile method.


ResetPrinterDialogs
ResetPrinterDialogs Method

Applies to

TPrintSet component

Declaration

procedure ResetPrinterDialogs;

Description

Overcomes a Delphi bug by resetting the internal printer structures.  This symptons of this bug are that the PrintDialog and/or PrinterSetupDialog no longer function.  Calling the provided routine prior to PrintDialog1.Execute or PrinterSetupDialog1.Execute insures that they both run correctly.

To duplicate this bug:

1) Run the PrintDialog1.Execute

2) Select the Setup button

3) Select Ok

4) Select Cancel

5) Do this one more time

The PrintDialog will no longer work (at all).


SavePrinterAsDefault
SavePrinterAsDefault Method

Applies To

TPrintSet

Declaration

procedure SavePrinterAsDefault;

Description

Save the current printer as the Window's default printer.  This is particularly useful for running an external program with page settings different than the current defaults.


SaveToDefaults Method

Applies To

TPrintSet

Declaration

procedure SaveToDefaults;

Description

Save the current printer settings as defaults.  This is particularly useful for running an external program with page settings different than the current defaults.


SaveToIniFile
SaveToIniFile Method

Applies To

TPrintSet

Declaration

procedure SaveToIniFile (IniFileName, Section: String);

Description

Save the current printer to the specified INI file's section.  This routine (along with its counterpart ReadFromIniFile) allows you to restore a printer's settings very easily.   For example, let's say you have a database program that allows you to print a customer label.  Unfortunately, you can't (or shouldn't) assume that the current printer is the label printer.  You also can't reliably save the Printer.PrinterIndex property to an INI file to restore the proper printer either (what if the user adds or deletes a printer from his/her printer list - the PrinterIndex is no longer valid).


Scale Property

Example

Applies to

TPrintSet component

Declaration

property Scale: Integer;

Description

The factor by which the printed output is to be scaled. The apparent page size is scaled from the physical page size by a factor of Scale/100. For example, a letter-size paper with a Scale value of 50 would contain as much data as a page of size 17 by 22 inches because the output text and graphics would be half their original height and width.


SetBinFromList Method

Applies To

TPrintSet

Declaration

function SetBinFromList: TStringList;

Description

Sets the DefaultSource to the specified item in the bin list returned from GetBinSourceList.


SetDeviceMode Method

Applies To

TPrintSet

Declaration

procedure SetDeviceMode;

Description

Updates the Windows internal TDevMode structure.  You should rarely (if ever) need to call this directly.


SetPaperFromList Method

Applies To

TPrintSet

Declaration

function SetPaperFromList: TStringList;

Description

Sets the PaperSize to the specified item in the bin list returned from GetPaperList.


SetPixelsPerInch

Declaration

procedure SetPixelsPerInch;

Description

Insures that the Printer.Canvas.Font.PixelsPerInch property is set properly.  This routine should be called before every Printer.BeginDoc call to insure that the printed text is sized correctly.  Without a call to this routine (or one similar) your application will not be guaranteed of correct text sizing.  This is a Delphi oversight.

To duplicate this bug, print a document on your default printer, then, without exiting, print on a different printer with a different resolution.


TPrintSet Component

Properties	   Methods

Unit

EDSPrint

Description

The TPrintSet component allows the Delphi developer to set several printer properties.

Several page properties may be set using TPrintSet.  You may set the page orientation using the Orientation property.  You may set the paper type (i.e. Letter, Legal) using the PaperSize property.

The print resolution of the printer can be accessed through the PrintQuality property.


TPrintSet Methods

Methods

Key methods

   CustomPageSetup	 DriverSetupDialog

   GetBinSourceList	 GetPaperList

   InchesDown	 InchesOver

   ReadFromIniFile	 ResetPrinterDialogs

   SaveToDefaults	 SaveToIniFile

   SavePrinterAsDefault	 SetDeviceMode

   TextOut	 UpdateDeviceMode


TPrintSet Properties

Properties

 BinIndex	 Color	 Copies

 DefaultSource	 Duplex	 Orientation

 PaperIndex	 PaperLength	 PaperSize

 PaperWidth	 PrinterDriver	 PrinterName

 PrinterPort	 PrintQuality	 Scale

 TTOption	 YResolution


TTOption Property

Example

Applies to

TPrintSet component

Declaration

property TTOption: Integer;

Description

Specifies how TrueType fonts should be printed.  The following as defined in the WinTypes.INT file are dmTT_Bitmap (print TrueType fonts as graphics - this is the default action for dot-matrix printers),  dmTT_Download (download TrueType fonts as soft fonts - this is the default action for Hewlett-Packard printers that use PCL), and dmTT_SubDev (substitute device fonts for TrueType fonts - this is

the default action for PostScript printers).


TextOut
TextOut Method

Applies To

TPrintSet

Declaration

procedure TextOut (X, Y: Double; St: String);

Description

Outputs the specified string at the location (in inches) provided.


UpdateDeviceMode Method

Applies To

TPrintSet

Declaration

procedure UpdateDeviceMode;

Description

Updates Delphi's internal TDevMode structure.  You should rarely (if ever) need to call this directly.


Why do you need EDSPrint?

EDSPrint resolves several problems inherent in the Delphi environment.

Inconsistent Text Sizing

The first problem involves text sizing.  Depending on your setup (well, your computers setup) you will notice that your application may print its text at varying sizes at different times.  Try printing on your default printer, then, without leaving your program, select a different printer of a different resolution.  You might notice that the size of the text on the two pages is different.  The problem is due to the fact that Delphi does not change the Printer.Canvas.Font.PixelsPerInch property when a change of printer has been made.  To overcome this oversight, we have included a routine called SetPixelsPerInch.

Printer Dialogs Quit Working

From time to time, the PrintDialog and PrinterSetupDialog seem to mysteriously quit working.  Try this in your Delphi application:

1) Run the PrintDialog1.Execute

2) Select the Setup button

3) Select Ok

4) Select Cancel

5) Do this one more time

The PrintDialog will no longer work (at all).

This is just one way of getting them to quit working.  There are many.  To overcome this, we have included a method called ResetPrinterDialogs.

No Way To Change Paper Sizes

Windows maintains a stucture which contains the current page settings (TDevMode).  Unfortunately, the Delphi VCL does not provide a straightforward way of accessing and modifying the values in the TDevMode structure.  So there is no way for you to make sure that your application defaults to a letter size page.  There is also no way of setting up your printer to print on custom paper sizes (for checks or labels).  That's where the TPrintSet component comes in.  We have also included a simple routine for setting up custom page sizes,  CustomPageSetup.

No Simple Way To Save/Restore Printer Information

EDSPrint allows you to save and restore printer settings.  This allows you to give your users a way of setting up alternate printers for printing alternate reports.  For example, let's say you have a database program that allows you to print a customer label.  Unfortunately, you can't (or shouldn't) assume that the current printer is the label printer.  You also can't reliably save the Printer.PrinterIndex property to an INI file to restore the proper printer either (what if the user adds or deletes a printer from his/her printer list - the PrinterIndex is no longer valid).  EDSPrint provides to simple routines, SaveToIniFile and ReadFromIniFile, which allow you to save and restore the current printer and its settings.


YResolution Property

Example

Applies to

TPrintSet component

Declaration

property YResolution: Integer;

Description

Specified the resolution of the printer in dots per inch.  If the printer initializes this property, the PrintQuality property specified the x-resolution of the printer in dots per inch.


ex:Bin

Example

The following code sets the bin source for the current printer to envelope:

  procedure TForm1.SetPrintEnvelope (Sender: TObject);

  begin

    PrintSet1.Bin := dmbin_Envelope;

  end;  { TForm1.SetPrintEnvelope }


ex:Color

Example

The following code sets the color printer to output monochrome:

  procedure TForm1.SetToMonochrome (Sender: TObject);

  begin

    PrintSet1.Color := dmcolor_Monochrome;

  end;  { TForm1.SetToMonochrome }


ex:Copies

Example

The following code sets the number of copies to be printed to 5:

  procedure TForm1.SetNumberOfCopies (Sender: TObject);

  begin

    PrintSet1.Copies := 5;

  end;  { TForm1.SetNumberOfCopies }


ex:Duplex

Example

The following code sets the printer to duplex printing:

  procedure TForm1.SetDuplexPrinting (Sender: TObject);

  begin

    PrintSet1.Duplex := dmdup_Horizontal;

  end;  { TForm1.SetDuplexPrinting }


ex:Orientation

Example

The following code sets the page orientation to landscape:

  procedure TForm1.SetLandscape (Sender: TObject);

  begin

    PrintSet1.Orientation := dmorient_Landscape;

  end;  { TForm1.SetLandscape }


ex:PaperLength

Example

The following code sets the paper size to 9 inches:

  procedure TForm1.SetPaperLength (Sender: TObject);

  const

    MillimetersPerInch = 254;

  begin

    PrintSet1.PaperLength := 9 * MillimetersPerInch;

  end;  { TForm1.SetPaperLength }


ex:PaperSize

Example

The following code sets the paper size to Legal:

  procedure TForm1.SetLegal (Sender: TObject);

  begin

    PrintSet1.PaperSize := dmpaper_Legal;

  end;  { TForm1.SetLegal }


ex:PaperWidth

Example

The following code sets the paper width to 5 inches:

  procedure TForm1.SetPaperWidth (Sender: TObject);

  const

    MillimetersPerInch = 254;

  begin

    PrintSet1.PaperWidth := 5 * MillimetersPerInch;

  end;  { TForm1.SetPaperWidth }


ex:PrintQuality

Example

The following code sets the printer to high resolution printing:

  procedure TForm1.SetHiRes (Sender: TObject);

  begin

    PrintSet1.PrintQuality := dmres_High;

  end;  { TForm1.SetHiRes }


ex:ReadFromIniFile
The following code show how to use the ReadFromIniFile settings.

const

  PrintersIni  = 'PRINTERS.INI';

  ColorSection = 'Color Printer';

  LabelSection = 'Label Printer';

procedure TForm1.PrintBrochure;

begin

  {print color brochure to color printer}

  if not ReadFromIniFile (PrintersIni, ColorSection) then

  begin

    {set up color printer}

    if MessageDlg ('No color printer specified.  Please set one up.',

                   mtError, [mbOk, mbCancel], 0) = mrCancel then Exit;

    PrinterSetupDialog1.Execute;

    SaveToIniFile (PrintersIni, ColorSection);

  end;  { if... }

  PrintColorBrochure;

  {print mailing label to label printer}

  if not ReadFromIniFile (PrintersIni, LabelSection) then

  begin

    {set up label printer}

    if MessageDlg ('No label printer specified.  Please set one up.',

                   mtError, [mbOk, mbCancel], 0) = mrCancel then Exit;

    PrinterSetupDialog1.Execute;

    SaveToIniFile (PrintersIni, LabelSection);

  end;  { if... }

  PrintLabel;

end;  { TForm1.PrintBrochure }


ex:Scale

Example

The following code sets the printer to print everything in half its original size:

  procedure TForm1.SetHalfPrinting (Sender: TObject);

  begin

    PrintSet1.Scale := 50;

  end;  { TForm1.SetHalfPrinting }


ex:TTOption

Example

The following code sets the printer to use bitmap fonts for TrueType:

  procedure TForm1.SetBitmapFonts (Sender: TObject);

  begin

    PrintSet1.TTOption := dmTT_Bitmap;

  end;  { TForm1.SetBitmapFonts }


ex:YResolution

Example

The following code sets the page resolution in dots per inch:

  procedure TForm1.SetPageResolution (Sender: TObject);

  begin

    PrintSet1.YResolution := 3300;   {300 dpi X 11"}

  end;  { TForm1.SetPageResolution }


exPrintMemo
The following code will print the memo in the a rectangle:

procedure TForm1.Print1Click(Sender: TObject);

begin

  if PrintDialog1.Execute then

  begin

    Printer.BeginDoc;

    with PrintSet1 do

      PrintMemo (Memo1, Rect (InchesOver (2), InchesDown (2),

                              InchesOver (6), InchesDown (4)));

    Printer.EndDoc;

  end;  { if... }

end;