Detect Type of Printer whether DOT Matrix or Inkjet/Laser

Detect Type of Printer whether DOT Matrix or Inkjet/Laser

Postby anserkk » Tue Oct 28, 2008 4:51 am

Hi All,

Is there a way I could determine if a printer is DOT Matrix (Text) or Laser/InkJet (Graphics) when a user select a printer especially from the print preview


My Intention :-

I want my users to select any printer while generating reports. If the user selects a DOT Matrix printer then I'll use TDosPrn.Prg to have a fast DOS mode printing to the LPT Port (without any graphics), If my users select an inkjet or laser printer then they get print out in graphics mode (much more neat with lines and grids etc). So the program behave little bit intelligently.

But for the above to happen, I should be able to identify the user selected printer is a DOT matrix or Inkjet/Laser


Regards

Anser
Last edited by anserkk on Tue Oct 28, 2008 12:45 pm, edited 2 times in total.
User avatar
anserkk
 
Posts: 1329
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Postby anserkk » Tue Oct 28, 2008 11:40 am

Solution for my above post but it is in Delphi. Can anybody help me to convert the same to FWH

Delphi code to determine if a printer is a Dot-Matrix or Laser (or InkJet) ?


Code: Select all  Expand view
{$APPTYPE CONSOLE}
uses Windows, Printers, WinSpool, Variants;
{
Using only API calls, determinate which type is the active printer:
Dot-Matrix or Laser (or InkJet)

}

function IsPrinterMatrix: Boolean;
var
  DeviceMode: THandle;
  Device, Driver, Port: array [0..79] of Char;
  pDevice, pDriver, pPort: PChar;
begin

  // Determinate that active printer is a Dot-Marix
  Result:= False;
  pDevice := @Device;
  pDriver := @Driver;
  pPort   := @Port;

  Device  := #0;
  Driver  := #0;
  Port    := #0;

  Printer.GetPrinter(pDevice, pDriver, pPort, DeviceMode);

  // Printer can be dot-matrix when number of colors is maximum 16
  // and when printer is capable to print only for TRUETYPE
  // fonts as graphics (dot-matrix and PCL printers are capable for that).

  if (GetDeviceCaps(Printer.Handle,NUMCOLORS)<=16) and
     (DeviceCapabilities(pDevice, pPort,DC_TRUETYPE,nil,nil) = DCTT_BITMAP)
  then
    Result := True;
end;

begin
  writeln ('Active printer is ', Printer.Printers[Printer.PrinterIndex]);

  if IsPrinterMatrix then
    writeln('This is a Dot-Matrix printer')
  else
    writeln('This is a LaserJet or InkJet printer');
end.


Regards

Anser
User avatar
anserkk
 
Posts: 1329
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Postby marca » Tue Oct 28, 2008 3:56 pm

Uma maneira de vc pegar isso como um paleativo é assim
IF(oPrn:nLogPixelX() <= 350,"JATO/LSER","MATRICIAL") // 1 é igual a JATO OU LASER e 2 matricial e 3 Arquivo
Marcelo Ferro da Silveira
Fwh14.04/xHarbour 1.2.3 Simplex / Bcc582 / Pelles 8
SqlLib /xMate/WS
marca
 
Posts: 116
Joined: Mon Aug 13, 2007 5:22 pm
Location: Brazil

Postby anserkk » Wed Oct 29, 2008 6:33 am

Thank you Mr.Marcelo Ferro

If oPrn:nLogPixelX() <= 350 then it is a Dot Matrix printer

Code: Select all  Expand view
   IF oPrn:nLogPixelX() <= 350
      MsgInfo("Dot Matrix  nLogPixel is "+str(oPrn:nLogPixelX()))
   else
      MsgInfo("InkJet/Laser nLogPixel is "+str(oPrn:nLogPixelX()))
   Endif


I checked the above code with different types of printers (Inkjet, Laser and Dot matrix) and I am getting the correct results to identify whether the selected printer is Dot Matrix or InkJet/Laser, eventhough there are differences in the pixels from one dot matrix to another dot matrix printer

Regards

------------------------------------------------------------------------------------

Obrigado Mr.Marcelo Ferro

Se oPrn: nLogPixelX () <= 350 então é uma impressora matricial

[code] IF oPrn: nLogPixelX () <= 350
MsgInfo ( "Dot Matrix nLogPixel é" + str (oPrn: nLogPixelX ()))
Diferente
MsgInfo ( "InkJet / Laser nLogPixel é" + str (oPrn: nLogPixelX ()))
Endif [/ code]

Eu chequei o código acima, com diferentes tipos de impressoras (Inkjet, Laser e Dot matriz) e estou obtendo os resultados corretos para identificar se a impressora está seleccionada Dot Matrix ou InkJet / Laser, apesar existem diferenças no pixels de uma matricial para outra impressora matricial

Atenciosamente

Anser
User avatar
anserkk
 
Posts: 1329
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Postby marca » Wed Oct 29, 2008 4:04 pm

Ola Anser

Esta maneira q. te passei é somente um paliativo pos também não conheço nenhuma função no xHarbour q. faça isso q. vc quer

mas ela ainda apresenta problemas como por exemplo

JATO DE TINTA
EPSON STYLUS C79 em modo economico oPrn:nLogPixelX () = 120
e isso ira te trazer problemas

pos uma matricial
MATRICIAL
EPSON LX 300 oPrn:nLogPixelX () = 240 X 144 maior q. a jato de tintas



Seria muito interessante se o xHarbour tivesse uma função q. nos desse mesta informação seria muito util
Marcelo Ferro da Silveira
Fwh14.04/xHarbour 1.2.3 Simplex / Bcc582 / Pelles 8
SqlLib /xMate/WS
marca
 
Posts: 116
Joined: Mon Aug 13, 2007 5:22 pm
Location: Brazil


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 87 guests