En el siguiente ejemplo se imprimen cuatro documentos.
Al seleccionar la impresora (distinta de la predeterminada de windows) antes de empezar con el bucle de impresi贸n de los cuatro documentos se obtiene como resultado que el primero se imprime en la impresora seleccionada y el resto en la predeterminada de windows:
#include 'inkey.ch'
#include 'set.ch'
#include 'report.ch'
#include 'fivewin.ch'
#include 'rddsys.ch'
#include "common.ch"
#include "DLL.ch"
#include 'ord.ch' //Para CDX
#include 'Image.ch'
#include "fileio.ch"
external dbfcdx, ordkeyno, ordkeycount, ordkeygoto //Para CDX
REQUEST HB_Lang_ES
REQUEST HB_CODEPAGE_ESWIN //Comentar en xHarbour
static oWnd
function main()
HB_Langselect("ES")
HB_SetCodePage("ESWIN")
setHandleCount(50)
set 3DLOOK ON
DEFINE FONT oFont NAME "MS Sans Serif" SIZE 0,-14 //BOLD //SIZE 8,16
DEFINE FONT oFontDoble NAME "MS Sans Serif" SIZE 0,-16
public nSizeCond:= 8
public nSizeNorm:=10
rddsetdefault('DBFCDX')
set AUTOSHARE TO 1 //CDX Modo Multiusuario.
DEFINE BRUSH oBru COLOR rgb(0,0,135) //Fondo de color
DEFINE WINDOW oWnd TITLE 'GESTION DE ESTACIONES' BRUSH oBru MENU MenuPpal()
set MESSAGE OF oWnd TO 'Prueba'+CurDir() CLOCK DATE KEYBOARD
ACTIVATE WINDOW oWnd MAXIMIZED ON INIT ( oWnd:setfont(oFont) )
return NIL
static function MenuPpal()
local oMenu
MENU oMenu
MENUITEM '&PruebaPRN' ACTION imprimelotedocs()
MENUITEM '&SALIR' ACTION oWnd:end()
ENDMENU
return oMenu
function imprimelotedocs()
local nDocs:=4, i:=0
if PrinterSetup() <> 0
for i=1 TO 4
FImprime_Test(i, .F.)
next i
endif
return nil
/** Funcion para imprimir FACTURAS de CONTADO a clientes.
** Devuelve el nombre de la factura impresa por si se usa para PDF.
**/
function FImprime_Test(nNumeroDoc, lPrever)
local nl:=0 // numero de linea que se est谩聽 imprimiendo.
local texto:=Space(62) // texto de la l铆nea a imprimir.
local oPrn, oFont1, oFont2, oFontCond
local nsl, nColStep
local fontsize:=-10
local mrgiz:=2, mrgsu:=2 // En cent铆metros.
local oPen1, oPen2
local salir:=.f.
nsl := 4 * (-1)*fontsize / 100 // Alto en cm para el salto de linea
if lPrever = .f. .or. lPrever=NIL
PRINT oPrn NAME "PruebaPRN"+alltrim(str(nNumeroDoc))
else
PRINT oPrn NAME "PruebaPRN"+alltrim(str(nNumeroDoc)) PREVIEW
endif
DEFINE FONT oFont1 NAME "COURIER NEW" SIZE 0, fontsize OF oPrn
DEFINE FONT oFont2 NAME "COURIER NEW" SIZE 0, fontsize BOLD OF oPrn
DEFINE FONT oFontCond NAME "COURIER NEW" SIZE 0, 8 OF oPrn
DEFINE PEN oPen1 width 1
DEFINE PEN oPen2 width 2
if empty( oPrn:hDC )
msgstop( "No hay impresora preparada" )
salir=.t.
endif
msgwait("IMPRIMIENDO Doc.: PruebaPRN"+alltrim(str(nNumeroDoc)),,1)
PAGE
nl=mrgsu + 3*nsl
// Datos del emisor
oPrn:CmSay(nl,mrgiz, "Campo 1",oFont2)
oPrn:CmSay(nl+1*nsl,mrgiz,"Campo 2",oFont1)
oPrn:CmSay(nl+2*nsl,mrgiz,"Campo 3",oFont1)
nl=nl+7*nsl
oPrn:line(nl,mrgiz,nl,19,oPen2)
nl=nl+1*nsl
texto='PRUEBA DE TEXTO'
oPrn:CmSay(nl,mrgiz,texto,oFont1)
oPrn:CmSay(nl,15,'FECHA: '+dtoc(date()),oFont1)
nl=nl+1*nsl
ENDPAGE //EJECT
ENDPRINT // Apaga la impresora
//oFont1:end()
//oFont2:end()
//oFontCond:end()
oPen1:end()
oPen2:end()
return "PruebaPRN"+alltrim(str(nNumeroDoc))