utf-8 printing

moush

New Member
Hello all,
I need some help on printing data from a utf-8 codepage database. I am using:

Progress Version:10.2B04

Session startup parameters:

-pf C:\PROGRESS\OpenEdge102B\startup.pf,-cpinternal UTF-8,-cpstream UTF-8,-cpcoll Basic,-cpcase Basic,-d dmy,-numsep 44,-numdec 46,(end .pf),-basekey ini,-ininame progress.ini,-pf AutoBoss.pf,-d dmy,-yy 1929,-ems,-mmax 9000,-TB 20,-TM 20,-pls,-T c:\temp,-D 200,-cpinternal utf-8,-cpstream utf-8,-p .\dbconnect.p,(end .pf)

Windows Vista
Windows codepage: 1253
cpinternal: utf-8
cpstream: utf-8
cpprint: utf-8
cpcase: Basic
cpcoll: Basic
cplog: utf-8
cprcodein: ?
cprcodeout: ?
cpterm: utf-8


DATABASE
DBTYPE: PROGRESS
DBVERSION: 10
Parameters: -db .\DB\AutoBoss.db,-1
DBCODEPAGE: UTF-8
DBCOLLATION: BASIC


I am trying to print to a usb thermal printer and my data (Greek Letters) come out in strange characters.
I have managed to export my data in a text file using:

OUTPUT STREAM report TO myfile.txt paged PAGE-SIZE 0 CONVERT TARGET "utf-8".
PUT stream report CONTROL "~357~273~277". /* BOM for UTF-8 */


and my data are readable. If I output the stream to the printer though, all the data are messed up.

Any help will be much appreciated.
Thank you.
 

RealHeavyDude

Well-Known Member
I am just speculating that - if Windows is able to display the file correctly - then your printer has a problem with utf-8 characters or needs special control sequences. But that you can only find out from the printer manual.

Heavy Regards, RealHeavyDude.
 

RealHeavyDude

Well-Known Member
Ooops - forgot: What happens when you send the file to the printer via the windows print command? If you get the same mess than I would say that the problems does not originate from Progress.

Heavy Regards, RealHeavyDude.
 

moush

New Member
I have already checked this. When i open the output file in notepad and print it, it comes out all right. So there is nothing wrong with the printer.
 

moush

New Member
The command does not do anything. Even when I execute it directly from command prompt "COPY c:\ticket.txt TSP100". Any ideas?
 

trx

Member
TSP100 is not valid printer name - it is just file name, so when you do "COPY ..." then you only copy ticket.txt to tsp100 .
If you want to send it to printer then use copy c:\ticket.txt \\computer_name\printer_share_name (I am not sure whether you need to share this printer first or not).
If your printer cannot parse text files then you will have to print using printer driver (like notepad) and not by copying file directly to the printer.
 

moush

New Member
Yes, I needed to share the printer. The command does execute but the output is still messed up. Even when I execute the command directly from command prompt, the output is messed up. I am really and seriously confused!!! When I open the file in notepad, I can read it and print it ok!!! When I execute the os command is messed up!!!!! I am missing something, it does not make any sense.
 

Osborne

Active Member
I am not sure about this and wonder whether the printer name may need a bit more information like the port of full destination. Possible examples:

OS-COMMAND NO-WAIT "COPY c:\ticket.txt file://printserver/printer1".
OS-COMMAND NO-WAIT "COPY c:\ticket.txt LPT1.
OS-COMMAND NO-WAIT PRINT "c:\ticket.txt"
OS-COMMAND NO-WAIT COPY "c:\ticket.txt" > LPT1

If no joy with OS-COMMAND, does it work if you use ShellExecuteA?:

Code:
DEFINE VARIABLE viReturnCode AS INTEGER NO-UNDO.
DEFINE VARIABLE fileName AS CHARACTER NO-UNDO.

fileName = "c:\ticket.txt":U.
RUN ShellExecuteA(0,
                 "print":U,
                 fileName,
                 "":U,
                 "":U,
                 0,
                 OUTPUT viReturnCode).

PROCEDURE ShellExecuteA EXTERNAL "shell32.dll":U:
   /* Handle to parent window */       
   DEFINE INPUT PARAMETER plHWND       AS LONG      NO-UNDO.
   /* Operation to perform: open, print */
   DEFINE INPUT PARAMETER pcOperation  AS CHARACTER NO-UNDO.
   /* Document or executable name */
   DEFINE INPUT PARAMETER pcFile       AS CHARACTER NO-UNDO.
   /* Command line parameters to executable in File */
   DEFINE INPUT PARAMETER pcParameters AS CHARACTER NO-UNDO.
   /* Default directory */
   DEFINE INPUT PARAMETER pcDirectory  AS CHARACTER NO-UNDO.
   /* whether shown when opened:
      0 hidden, 1 normal, minimized 2, maximized 3,
      0 if File is a document */
   DEFINE INPUT PARAMETER plShowCmd    AS LONG      NO-UNDO.
   /* Return Code: less than or equal to 32 */
   DEFINE RETURN PARAMETER plInstance  AS LONG      NO-UNDO.
END.
 

moush

New Member
I have used the ShellExecuteA you have in your post without any results. It compiles, it runs but I do not have anything on the printer OR any error. Any ideas?
 

moush

New Member
Maybe it has something to do with shell32.dll that ShellExecuteA uses and my windows vista. What do you think?
 

Osborne

Active Member
Maybe it has something to do with shell32.dll that ShellExecuteA uses and my windows vista. What do you think?
I suppose that could be possible. Can you use ShellExecuteA to open the file?
Code:
RUN ShellExecuteA(0,
                 "[B][COLOR="#FF0000"]open[/COLOR][/B]":U,
                 fileName,
                 "":U,
                 "":U,
                 [B][COLOR="#FF0000"]1[/COLOR][/B],
                 OUTPUT viReturnCode).
