RichEdit

RichEdit

Postby theotokos » Thu Mar 07, 2013 12:06 pm

Good Day,

I have a RichEdit field that I record in a DBF file MEMO field, this all right so far, but now need to print this
field with formatting in a RichEdit TPrinter (oPrn: Say), or another way that you can print other fields of DBF and MEMO field (RichEdit) together.


Example of what I'm doing:


Glucose: 110 mg / dl Vr.Ref.: F1s231 fs2d1 f32s1d f3232 F3S
Sd12FSD12F 12sdf 12SD2f2f f21


Note dsdasd 1as21d2as Of the d1as
f2sd31f 321sd32f 1sd321 f3s2dsd


N.T.: Fields Vr.Ref. and field observation are RichEdi
theotokos
 
Posts: 10
Joined: Thu Sep 02, 2010 10:56 am

Re: RichEdit

Postby Antonio Linares » Fri Mar 08, 2013 10:34 am

Please try with:

oRichEdit:Print( "document_name" )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42092
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: RichEdit

Postby Massimo Linossi » Fri Mar 08, 2013 3:32 pm

Hi Antonio.
If I want to print the text in a specific line and column, or to print it in a page but controlling the page break, because I have an header with some
other datas ?
TIA
Massimo.
User avatar
Massimo Linossi
 
Posts: 498
Joined: Mon Oct 17, 2005 10:38 am
Location: Italy

Re: RichEdit

Postby Antonio Linares » Fri Mar 08, 2013 5:13 pm

Massimo,

Class TRichEdit Method Print() is very simple and can be easily modified:

Code: Select all  Expand view
METHOD Print( cName ) CLASS TRichEdit

   local aMargins := PageGetMargins()
   local oPrn

   DEFAULT cName := "FWH RICHEDIT FILE"

   if ::IsSelection()
      PRINT oPrn NAME cName FROM USER SELECTION
   else
      PRINT oPrn NAME cName FROM USER
   endif

      if Empty( oPrn:hDC )
         MsgStop( "Printer not ready!" )
         return Self
      endif

      CursorWait()

      AEval( aMargins, { |x,y| aMargins[ y ] := x * 1440 / 2540 } )

      REPrint( ::hWnd, cName, oPrn:hDC, PrnGetPagNums(), PrnGetSelection(), ;
               PrnGetCollate(), PrnGetPages(), PrnGetCopies(), aMargins )

      CursorArrow()

   ENDPRINT

return nil
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42092
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: RichEdit

Postby Massimo Linossi » Fri Mar 08, 2013 5:17 pm

Thanks Antonio. Have a nice weekend.
User avatar
Massimo Linossi
 
Posts: 498
Joined: Mon Oct 17, 2005 10:38 am
Location: Italy

Re: RichEdit

Postby theotokos » Sat Mar 09, 2013 12:26 am

:roll:
Hello everybody
what I really need is to print a report and more MEMO field (RichEdit), more or less like this:

Clietnes................................Data..........................................Memo (RichEdit)
José....................................11/22/3333..................................Vr.Ref.: Jfjsldkf jsdjfsdfsd f
....................................................................................................fsd fsd fsdfsdk fksd fks
....................................................................................................efsd fsd fsdf3sd fsd fsd fds
Maria..................................11/33/2222..................................Vr.Ref.: da sdasld as dasdas das das das da
...................................................................................................d asd asd asd as das das das das das

Admittedly, this memo field (RichEdit) data will be formatted with fonts, color, etc..
theotokos
 
Posts: 10
Joined: Thu Sep 02, 2010 10:56 am

Re: RichEdit

Postby reinaldocrespo » Sat Mar 09, 2013 3:19 pm

I'm no longer printing richtext using tprinter, but on my previous systems I used it a lot. Here are some things you may be able to use:

