adapt old code to use print command

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

jparada
Posts: 433
Joined: Fri Jan 23, 2009 5:18 pm

adapt old code to use print command

Post by jparada »

Hi,

I'm trying to adapt the code below to use Print command, but I'll take two attempts without success.

Code: Select all

Parameters cArchivo

Local nArch, nNvo, cLinea, i, cCar, cSist
cSist := 'Sistema'

BEGIN SEQUENCE

   nArch := FOpen( cArchivo, FO_READWRITE )
   If FError() # 0
      ? "Error:"+LTrim(Str(FError()))+". Al tratar de abrir el archivo...<Enter>"
      Break
   Endif

   BEGIN SEQUENCE
      cLinea := ""
      nPag   := 1

      Set Device To Printer
      Set Print On

      Do While .T.

         cCar   := FReadStr( nArch, 1 )
         cLinea += cCar

         If cCar == ""        // Fin de archivo
            Exit
         Endif

         If cCar == CHR(10)    // Fin de la linea
            If PRow() >= 60
               ? ''
               ? Repl( '-', 80 )
               ? PadL( 'Pag. '+Str( nPag++), 78)
               Eject

               ? cSist + Space(50)+ 'Manual del usuario'
               ? Repl( '-', 80 )
               ? ''
            Endif

            ? Left(cLinea, Len(cLinea)-1 )
            cLinea := ""
         Endif
      Enddo

      Set Print Off
      Set Printer To

   END SEQUENCE

   FClose( nArch )

END SEQUENCE

Return
Any help is welcome.

Best Regards,
Javier
User avatar
mol
Posts: 3825
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: adapt old code to use print command

Post by mol »

jparada wrote:Hi,

I'm trying to adapt the code below to use Print command, but I'll take two attempts without success.

Code: Select all

Parameters cArchivo

Local nArch, nNvo, cLinea, i, cCar, cSist
cSist := 'Sistema'

BEGIN SEQUENCE

   nArch := FOpen( cArchivo, FO_READWRITE )
   If FError() # 0
      ? "Error:"+LTrim(Str(FError()))+". Al tratar de abrir el archivo...<Enter>"
      Break
   Endif

   BEGIN SEQUENCE
      cLinea := ""
      nPag   := 1

      Set Device To Printer
      Set Print On

      Do While .T.

         cCar   := FReadStr( nArch, 1 )
         cLinea += cCar

         If cCar == ""        // Fin de archivo
            Exit
         Endif

         If cCar == CHR(10)    // Fin de la linea
            If PRow() >= 60
               ? ''
               ? Repl( '-', 80 )
               ? PadL( 'Pag. '+Str( nPag++), 78)
               Eject

               ? cSist + Space(50)+ 'Manual del usuario'
               ? Repl( '-', 80 )
               ? ''
            Endif

            ? Left(cLinea, Len(cLinea)-1 )
            cLinea := ""
         Endif
      Enddo

      Set Print Off
      Set Printer To

   END SEQUENCE

   FClose( nArch )

END SEQUENCE

Return
Any help is welcome.

Best Regards,
Javier
Hi Javier!
try to do something like that:

Code: Select all

set printer to tempfile.prn
***
*** put your code here...
***

*** after all is printed:
set printer to

FilePrint('tempfile.prn', 'this could be the name of your printjob appearing in priter task folder')

*----------------------
function FilePrint
	param cFileName, cPrintJobTitle
	local cPrinter := WIN_PRINTERGETDEFAULT()
	local tmp
	
	
	if type("cPrintJobTitle") <> "C"
		cPrintJobTitle := "Printout from Javier program"
	endif
	WIN_PRINTFILERAW( cPrinter, cFileName, cPrintJobTitle )
	
return .f.

jparada
Posts: 433
Joined: Fri Jan 23, 2009 5:18 pm

Re: adapt old code to use print command

Post by jparada »

Hi Marek,

Thanks for answering,

