FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Printing a pre-formated letter
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Printing a pre-formated letter
Posted: Wed Feb 18, 2009 11:43 PM
To All

I have text stored in VarChar(max) SQL Server field and I have no problem importing and exporting the text in Notepad.

I want to be able to print the text and have it come out the way it is formatted in the field .. when I look at the data like this :

Code (fw): Select all Collapse
cTEXT := oRsLett:Fields("letter_text"):Value
MsgInfo( cTEXT )


MsgInfo displays the text correctly formatted perfectically .. just as it was inserted into the SQL table .. however, I am trying to print this USING

Code (fw): Select all Collapse
oPRINT:StartPage()

cDEFA := SET(7)
IF FILE( cDEFA+"\AGENCY.BMP" )
   oPRINT:SayBitMap( 10,500, cDEFA+"\AGENCY.BMP", 900,700 )    //800,500
ENDIF

oPrint:Say ( 1000, 100, cTEXT , oFONT )

oPRINT:EndPage()


and all I get is the first line that runs off the page .. surely there must be a way to print formatted text easily at certain co-ordanents on a page ??

Thanks
Rick Lipkin
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Printing a pre-formated letter
Posted: Thu Feb 19, 2009 07:59 AM

Try oPrint:CmSay() method.

EMG

Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Printing a pre-formated letter
Posted: Thu Feb 19, 2009 02:13 PM
Enrico

I tried your suggestion with the same result .. I had some old code from extracting letters from a .fpt memo field and I thought I would give it a shot and it worked .. here is the code .. a bit crude, but it works :

Code (fw): Select all Collapse
cTEXT := oRsLett:Fields("letter_text"):Value
oRsLett:Close()

oPRINT:lPrvModal := .T.

DEFINE FONT oFont NAME "Courier New" SIZE 0,-10 BOLD of oPRINT  // SIZE 10 -40

nLINES := 68

nRowStep := oPrint:nVertRes() / nLINES  // pixel per line = 57.65 @ 55
nColStep := oPrint:nHorzRes() /80       // columns

nBREAK := ( nRowStep * nLINES ) -;  // 57.65 * 55 = 3170.75 pixels resolution
          ( nRowStep * 5 )          // back off 5 lines

Line   := 0
nPAGE  := 1

oPRINT:StartPage()

xLINES := MLCount( cTEXT, 70 )
LINE := 5

IF EMPTY( cTEXT )
ELSE

   FOR i = 1 to xLINES
       pLINE := "    "+ALLTRIM(HardCr(MemoLine( cTEXT, 70, i )))
        prntline( pLINE )

       IF LINE >= nBREAK
          LINE := 0
          oPRINT:EndPage()
          oPRINT:StartPage()
          nPAGE++
          Line += nROWSTEP
          Line += nROWSTEP
       ENDIF
   NEXT
ENDIF

oPRINT:EndPage()
CursorArrow()

IF mVIEW = 'V'
   oPRINT:Preview()
ELSE
   PrintEnd()
ENDIF

oFONT:END()
RELEASE FONT oFont

MsgInfo( "Automated Letter sent to the Printer" )

RETURN(.T.)

//-----------------
Static Func prntline( pLINE )

LOCAL i, nCOL

nCOL := 0
FOR i = 1 to LEN(pLINE)
    oPRINT:SAY ( LINE, nCOL, SUBSTR(pLINE,i,1) , oFONT )
    nCOL += nColStep
NEXT
Line += nRowStep

RETURN(.T.)
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Printing a pre-formated letter
Posted: Thu Feb 19, 2009 05:00 PM

Please build a reduced and self-contained sample of what you are trying to do. Please note that CmSay() means "Centimeters Say", ie. you have to provide the coordinates in centimeters.

EMG

Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Printing a pre-formated letter
Posted: Thu Feb 19, 2009 09:21 PM
Enrico

What I have done is stored a complete document in a SQL Varchar(max) field .. what that does is stores the data exactically as it was put in .. for example, I have a complete letter with 3 paragraphs of text .. I can store it directly to the field like any other field where cLETTER is that variable that contains the formatted text using Notepad :

Code (fw): Select all Collapse
DO CASE
CASE cFIELD = "LETTER"
     cFILENAME := "LETTER.TXT"
     cREAD := cLETTER

     IF empty( cREAD ) .or. empty( alltrim( cREAD) )

        IF cMODE = "V"
           SAYING := "Sorry .. No Letter Text here to View"
           MsgInfo( SAYING )
           RETURN(.F.)
        ENDIF

        cREAD := " "
     ENDIF

OTHERWISE
     RETURN(.F. )