If it opens okay then it suggests shell32.dll could to be okay and maybe it is purely down to the printer possibly requiring special commands.
 

Osborne

Active Member
Further thought, if shell32.dll is okay then maybe adding some printer information may help:
Code:
DEFINE VARIABLE viReturnCode AS INTEGER NO-UNDO.
DEFINE VARIABLE fileName AS CHARACTER NO-UNDO.
DEFINE VARIABLE vPrinter AS CHARACTER NO-UNDO.

fileName = "c:\ticket.txt":U.
vprinter = '"' + SESSION:PRINTER-NAME + '"'.

RUN ShellExecuteA(0,
                 "printto":U,
                 fileName,
                 vprinter,
                 "":U,
                 0,
                 OUTPUT viReturnCode).

PROCEDURE ShellExecuteA EXTERNAL "shell32.dll":U:
   /* Handle to parent window */       
   DEFINE INPUT PARAMETER plHWND       AS LONG      NO-UNDO.
   /* Operation to perform: open, print */
   DEFINE INPUT PARAMETER pcOperation  AS CHARACTER NO-UNDO.
   /* Document or executable name */
   DEFINE INPUT PARAMETER pcFile       AS CHARACTER NO-UNDO.
   /* Command line parameters to executable in File */
   DEFINE INPUT PARAMETER pcParameters AS CHARACTER NO-UNDO.
   /* Default directory */
   DEFINE INPUT PARAMETER pcDirectory  AS CHARACTER NO-UNDO.
   /* whether shown when opened:
      0 hidden, 1 normal, minimized 2, maximized 3,
      0 if File is a document */
   DEFINE INPUT PARAMETER plShowCmd    AS LONG      NO-UNDO.
   /* Return Code: less than or equal to 32 */
   DEFINE RETURN PARAMETER plInstance  AS LONG      NO-UNDO.
END.
 

moush

New Member
With open command instead of print, the file opens in notepad ok.
The changes you made in the coding have an error, vprinter:U need to be just vprinter, and it still does not produce anything on the printer. Compiles, runs but without and print out or any error.
If the problem is caused by the printer, shouldn't I have the same mess when printing the file from notepad? If i open it in notepad and print it, it is fine.
 

Osborne

Active Member
Ah yes, vprinter:U was an error and you are correct it should just be vprinter. With you being able to open the file then it would suggest shell32.dll is okay on your system. As trx pointed out, the mess when printing could be due to the printer being unable to parse text files and you have to print using a printer driver (like notepad). I cannot explain why trying to print with ShellExecuteA does not work and am at a loss as to what else to try.
 

Osborne

Active Member
Not knowledgeable on this apart from opening the file in an external application and printing from there. Hopefully someone else may know of a better way.
 

moush

New Member
Interesting enough, I have manage to print the file but with out any control (or at least I do not know a way to) on changing fonts to make the file more readable with headers and so on with the following:

DEFINE VARIABLE whand AS HANDLE NO-UNDO.
DEFINE VARIABLE file-to-print AS CHARACTER NO-UNDO INITIAL "c:\ticket.txt".
DEFINE VARIABLE p_FontNumber AS INTEGER NO-UNDO INITIAL 12.
DEFINE VARIABLE p_UseDialog AS INTEGER NO-UNDO INITIAL 0.
DEFINE VARIABLE p_PageSize AS INTEGER NO-UNDO INITIAL 20.
DEFINE VARIABLE p_PageCount AS INTEGER NO-UNDO INITIAL 0.
DEFINE VARIABLE p_Printed AS LOGICAL NO-UNDO.
DEFINE VARIABLE vPrinter AS CHARACTER NO-UNDO.

vprinter = '"' + SESSION:pRINTER-NAME + '"'.

ASSIGN whand = CURRENT-WINDOW.
RUN setKey ("Windows", "Device", "TSP100,WinSpool,Ne01:").

SESSION:pRINTER-CONTROL-HANDLE = 0.

RUN adecomm\_osprint.p (INPUT whand,
INPUT file-to-print,
INPUT p_FontNumber,
INPUT p_UseDialog,
INPUT p_PageSize,
INPUT p_PageCount,
OUTPUT p_Printed).

/*
IF p_Printed = TRUE THEN
MESSAGE "Print successful!" VIEW-AS ALERT-BOX.

ELSE
MESSAGE "Print failed." VIEW-AS ALERT-BOX.
*/

PROCEDURE SetKey:
DEFINE INPUT PARAMETER pSection AS CHAR NO-UNDO.
DEFINE INPUT PARAMETER pEntry AS CHAR NO-UNDO.
DEFINE INPUT PARAMETER pString AS CHAR NO-UNDO.
DEFINE VAR result AS INT NO-UNDO.
RUN WriteProfileStringA(pSection,pEntry,pString, OUTPUT result).
END PROCEDURE.

PROCEDURE WriteProfileStringA EXTERNAL "KERNEL32.DLL":
DEFINE INPUT PARAMETER lpszSection AS CHAR.
DEFINE INPUT PARAMETER lpszEntry AS CHAR.
/*DEFINE INPUT PARAMETER lpszString AS CHAR.*/
DEFINE INPUT PARAMETER pString AS CHAR NO-UNDO.
DEFINE RETURN PARAMETER result AS LONG.
END.




Still though, the whole thing does not make any sense to me!!! If anyone has a better knowledge on this, I would really like to understand why this is happening and how it is working with the above code.
 
Top