cancel
Showing results for 
Search instead for 
Did you mean: 

PB 12.5 Classic: Send EPL to printer

Former Member
0 Kudos

Hi,

we have an EPL output file and need to redirect it to a label printer. How can it be implemented? Over PrintJob or WindowsApi? I 've some test but nothing works yet.

1 Try:

PrintSetPrinter("LABEL_PRINTER")

ulong li_job

li_job = PrintOpen("LABEL_NAME")

print(li_job, "~r~n")

print(li_job,"N~r~n")

print(li_job,"A50,100,0,3,1,1,N"+"Example 3"+ "~r~n")

PrintClose(li_job)

2 Try:

External Functions:

function integer OpenPrinter ( string pPrinterName, ref ulong phPrinter, printer_defaults pDefault ) Library "winspool.drv" ALIAS FOR "OpenPrinter;Ansi"

function integer ClosePrinter ( ulong phPrinter ) Library "winspool.drv"

Function integer EndDocPrinter (Long hPrinter) library "winspool.drv"

Function integer EndPagePrinter (Long hPrinter) library "winspool.drv"

Function integer StartDocPrinter (Long hPtinter, Long Level, DocInfo pDocInfo) library "winspool.drv" ALIAS FOR "StartDocPrinter;Ansi"

Function integer StartPagePrinter (Long hPrinter) library "winspool.drv"

Function integer WritePrinter (Long hPrinter, String pBuf, Long cdBuf, ref Long pcWritten) library "winspool.drv"

$PBExportHeader$docinfo.srs

global type docinfo from structure

  integer cbsize

  string lpszdocname

  string lpszoutput

  string lpszdatatype

end type

$PBExportHeader$printer_defaults.srs

global type printer_defaults from structure

  long pDataType

    long pDevMode

    long DesiredAccess

end type

String ls_text, ls_printer

long ll_null, ll_pos

ulong ll_printer

Boolean ll_bol

integer ll_ret,l_doc

docinfo mydocinfo

setnull(ll_null)

printer_defaults pd

pd.desiredaccess = 4

ls_printer="\\PSVM7.HVEA.HEALTHNET.LU\PR890-64"

ll_ret = OpenPrinter(ls_printer,ll_printer,pd)

if ll_ret = 0 then

messagebox("","Error")

else

mydocinfo.lpszdocname="label"

setnull(ls_text)

mydocinfo.lpszoutput=ls_text

mydocinfo.lpszdatatype=ls_text

l_doc=StartDocPrinter(ll_printer,1,Mydocinfo)

StartPagePrinter(ll_printer)

ls_text=""

ls_text= ls_text+ "q3000~r~n"

ls_text= ls_text+ "N~r~n"

ls_text= ls_text+ "A220,5,0,2,1,2,R,XXXXXX~r~n"

ls_text= ls_text+ "A200,43,0,2,1,1,N,XXXX~r~n"

ls_text= ls_text+ "P1~r~n"

ll_ret=WritePrinter(ll_printer,ls_text,len(ls_text),ll_null)

ll_ret=EndPagePrinter(ll_printer)

ll_ret=EndDocPrinter(ll_printer)

ll_ret = ClosePrinter(ll_printer)

end if

Some ideas?

regards

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

