Printer Projects

Contents

A. Delphi Examples
B. C Utility

AmazonTechnical.gif (2495 bytes)  in   look for  Delphi

A. Delphi Examples

Program Description Keywords
A-1
HardCopy

HardCopy.ZIP
(Delphi 3 Source and EXEs)
Simple Report Writer. ZIP file contains two examples of using a non-visual Hardcopy unit as a simple report writer. HardCopy1 shows how to print text at specific column or row; how to justify text (left, center, right); how to establish a column definition for tabular data; how to print bitmap (Delphi logo), circle or ellipse on Printer.Canvas; shades of gray; how to print certain information about the printer. HardCopy2 shows a simple business report with nine columns of data, justified appropriately, and with column headings. Also includes heading with logo (Delphi logo), title and page numbers. Tested only on an HP LaserJet 5 and an Epson Stylus Color ESC/P2. Printer, Report Writer, GetDeviceCaps, Bitmap
A-2
LaserJet

LaserJet.ZIP
(Delphi 1 Source and EXE. LaserJet.PAS should work in Turbo Pascal or Delphi 3)
Print directly to HP LaserJet using HP PCL. Example shows how to print text and shadowed boxes with different shading.

For info on PCL 3: www.ajp.clara.net

For commercial PCL products see: www.pcltools.com
HP LaserJet, PCL
A-3
Printer Demo #1

This Demo shows the following::
1. A rectangle to show the margins and printable area

2. Printer.Canvas properties.

3. GetDeviceCaps Values

4. Print image with and without transparency using Draw, StretchDraw, StretchDIBits and CopyRect.  [See Joe Hecht's notes about Printing and Transparency -- Item 11 on the Delphi Printing Info and Links page.]

5. How to print images (Spectrum, KC Fox) with 1-to-1 pixel mapping using Draw -- very small on most printers. Does not appear on some printers or versions of Delphi. For example, no image is displayed on LaserJet 5 in Delphi 1 or 2 but does appear in Delphi 3 with same printer.

6. Print same images, using StretchDraw.

7. Print Image the "right" way using StretchDIBits.

8. Create and Print Hue-Saturation color circle Bitmap with StrechDraw and StretchDIBits.

Draw sine curve to offscreen bitmap and then use CopyRect to Printer Canvas.

9. List the fonts for this printer

Delphi printing, Draw, StretchDraw, StretchDIBits, CopyRect, GetDeviceCaps, Pixels Per Inch, Aspect Ratio, Fonts, Scanline, HSVtoRGB, TextOut, Rect, sorting using TStringList, Transparency
A-4
Printer Demo #2
This Demo shows how to write a routine, DisplayGraphics, that displays various graphics pen/brush styles, and how to draw lines, ellipses, chords, "pies" and text on a Canvas. Use this routine with any canvas. The example shows how to write on the TForm, TImage,TBitmap, and Printer canvases. Output on the Printer canvas is in either Landscape or Portrait orientation. Results of Pen/Brush styles differ on various printers. Note that the TForm Canvas is not preserved when it is "damaged," i.e., it is not redrawn unless the OnPaint handler is used.

Two Windows regions are used to define a complex clipping region.

The various rectangles that are drawn on the screen show the 20 colors in Windows that do NOT dither (even on a 256-color display). In addition, shades of gray are shown, which differ on various printers.

Windows non-dither colors, Pen.Style, Pen.Width, Brush.Style, Canvas.MoveTo, Canvas.LineTo, Canvas.Rectangle, Canvas.Ellipse, Canvas.Chord, Canvas.Pie, Canvas.TextOut, MulDiv, Device-independent graphics, CreateRectRgn, CreateEllipticRgn, CombineRgn, SelectClipRgn, DeleteObject
A-5
ShellDemo
SHPrinters.ZIP
Delphi 3 version of most of the code from Microsoft's Knowledge Base Article Q153751, "Sample: PRINTERS.EXE: Using Printers with Windows 95 Shell." This Knowledge Base article "demonstrates how to programmatically manipulate printer items in the Windows 95 shell."

Microsoft's pidl is a pItemIDList here. Borland's name is much more mnemonic than Microsoft for those of us that don't use pidls every day.

Translated routines include: ExecuteAddPrinter, GetAddPrinterItem, GetItemIDName, GetPrinterItemIDList, GetThisPrinter, ItemIDListCreate, ItemIDListGetNextItem, ItemIDListGetSize, ItemIDListsConcatenate, OpenPrinterProperties, OpenThisPrinter.

The demo program focuses on these routines:
OpenThisPrinter: Show Printer Queue Screen
OpenPrinterProperties: Show Printer Properties Screen
ExecuteAddPrinter: Show Add Printer Wizard Screen

Comments in the Delphi code tell you where to find the equivalent function in the Microsoft C code.

Delphi Informant's The Secret World of PIDLs -- Working with Windows' Shell Item Identifiers, Dec 1999

pidl (pItemIDList in ShlObj), IShellFolder, IEnumIDList, EnumObjects, ShellAPI, IMalloc, TShellExecuteInfo, ShellExecuteEx, SHGetDesktopFolder, SHGetMalloc, SHGetSpecialFolderLocation, ZeroMemory

Also see:  efg's Delphi Printing Info and Links page


B. C Utility

Program Description Keywords
B-1
Prt

Prt.ZIP
(Borland C++ 5.02 Source and EXE)

Print Utility. Command-line utility to print ASCII files with headers and footers only on HP LaserJet printers with PCL. Uses Unix-like command-line file expansion when compiled with "WildArgs" (see the .mak file). Uses legible.h header file to use Delphi/Pascal-like style in C++. LaserJet.U unit packages much of the HP PCL for use by other programs. Shows how to use Delphi/Pascal-like units (.U files) in C++! (Basically, a .U combines a .H and a .C). Prt has been compiled using Borland, QNX and Sun C++ compilers. WILDARGS.OBJ, sys/stat.h, legible.h, C/C++ "units", HP LaserJet, PCL

Links Verified 19 Nov 2001
Updated 18 Feb 2002


since 1 Nov 1998