ENDCASE

FERASE( xVOL+"\DBTMP\"+cFILENAME )

nHANDLE := FCREATE(  xVOL+"\DBTMP\"+cFILENAME, 0 )
IF FERROR() <> 0
   SAYING := "Error Creating file "+(xVOL+"\DBTMP\"+cFILENAME)+CHR(10)
   SAYING += "Error "+STR(FERROR())+CHR(10)
   MsgInfo( SAYING )
   RETURN(.F.)
ENDIF

FWRITE( nHANDLE, cREAD )   // write out the file
FCLOSE( nHANDLE )

SysReFresh()

WAITRUN( "NOTEPAD " + xVOL+"\DBTMP\"+cFILENAME, 1 )

SysReFresh()

cFILE :=  xVOL+"\DBTMP\"+cFILENAME

// open file //
nHANDLE := FOpen( cFILE )
IF FERROR() <> 0
   SAYING := "Error reading file "+cFILE+CHR(10)
   SAYING += " "+STR(FERROR())+CHR(10)
   FERASE( xVOL+"\DBTMP\"+cFILENAME )
   MsgInfo( SAYING )
   RETURN(.F.)
ENDIF

// get number of bytes in file
nBYTES := FSEEK( nHANDLE, 0,2 )

// pad the buffer nBytes+1
cBUFFER := SPACE(nBYTES+1)

FSeek( nHANDLE, 0, 0 )
nBytesRead   := FRead( nHANDLE, @cBuffer, nBytes )

FClose( nHANDLE )
FERASE( xVOL+"\DBTMP\"+cFILENAME )

SysReFresh()

lOK := .F.

IF cMODE = "V"
ELSE
   DO CASE
   CASE cFIELD = "LETTER"

        IF nBYTESREAD < 2  // blank file

          cBUFFER     := ""
          lLETTER     := .F.
          lOK         := .F.

          cLETPROMPT := "LETTER Text  [not found]"
          oBtn3:cCAPTION := cLETPROMPT
          oBtn3:SetColor( "R+/W*" )
          oBtn3:ReFresh()
          SysReFresh()

       ELSE

          lLETTER     := .T.
          lOK         := .T.
          cLETPROMPT := "LETTER Text  [read me]"
          oBtn3:cCAPTION := cLETPROMPT
          oBtn3:SetColor( "G/W*" )
          oBTN3:ReFresh()
          SysReFresh()
       ENDIF

       cLETTER := cBUFFER

   OTHERWISE
        RETURN(.F. )
   ENDCASE

   cBUFFER := NIL
ENDIF

RETURN( lOK )


Once the binary data has been stored to cLETTER .. I can write it to the sql table like this oRs:Fields("letter"):Value := cLETTER

Then when I extract the data all I have to do is store the binary data to another variable like cLETTER := oRs:Fields("letter"):Value

NOW, cLETTER contains the complete formatted text just as it was typed in Notepad .. formatted correctly and in three paragraphs... and you can test this and look at the document like :

MsgInfo( cLETTER )

and it will look just like the letter formatted perfectically.

The problem I had was dumping the entire contents of cLETTER to the printer .. SAY and cmSay extract the entire variable and print one continious line on the page and it looks nothing like the document ..

That is why I had to parce up cLETTER into individual lines so I could get the entire document to print each line.

Hope that made sense ??

Thanks
Rick Lipkin
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Printing a pre-formated letter
Posted: Thu Feb 19, 2009 10:23 PM

Understood. I think you have to use MLCOUNT()/MEMOLINE() to get and print each single line from your text.

EMG

Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Printing a pre-formated letter
Posted: Thu Feb 19, 2009 11:47 PM
Enrico

Actually, I was pleasantly suprised that this code snipit worked

Code (fw): Select all Collapse
xLINES := MLCount( cTEXT, 100 )
LINE := 5

IF EMPTY( cTEXT )
ELSE

   FOR i = 1 to xLINES
       pLINE := "    "+MemoLine( cTEXT, 100, i )
        prntline( pLINE )

       IF LINE >= nBREAK
          LINE := 0
          oPRINT:EndPage()
          oPRINT:StartPage()
          nPAGE++
          Line += nROWSTEP
          Line += nROWSTEP
       ENDIF
   NEXT
ENDIF


After my amazement that the above code worked .. I took out the hardcr() and the Alltrim because the paragraphs were indented .. adjusting the LINE variable .. I was able to place the whole block of text exacticly where I wanted it ..

Rick Lipkin
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Printing a pre-formated letter
Posted: Fri Feb 20, 2009 09:16 AM

Great! :-)

EMG

Continue the discussion