You can use the OpenPrinter function (and it's friends) with no problems, on any print driver.

Suggestions:

- change OpenPrinter declaration to accept LONG for parameter 3, send it a Zero when you call it (it can accept NULL and not need the structure at all)

- remove cbsize from the docinfo structure, it doesn't belong there

- change lpszoutput in docinfo to a long, set it to zero (it's easier than setting a null)

- set lpszdatatype to "RAW"

Define the WritePrinter functions like this:

Function Long WritePrinter(Long Handle, Ref Byte pData[], Long pDataLen, Ref Long BytesWritten) Library "winspool.drv" Alias For "WritePrinter;ansi"

Function Long WritePrinter(Long Handle, Ref Char pData[], Long pDataLen, Ref Long BytesWritten) Library "winspool.drv" Alias For "WritePrinter;ansi"

Function Long WritePrinterS(Long Handle, Ref String pData, Long pDataLen, Ref Long BytesWritten) Library "winspool.drv" Alias For "WritePrinter;ansi"

Use Character arrays when you need to write binary to the printer, and need to compute/plug in values that may end up as binary zero. If you need to read/print a file that has binary in it, read it into a blob, and call WritePrinter with it.

We've been using direct printing like this in one of our applications for about 20 years, and it works fine.

Hope this helps.

Answers (5)

Answers (5)

Former Member
0 Kudos

Thanks Brad your suggestion helps, here the integration and declaration:

Declarations;


$PBExportHeader$docinfo.srs

global type docinfo from structure

  string lpszdocname

  long lpszoutput

  string lpszdatatype

end type

Local External Functions:


function integer OpenPrinter ( string pPrinterName, ref ulong phPrinter, long pDefault ) Library "winspool.drv" alias for "OpenPrinterW"

function integer ClosePrinter ( ulong phPrinter ) Library "winspool.drv"

Function integer EndDocPrinter (Long hPrinter) library "winspool.drv"

Function integer EndPagePrinter (Long hPrinter) library "winspool.drv"

Function integer StartDocPrinter (Long hPtinter, Long Level, DocInfo pDocInfo) library "winspool.drv" alias for "StartDocPrinterW"

Function integer StartPagePrinter (Long hPrinter) library "winspool.drv"

Function Long WritePrinter(Long Handle, Ref Byte pData[], Long pDataLen, Ref Long BytesWritten) Library "winspool.drv" Alias For "WritePrinter;ansi"

Function Long WritePrinter(Long Handle, Ref Char pData[], Long pDataLen, Ref Long BytesWritten) Library "winspool.drv" Alias For "WritePrinter;ansi"

Function Long WritePrinterS(Long Handle, Ref String pData, Long pDataLen, Ref Long BytesWritten) Library "winspool.drv" Alias For "WritePrinter;ansi"

Script Print Text:


String  ls_printer , ls_texte, ls_Emp_Input, ls_null

long ll_null, ll_pos, ll_doc

ulong ll_printer

integer ll_ret

docinfo mydocinfo

setnull(ll_null)

//printer name

ls_printer="printer_name"

setnull(ls_null)

ll_ret = OpenPrinter(ls_printer,ll_printer,0)

if ll_ret = 0 then

  messagebox("","Error")

else

  mydocinfo.lpszdocname="Label"

  setnull(ls_null)

  mydocinfo.lpszoutput=0

  mydocinfo.lpszdatatype="Raw"   // or set value to ls_null

  ll_doc=StartDocPrinter(ll_printer,1,Mydocinfo)

  StartPagePrinter(ll_printer)

  ls_texte = "N~r~n"

  ls_texte +="q416~r~n"

  ls_texte +="Q240~r~n"

  ls_texte +="A16,4,0,3,1,1,N,~"41272535~"~r~n"

  ls_texte +="P1~r~n"

  ll_ret=WritePrinterS(ll_printer,ls_texte,len(ls_texte),ll_null)

  ll_ret=EndPagePrinter(ll_printer)

  ll_ret=EndDocPrinter(ll_printer)

  ll_ret = ClosePrinter(ll_printer)

end if

Script Print EPL File:



String  ls_printer , ls_Emp_Input, ls_null

long ll_null, ll_doc

ulong ll_printer

integer ll_ret

docinfo mydocinfo

setnull(ll_null)

blob lbl_data

blob lbl_temp

long ll_file

//reading file

lbl_data = blob("")

ll_file = fileopen("C:\EP.EPL",textmode!)

DO WHILE FileReadex(ll_file,lbl_temp) > 0

  lbl_data += lbl_temp

LOOP

ls_Emp_Input = string(lbl_data,EncodingANSI!)

FileClose(ll_file)

//printer name

ls_printer="printer_name"

setnull(ls_null)

ll_ret = OpenPrinter(ls_printer,ll_printer,0)

if ll_ret = 0 then

  messagebox("","Error")

else

  mydocinfo.lpszdocname="Label"

  setnull(ls_null)

  mydocinfo.lpszoutput=0

  mydocinfo.lpszdatatype="Raw"   // or set value to ls_null

  ll_doc=StartDocPrinter(ll_printer,1,Mydocinfo)

  StartPagePrinter(ll_printer)

  ll_ret=WritePrinterS(ll_printer,ls_Emp_Input,len(ls_Emp_Input),ll_null)

  ll_ret=EndPagePrinter(ll_printer)

  ll_ret=EndDocPrinter(ll_printer)

  ll_ret = ClosePrinter(ll_printer)

end if

Former Member
0 Kudos

Depending on the Barcode printer driver you'll need to look at using the Generic Text Driver in windows.   

arnd_schmidt
Active Contributor
0 Kudos

First I would check if the printer is ready to accept Unicode.

If it needs ANSI you have to send blobs to the printer. WritePrinter() accepts these byte arrays.

To convert an Unicode string to an ANSI blob use the blob ( ls_string, EncodingANSI!) function.

hth

Arnd


Former Member
0 Kudos

Hi Marko;

  Hopefully, this thread might be of some help ... http://nntp-archive.sybase.com/nntp-archive/action/article/%3C4d776f69$1@forums-1-dub%3E

HTH

Regards ... Chris

Former Member
0 Kudos

I have not used them but based on a quick search, you need to copy the file to the printer. Here is a link that talks about the difference between local and networked printers.

https://www.experts-exchange.com/questions/28124336/copy-epl-file-to-shared-eltron-printer.html