Code: Select all  Expand view

                nFrom := 0
        a := ::oprn:Inch2Pix( ::ntop, ::nLeft )             //print region
        b := ::oprn:Inch2Pix( ::nRight, ::nBottom ) 

        RESetSelection( aoRtf[i]:hWnd, nFrom, -1)
        nLen    := Len( aoRtf[ i ]:GetSel() ) -1

        aRet := REPrintBox( aoRtf[i]:hWnd, iif( ::isPreview, ::oPrn:hDCOut, ::oPrn:hDC ),.t., a[1 ], a[2], b[1], b[2], nFrom )
        nFrom := aRet[ 1 ]

        ::nLastLine := ::oPrn:Pix2Inch( aRet[ 2 ], 0 )[1]

 


Notice how RePrintBox returns an array with the last printed pos in the RTF as the 1st element, and the line pos on the page that it printed on. You will need this in case you run into the next page. In case it helps you, below is the full method that did the printing. Keep in mind that it prints from an array of multiple rtfs and that printing all the rtfs may take multiple pages.

Code: Select all  Expand view
*-------------------------------------------------------------------------------------------------------------------------------
METHOD PrintBodyWithAttributes() CLASS PathologyTranscription

local cTitle := "Pathology Transcription " + hb_TokenUpper( Trim( ::oPat:Last ) + " " + ;
                    Trim( ::oPat:last2 ) + ", " + ::oPat: name )
local nFrom     := 0
local a         := ::oprn:Inch2Pix( ::ntop, ::nLeft )
local b         := ::oprn:Inch2Pix( ::nRight, ::nBottom )
local isdone    := .f.
local aoRtf     := ::aRtfTranscriptions
local i         := 1
local aRet, Elem
local nLen      := 0
local aFont, nColor
local nTotPage  := 0

    ::nLastLine := ::oPrn:Pix2Inch( a[ 1 ], 0 )[1]

    While !isdone
       
        while i < _MAX_AREAS +1 .and. aoRtf[ i ] == Nil
            i++ 
        End
       
        if i > _MAX_AREAS
            exit   
        endif
       
        RESetSelection( aoRtf[i]:hWnd, nFrom, -1)
        nLen    := Len( aoRtf[ i ]:GetSel() ) -1

        aRet := REPrintBox( aoRtf[i]:hWnd, iif( ::isPreview, ::oPrn:hDCOut, ::oPrn:hDC ),.t., a[1 ], a[2], b[1], b[2], nFrom )
        nFrom := aRet[ 1 ]

        DO CASE
            CASE nFrom < nlen           //did not finish, must run over to next page
                ntotPage++      ;aoRtf[i]:nPrintedPages++
                ::oprn:InchSay( 10.53, 7.5, "Page " + Str( nTotPage, 2 ), ::aFonts[ 1 ],,,, PAD_RIGHT )
                ::oprn:InchSay( 10.0, 4.25, "Continues on page " + str( nTotPage + 1, 2 ) + "...", ::ofont,,,, 2 )
                ::oprn:endPage()    ;::oprn:Startpage()
                a := ::oPrn:Inch2Pix( .60, 0.15 )   ;b := ::oprn:Inch2Pix( 10.5, 8.15 )     //Main Boxed area
                ::oprn:Box( a[ 1 ], a[ 2 ], b[ 1 ], b[ 2 ] )        //draw box around main area

                ::oprn:InchSay( 0.30, 0.50, "...continuation from page " + Str( nTotPage, 2 ), ::oFont )
                ::PrintForm( .f. )
                ::FillHeader1( .f. )

                a := ::oprn:Inch2Pix( ::ntop, ::nLeft )             //new print region
                b := ::oprn:Inch2Pix( ::nRight, ::nBottom )         //area for text

            CASE i == 4
                isdone := .t.

            CASE i < len( aoRtf )
                if !empty( aoRtf[ i ]:GetText() )
                    /*(aFont  := REGetCharFormat( aoRtf[i]:hWnd, @nColor )
                    logfile( "f:\mp\trace.log", { ::oprn:Pix2Inch( aFont[ LF_HEIGHT ], 0 )[1], aoRtf[i]:GetLineFromChar( nFrom ) -nTmp } )
                    ::nLastLine := ( ( ( aoRtf[i]:GetLineFromChar( nFrom ) - nTmp ) + 1 ) * ;
                            Max( ::oprn:Pix2Inch( aFont[ LF_HEIGHT ], 0 )[1], 0.10 ) ) + ;
                            iif( ntotPage > 0, 1.00, 4.69 ) */

                    ::nLastLine := ::oPrn:Pix2Inch( aRet[ 2 ], 0 )[1]
                    ::nlastline += 0.32                     //couple of blank lines
                Endif

                i++ ;nFrom := 0
                a := ::oprn:Inch2Pix( ::nLastLine, ::nLeft )        //new print region

