Ioannis Anifantakis
asked on
Select a printer and print text or file in Delphi
I can get a list of available printers in delphi through the
Printer.Printers.Text
and I can also select a printer by its index like
myPrinterName:=Printer.Pri nters[i] (where i is the index of my desired printer).
How can I textout some string or file to the desired printer in delphi?
Printer.Printers.Text
and I can also select a printer by its index like
myPrinterName:=Printer.Pri
How can I textout some string or file to the desired printer in delphi?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That seems to select different printers and draw the text on the canvas...
Just a hint...
if some of my printers are inkjet-laser and others are Dot-Matrix, then the textout is really bad when it gets to the dot-matrix one...
Is there any way arround this so I can print correctly on my desired printer either if its inkjet-laser or DotMatrix?
Just a hint...
if some of my printers are inkjet-laser and others are Dot-Matrix, then the textout is really bad when it gets to the dot-matrix one...
Is there any way arround this so I can print correctly on my desired printer either if its inkjet-laser or DotMatrix?
>>That seems to select different printers and draw the text on the canvas...
yup, that's how it works you can textout() or draw() onprinters canvas like on any other canvas
>>Is there any way arround this so I can print correctly on my desired printer either if its inkjet-laser or DotMatrix?
well it doesn't matter if it is laser, dot-matrix or termal printer it's all up to you what you draw on canvas and where you draw it.
for your "calculations" you can use:
printer.Canvas.TextHeight( 'Lj')
printer.Canvas.TextWidth(' W')
as well as
GetDeviceCaps(Printer.Hand le, ... )
ziolko.
yup, that's how it works you can textout() or draw() onprinters canvas like on any other canvas
>>Is there any way arround this so I can print correctly on my desired printer either if its inkjet-laser or DotMatrix?
well it doesn't matter if it is laser, dot-matrix or termal printer it's all up to you what you draw on canvas and where you draw it.
for your "calculations" you can use:
printer.Canvas.TextHeight(
printer.Canvas.TextWidth('
as well as
GetDeviceCaps(Printer.Hand
ziolko.
I used to use coordinates in milimeters to print text in specific position regardles of printer, it worked on different laser printers but never tried with dot-matrix.
basically i used:
res := GetDeviceCaps(printer.Hand le, PHYSICALWIDTH);
sze := GetDeviceCaps(printer.Hand le, HORZSIZE);
to calculate device units per millimeter (res / sze)
then
offX := GetDeviceCaps(printer.Hand le, PHYSICALOFFSETX)
to get edge of non-printable area, then when I wanted to print something 90 millimeters from lefte edge of page I calculated 90 millimeters to device units and substract offX
ziolko.
basically i used:
res := GetDeviceCaps(printer.Hand
sze := GetDeviceCaps(printer.Hand
to calculate device units per millimeter (res / sze)
then
offX := GetDeviceCaps(printer.Hand
to get edge of non-printable area, then when I wanted to print something 90 millimeters from lefte edge of page I calculated 90 millimeters to device units and substract offX
ziolko.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
procedure TForm1.Button1Click(Sender
begin
with Printer do
begin
PrinterIndex := your_printer_index;
BeginDoc;
Canvas.TextOut(200,200, 'hello world');
EndDoc;
end;
end;
ziolko.