I already try something similar and I did not get good results, what I need is to print many (probably hundreds) of xml files and what I want is to automate this process.

But with the code below, I have problems because not print correctly, that's why I wanted to try the print command of hmg.

Code: Select all

Local aPrn := WIN_PRINTERLIST()
Local GetList := {}
SetMode(25,80)
CLS

If Empty( aPrn )
      Alert("No hay impresoras instaladas - No es posible continuar...")
      Quit
Endif

@ 2, 0 TO 15, 55
nPrn := AChoice( 3, 1, 14, 54, aPrn, .T.,, nPrn )
If nPrn != 0
      aEval( Directory( hb_dirbase() + hb_ps() + "*.xml"), {|aFile| PrnTest( aPrn[ nPrn ], aFile[F_NAME] ) } )
Endif
Return

Procedure PrnTest( cPrinter, cFileName )
   WIN_PRINTFILERAW( cPrinter, cFileName, hb_ansitooem("Impresión en formato RAW archivo: " + Alltrim( cFileName) ) )
Return
Some extra help?

Best Regards,
Javier
User avatar
Rathinagiri
Posts: 5482
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: adapt old code to use print command

Post by Rathinagiri »

Hi Javier,

First of all, you want to print in text mode or graphics mode?

If you want to print in graphics mode, then HMG print commands will be useful.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
mol
Posts: 3825
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: adapt old code to use print command

Post by mol »

I don't know if I can understand your problem...

WIN_PRINTFILERAW function puts file exactly as it is into printer queue.
There is no parsing of your .xml file at all.

It will work when your printer is not only windows printer. It's very frequent the printer has no preprocessor for text. In this case you should use HMG commands for printout.
You can adapt my MOLDRUK.exe for printing text files on your windows printer.
you can find sources here:
http://www.molsystemy.pl/hmg/moldruk.prg
jparada
Posts: 433
Joined: Fri Jan 23, 2009 5:18 pm

Re: adapt old code to use print command

Post by jparada »

Hi Marek,

Thanks for answering.

Oh I see, then probably I have problems because I am trying to print to only windows printers.

Let me take a look at your program, and you have some help on what I should modify your program and how I should use?.

Any help is welcome.

Thanks.

Best Regards,
Javier
User avatar
mol
Posts: 3825
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: adapt old code to use print command

Post by mol »

I've prepared some national and graphical characters conversion (from CP 852 to Win 1250) in my program to correctly print frames from older programs.

But, if you don't need it, you can cut it off from procedure.
Program also interprets few commands to switch between 5 cpi, 10 cpi, 12 cpi, 17 cpi and 20 cpi, bold and italic.

I can prepare "light" version for you, please write your suggestions.
Marek
jparada
Posts: 433
Joined: Fri Jan 23, 2009 5:18 pm

Re: adapt old code to use print command

Post by jparada »

Hi Marek,

Thanks for answering.

Without even looking at the code, I did a little test trying to print an xml file, and I could print, I mean, your program worked well, sending the printer the contents of the xml file, I have only one problem, but I think has nothing to do with your program, the contents of the xml file is truncated, I did a test trying to print the same xml file with Internet Explorer and happens the same problem.

Any ideas what I can do for the xml file contents can be fully printed correctly on a sheet of letter size paper. (I mean to do with your program not to IE)

You think dealing with different fonts and sizes?.

I appreciate any help, and hope I'm not giving much trouble.

Thanks.

Best Regards,
Javier
User avatar
mol
Posts: 3825
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: adapt old code to use print command

Post by mol »

Send me a sample xml file. I'll watch it.
Marek
jparada
Posts: 433
Joined: Fri Jan 23, 2009 5:18 pm

Re: adapt old code to use print command

Post by jparada »

Hi Marek,

Thanks for answering.

Where I can send the xml file, maybe a private email, and if you agree, we can continue privately.

Thanks.

Best Regards,
Javier
Post Reply