//              nTmp := 0

            OTHERWISE               //unknown problems --get the hell out
                isdone := .t.
        END
    End

    ::oprn:InchSay( 10.53, 7.5, "Page " + Str( nTotPage+1, 2 ), ::aFonts[ 1 ],,,, PAD_RIGHT )
    ::nLastLine := ::oPrn:Pix2Inch( aRet[ 2 ], 0 )[ 1 ]

return nil
 


The key here is understanding how REPrintBox() works.

Hope that helps.


Reinaldo.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: RichEdit

Postby theotokos » Sat Mar 09, 2013 7:31 pm

Goodnight reinaldo, it seems that your solution solves the problem, but I'm still crush through .... and did not quite understand the routine, because I will not actually
have the object in RTF Dialog (eg REDEFINE RichEdit ORTF VAR cobs ID oFld OF 4202: aDialogs [3] Valid (COBS: = ORTF: SaveAsRTF (),. t.)) and Sim call a routine
Print it and use the MEMO field with the RichEdit formats. So I need to read this field (COBS: = Protocol-> observation) and print in one position
sheet with the formatting of RichEdit. Excuse me stupid.


reinaldocrespo wrote:I'm no longer printing richtext using tprinter, but on my previous systems I used it a lot. Here are some things you may be able to use:

Code: Select all  Expand view

                nFrom := 0
        a := ::oprn:Inch2Pix( ::ntop, ::nLeft )             //print region
        b := ::oprn:Inch2Pix( ::nRight, ::nBottom ) 

        RESetSelection( aoRtf[i]:hWnd, nFrom, -1)
        nLen    := Len( aoRtf[ i ]:GetSel() ) -1

        aRet := REPrintBox( aoRtf[i]:hWnd, iif( ::isPreview, ::oPrn:hDCOut, ::oPrn:hDC ),.t., a[1 ], a[2], b[1], b[2], nFrom )
        nFrom := aRet[ 1 ]

        ::nLastLine := ::oPrn:Pix2Inch( aRet[ 2 ], 0 )[1]

 


Notice how RePrintBox returns an array with the last printed pos in the RTF as the 1st element, and the line pos on the page that it printed on. You will need this in case you run into the next page. In case it helps you, below is the full method that did the printing. Keep in mind that it prints from an array of multiple rtfs and that printing all the rtfs may take multiple pages.

Code: Select all  Expand view
*-------------------------------------------------------------------------------------------------------------------------------
METHOD PrintBodyWithAttributes() CLASS PathologyTranscription

local cTitle := "Pathology Transcription " + hb_TokenUpper( Trim( ::oPat:Last ) + " " + ;
                    Trim( ::oPat:last2 ) + ", " + ::oPat: name )
