1. Anton van der Post
  2. PowerBuilder
  3. Tuesday, 6 February 2018 21:18 PM UTC

In PB9 -  printsend was used to send ( 4"X6" ) label specific printer codes describing the label layout to our label printers.

Label software LOFTWARE - Compiled files Labelname.dwn contains the layout definition ( template binary codes ) of the label and Labelname.dat contains the detail of the label ( binary code followed by fieldname/position on label ).

Since PRINTSEND is no longer supported in PB2017 - any ideas how to accomplish the same result - sending binary codes and data to a printjob ?

Thank you

Anton

 

In sample code below is shown the PRINTSEND function - dumping the the label template to the printer.

 ls_HeaderFile = ls_labelsdirectory + "LABELS\" + TRIM(lsLabelFile) +".DWN"
 
 IF ls_HeaderFile <> "" THEN
  IF FileExists(ls_HeaderFile) THEN
   // On Disk
   long ll_HeaderFileHandle, ll_HeaderFileSize, ll_HeaderLoopControl, ll_HeaderLineRead
   string ls_Line = ""
   ll_HeaderFileSize = FileLength(ls_HeaderFile)
   ll_HeaderFileHandle = FileOpen(ls_HeaderFile)
   ll_HeaderLoopControl = 0
   IF ll_HeaderFileHandle > 0 THEN
    // Read the file one line at a time and print it out...
    DO WHILE ll_HeaderLoopControl < ll_HeaderFileSize
     ll_HeaderLineRead = FileRead(ll_HeaderFileHandle,ls_Line)
     IF ll_HeaderLineRead > 0 THEN
      ll_HeaderLoopControl = ll_HeaderLoopControl + ll_HeaderLineRead
      PrintSend(ll_PrintJob,ls_Line)
     ELSE
      IF ll_HeaderLineRead <> -100 THEN
       gnv_app.inv_error.of_Message("File read error on the header file '" + ls_HeaderFile + "'")
       lb_Return = FALSE
       EXIT
      ELSE
       EXIT
      END IF
     END IF
    LOOP
   END IF
   FileClose(ll_HeaderFileHandle)
  ELSE
   gnv_app.inv_error.of_Message("Cannot find the header file '" + ls_HeaderFile + "'")
   lb_Return = FALSE  // specified file does not exist.
  END IF
 END IF

// Routine processing the ls_DetailFile - Labelname.dat

etc.

 

 

 

 

 

 

 

 

Govinda Lopez @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 7 February 2018 01:08 AM UTC
  2. PowerBuilder
  3. # 1

Hi Anton,

 

PrintSend is an obsolete function and is provided for backward compatibility only. The ability to use this function is dependent upon the printer driver. So, if you have the latest version, you might want to try it out. If the driver is still the same, there is a chance this might still work for you.

 

Regards,

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 7 February 2018 04:37 AM UTC
  2. PowerBuilder
  3. # 2

Hi Anton;

  Try this alternative.

HTH

Regards ... Chris

Comment
  1. Brad Mettee
  2. Wednesday, 7 February 2018 14:17 PM UTC
Chris,



PrintText will put the text on the page through the normal printer driver. It basically is the same as a datawindow object the produces text. The text will be rendered on the DeviceContext owned by the printer driver (it's GUI, not direct to printer). It can't be used to send codes to the printer (unless the PB2017 help is drastically wrong). I printed the sample you point to by redirecting print output to file (full print stream), and none of the text was sent to the printer as written (including some escape codes I put in). I also tried the example when using the Generic/Text printer driver. Although the output does get sent as written, spaces and CR/LF also get put into the print stream, so there's no guarantee that a NUL (or non-ascii chars) will be sent properly.



See my answer post for solution we've been using for many years.



p.s. Example uses the variable X without declaring it, so the test button moved after being clicked :)

  1. Helpful
There are no comments made yet.
Brad Mettee Accepted Answer Pending Moderation
  1. Wednesday, 7 February 2018 14:47 PM UTC
  2. PowerBuilder
  3. # 3

Using the the following external functions (WinAPI), you can open the printer (as defined by Windows) in a raw data mode, and just send your data directly to it instead of using the old style DOS copy command. (this will only work if Windows knows about the printer and has it defined in the printer list)

External Function Declarations (these are directly from a UO we currently use to print raw data to a dot matrix printer)
Function Long OpenPrinter(String PrinterName, Ref Long Handle, Long Defaults) library "winspool.drv" alias for "OpenPrinterW"
Function Long ClosePrinter(Long Handle) 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"
Function Long StartPagePrinter(Long Handle) Library "winspool.drv"
Function Long EndPagePrinter(Long Handle) Library "winspool.drv"
Function Long EndDocPrinter(Long Handle) Library "Winspool.drv"
Function Long AbortPrinter(Long Handle) Library "Winspool.drv"
Function Long GetLastError() Library "Kernel32.dll"
Function Long StartDocPrinter(Long Handle, Long Level, Ref DocInfo DI) Library "Winspool.drv" alias for "StartDocPrinterW"

For the return values - 0 is failure, anything else is success.

stru_DocInfo structure, local to UO
String DocName
Long OutputFile
String DataType

Sample process. This is just basic concept code, it won't compile like this.

long ll_rtn, ll_handle
stru_DocInfo lstru_docinfo
ll_rtn = OpenPrinter(dw.object.datawindow.printer, ll_handle, 0)  // dw is any datawindow that's currently using the correct printer
lstru_docinfo.DocName = "Raw Document"
lstru_docinfo.OutputFile = 0
lstru_docinfo.DataType = "RAW"

StartDocPrinter(ll_handle, 1, lstru_docinfo)

StartPagePrinter(ll_handle)
string pData
pData = "Any length of data you want to write to the printer"
long StringLen
Long BytesWritten
StringLen = len(pdata)
​WritePrinter(ll_handle, pData, stringlen, byteswritten)
if byteswritten <> stringlen then "something went wrong"
EndPagePrinter(ll_handle)
EndDocPrinter(ll_handle)

As soon as you "enddoc" your print job will be released and should start printing.

If you're planning on printing multiple "pages" then you'll need to do a startpage/endpage for each one.

We're currently using all three WritePrinter methods, and they works well. You should also be able to open a file in stream mode, ReadFileEx into a blob, and use WritePrinter with the blob (this would require a new external declaration for blob data).

The "ansi" declaration WritePrinter functions is important. Without it, characters will be converted to unicode and corrupt the data stream. You need RAW, untranslated data, for this to work properly.

Hope this helps.

Brad

 

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.