local nFrom     := 0
local a         := ::oprn:Inch2Pix( ::ntop, ::nLeft )
local b         := ::oprn:Inch2Pix( ::nRight, ::nBottom )
local isdone    := .f.
local aoRtf     := ::aRtfTranscriptions
local i         := 1
local aRet, Elem
local nLen      := 0
local aFont, nColor
local nTotPage  := 0

    ::nLastLine := ::oPrn:Pix2Inch( a[ 1 ], 0 )[1]

    While !isdone
       
        while i < _MAX_AREAS +1 .and. aoRtf[ i ] == Nil
            i++ 
        End
       
        if i > _MAX_AREAS
            exit   
        endif
       
        RESetSelection( aoRtf[i]:hWnd, nFrom, -1)
        nLen    := Len( aoRtf[ i ]:GetSel() ) -1

        aRet := REPrintBox( aoRtf[i]:hWnd, iif( ::isPreview, ::oPrn:hDCOut, ::oPrn:hDC ),.t., a[1 ], a[2], b[1], b[2], nFrom )
        nFrom := aRet[ 1 ]

        DO CASE
            CASE nFrom < nlen           //did not finish, must run over to next page
                ntotPage++      ;aoRtf[i]:nPrintedPages++
                ::oprn:InchSay( 10.53, 7.5, "Page " + Str( nTotPage, 2 ), ::aFonts[ 1 ],,,, PAD_RIGHT )
                ::oprn:InchSay( 10.0, 4.25, "Continues on page " + str( nTotPage + 1, 2 ) + "...", ::ofont,,,, 2 )
                ::oprn:endPage()    ;::oprn:Startpage()
                a := ::oPrn:Inch2Pix( .60, 0.15 )   ;b := ::oprn:Inch2Pix( 10.5, 8.15 )     //Main Boxed area
                ::oprn:Box( a[ 1 ], a[ 2 ], b[ 1 ], b[ 2 ] )        //draw box around main area

                ::oprn:InchSay( 0.30, 0.50, "...continuation from page " + Str( nTotPage, 2 ), ::oFont )
                ::PrintForm( .f. )
                ::FillHeader1( .f. )

                a := ::oprn:Inch2Pix( ::ntop, ::nLeft )             //new print region
                b := ::oprn:Inch2Pix( ::nRight, ::nBottom )         //area for text

            CASE i == 4
                isdone := .t.

            CASE i < len( aoRtf )
                if !empty( aoRtf[ i ]:GetText() )
                    /*(aFont  := REGetCharFormat( aoRtf[i]:hWnd, @nColor )
                    logfile( "f:\mp\trace.log", { ::oprn:Pix2Inch( aFont[ LF_HEIGHT ], 0 )[1], aoRtf[i]:GetLineFromChar( nFrom ) -nTmp } )
                    ::nLastLine := ( ( ( aoRtf[i]:GetLineFromChar( nFrom ) - nTmp ) + 1 ) * ;
                            Max( ::oprn:Pix2Inch( aFont[ LF_HEIGHT ], 0 )[1], 0.10 ) ) + ;
                            iif( ntotPage > 0, 1.00, 4.69 ) */

                    ::nLastLine := ::oPrn:Pix2Inch( aRet[ 2 ], 0 )[1]
                    ::nlastline += 0.32                     //couple of blank lines
                Endif

                i++ ;nFrom := 0
                a := ::oprn:Inch2Pix( ::nLastLine, ::nLeft )        //new print region

//              nTmp := 0

            OTHERWISE               //unknown problems --get the hell out
                isdone := .t.
        END
    End

    ::oprn:InchSay( 10.53, 7.5, "Page " + Str( nTotPage+1, 2 ), ::aFonts[ 1 ],,,, PAD_RIGHT )
    ::nLastLine := ::oPrn:Pix2Inch( aRet[ 2 ], 0 )[ 1 ]

return nil
 


The key here is understanding how REPrintBox() works.

Hope that helps.


Reinaldo.
theotokos
 
Posts: 10
Joined: Thu Sep 02, 2010 10:56 am

Re: RichEdit

Postby reinaldocrespo » Sat Mar 09, 2013 10:42 pm

Unless you are ok with printing only text, you will need to create the oRichText object in order to print the rtf. There is no other option. What I used to do in that case, was to create the dialog as a hidden object as in : On INIT odlg:hide() -and then print.

Hope that helps,


Reinaldo.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: RichEdit

Postby theotokos » Sun Mar 10, 2013 1:22 pm

I understood, then it creates a richedit dialog and objects necessary for printing and makes printing with formatted text. I will assemble here for the test. For now many thanks for the help. Stay with God.

reinaldocrespo wrote:Unless you are ok with printing only text, you will need to create the oRichText object in order to print the rtf. There is no other option. What I used to do in that case, was to create the dialog as a hidden object as in : On INIT odlg:hide() -and then print.

Hope that helps,


Reinaldo.
theotokos
 
Posts: 10
Joined: Thu Sep 02, 2010 10:56 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 100 guests