FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Ayuda Urgente con Imprimir Texto Memo con Richedit5
Posts: 719
Joined: Fri May 12, 2017 02:50 PM
Ayuda Urgente con Imprimir Texto Memo con Richedit5
Posted: Mon Mar 18, 2019 09:53 PM
Amigos.

Necesito solucionar el problema de imprimir campo memo FPT guardado con Richedit5.

Cristobal Navarro, me proporciono el código que muestro mas abajo, funciona para imprimir solo una página, pero los texto que guardo son texto enriquecido y que pueden llegar a tener 4 páginas, por lo que me es Urgente lograr que este codigo me permita imprimir la totalidad del texto en forma directa, no pasando por Word.

En espera como siempre de su ayuda, les saluda muy atte.
Antonio.

Código que Imprime solo una pagina del Texto:
Code (fw): Select all Collapse
    #include "FiveWin.ch"
    #include "richedi5.ch"

    //----------------------------------------------------------------------------//

    function Main()

       local oDlg
       local oRich
       //local hRichDLL  := LoadLibrary( "riched20.dll" )
       local lSyntaxHL := .f.
       local cTxt      := ""
       local uVal

       FWSetLanguage( 2 )

        USE RTFCODE
        GO TOP
        cTxt     += rtfcode->memcode
        CLOSE

       //? cTxt
       // Simulo la lectura del contenido del campo
       //cTxt  :=  "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fprq2\fcharset0 Microsoft Sans Serif;}{\f1\fnil\fcharset0 Microsoft Sans Serif;}}" + ;
       //          "{\colortbl ;\red128\green0\blue0;\red0\green0\blue0;\red0\green128\blue0;\red255\green0\blue0;}" + ;
       //          "\viewkind4\uc1\pard\cf1\b\i\f0\fs28 JH\cf2\b0\i0  - Sue let me \cf3 know\cf2  that their rep had noticed that they were not performing the yearly \cf4\ul\b\fs24 escrow\cf2\ulnone\b0\fs28  analysis.\cf0\f1\fs17\par" + ;
       //          "}"

       DEFINE DIALOG oDlg RESOURCE "Test"
       oDlg:lHelpIcon   := .F.

       REDEFINE BUTTON ID 110 ;
          ACTION ( oRich:SetText( cTxt ) )

       REDEFINE CHECKBOX lSyntaxHL ID 115 OF oDlg ;
          ON CHANGE ( oRich:lHighLight := lSyntaxHL, ;
                      oRich:SetText( oRich:GetText() ) )

       REDEFINE BUTTON ID 120 ;
          ACTION oRich:LoadFromRTFFile( cGetFile( "RTF file (*.rtf) | *.rtf" ) )
         
       REDEFINE BUTTON ID 130 ;
          ACTION oRich:SaveToRTFFile( cGetFile( "RTF file (*.rtf) | *.rtf",;
                                      "Please write a filename", "test" ) )
           
       REDEFINE BUTTON ID 998 ACTION PrintBox( oRich, .T. )
       //( oRich:GoToLine( 10 ), oRich:SetFocus() )

       oRich := TRichEdit5():Redefine( 100, bSETGET( cTxt ), oDlg )
       //oRich:lHighLight = .T.

       ACTIVATE DIALOG oDlg CENTERED ;  //
          ON INIT ( oRich:LoadRtf( cTxt ), oRich:PostMsg( WM_KEYDOWN, VK_HOME, 0 ) ) ; //oRich:SetText( cTxt ) ;  //
          VALID ( cTxt := oRich:SaveAsRTF(),  .T. ) // oRich:GetText(), .T. )

       //MemoEdit( cTxt )
       //MemoEdit( uVal )
       //XBrowse( hb_aTokens( uVal ) )

       //FreeLibrary( hRichDLL )

    return nil

    //----------------------------------------------------------------------------//

    function PrintBox( oRtf, lPreview )

       local oPrn
       local aRTF := { 100, 1500 }  // { nFrom, nTop }

       DEFAULT lPreview := .f.    // if .T., to screen

       if lPreview
          PRINT oPrn NAME "FWH RICHEDIT FILE" PREVIEW
       else
          PRINT oPrn NAME "FWH RICHEDIT FILE"
       endif

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

          PAGE
             CursorWait()
             oPrn:Box( aRTF[ 1 ] + 10, 90, aRtf[ 2 ] + 1000, aRTF[ 1 ] + 1010 )

    /*
          nFrom := REPrintBox5( ::hWnd, hDC, ::IsSelection(), ;
                               nTop, nLeft, nRight, nBottom, nFrom )
         // El ultimo parámetro indica a partir de qué número de carácter dentro del texto quieres empezar a imprimir.
    */
             aRTF := REPrintBox5( oRTF:hWnd, If( lPreview, oPrn:hDCOut, oPrn:hDC ), ;
                                  oRTF:IsSelection(), ;
                                  aRTF[ 1 ] + 20, 110, aRTF[ 1 ] + 1000, aRtf[ 2 ] + 990, 0 )

             CursorArrow()
          ENDPAGE

       ENDPRINT

    return nil

    //----------------------------------------------------------------------------//
FWH 22.10 - HARBOUR - PELLES C
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Ayuda Urgente con Imprimir Texto Memo con Richedit5
Posted: Tue Mar 19, 2019 01:47 PM
Intenta asi:

Code (fw): Select all Collapse
#include "FiveWin.ch"
#include "richedi5.ch"

ANNOUNCE RDDSYS
REQUEST DBFCDX, DBFFPT

FUNCTION Main()

   LOCAL oDlg
   LOCAL oRich
   LOCAL lSyntaxHL := .F.
   LOCAL cTxt      := ""
   LOCAL uVal

   RDDSETDEFAULT("DBFCDX")

   FWSetLanguage( 2 )

   USE RTFCODE NEW  // SIN INDICE .CDX?
   GO TOP

   BROWSE() // VISUAL DEL CAMPO

   // WHILE .NOT. EOF()

   cTxt     += rtfcode->memcode

   // SI SOLO UN CAMPO:
   // cTxt     := rtfcode->memcode
                                  
   // SKIP

   // ENDDO

   DEFINE DIALOG oDlg RESOURCE "Test"

   oDlg:lHelpIcon   := .F.

   REDEFINE BUTTON ID 110 ;
      ACTION ( oRich:SetText( cTxt ) )

   REDEFINE CHECKBOX lSyntaxHL ID 115 OF oDlg ;
      ON CHANGE ( oRich:lHighLight := lSyntaxHL, ;
      oRich:SetText( oRich:GetText() ) )

   REDEFINE BUTTON ID 120 ;
      ACTION oRich:LoadFromRTFFile( cGetFile( "RTF file (*.rtf) | *.rtf" ) )
         
   REDEFINE BUTTON ID 130 ;
      ACTION oRich:SaveToRTFFile( cGetFile( "RTF file (*.rtf) | *.rtf",;
      "Please write a filename", "test" ) )
           
   REDEFINE BUTTON ID 998 ACTION PrintBox( oRich, .T. )

   oRich := TRichEdit5():Redefine( 100, bSETGET( cTxt ), oDlg )

   ACTIVATE DIALOG oDlg CENTERED ;
      ON INIT ( oRich:LoadRtf( cTxt ), oRich:PostMsg( WM_KEYDOWN, VK_HOME, 0 ) ) ; //oRich:SetText( cTxt ) ;  //
      VALID ( cTxt := oRich:SaveAsRTF(),  .T. ) // oRich:GetText(), .T. )

   CLOSE

RETURN nil

//----------------------------------------------------------------------------//

FUNCTION PrintBox( oRtf, lPreview )

   LOCAL oPrn
   LOCAL aRTF := { 100, 1500 }  // { nFrom, nTop }

   DEFAULT lPreview := .F.    // if .T., to screen

   IF lPreview
      PRINT oPrn NAME "FWH RICHEDIT FILE" PREVIEW
   ELSE
      PRINT oPrn NAME "FWH RICHEDIT FILE"
   ENDIF

   IF Empty( oPrn:hDC )
      MsgStop( "Printer not ready!" )
      RETURN nil
   ENDIF

   PAGE

      oPrn:Box( aRTF[ 1 ] + 10, 90, aRtf[ 2 ] + 1000, aRTF[ 1 ] + 1010 )

       /*
       nFrom := REPrintBox5( ::hWnd, hDC, ::IsSelection(), ;
                               nTop, nLeft, nRight, nBottom, nFrom )
       // El ultimo parámetro indica a partir de qué número de carácter dentro del texto quieres empezar a imprimir.
       */

      aRTF := REPrintBox5( oRTF:hWnd, If( lPreview, oPrn:hDCOut, oPrn:hDC ), ;
      oRTF:IsSelection(), ;
      aRTF[ 1 ] + 20, 110, aRTF[ 1 ] + 1000, aRtf[ 2 ] + 990, 0 )

   ENDPAGE

   ENDPRINT

RETURN nil
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 1344
Joined: Wed Nov 16, 2005 09:14 PM
Re: Ayuda Urgente con Imprimir Texto Memo con Richedit5
Posted: Tue Mar 19, 2019 09:16 PM
Antonio:
Te vuelvo a pasar el codigo, por si el que te habia pasado estaba mal.
Este funciona en la actualidad, y aunque usa Word, el mismo no se ve, solo lo usa para imprimir el documento
Code (fw): Select all Collapse
   cText:= mitabla->texto // Texto con formato guardado en la dbf en un campo memo
   memowrit( hb_CurDrive()+":\"+curdir()+"\Temp.rtf", cText )
   if   (oWord := WinWordObj() ) == nil
        MsgAlert( "Complemento no instalado" ,  "Alerta" )        
        else
        oDoc = oWord:Documents:Open(hb_CurDrive()+":\"+curdir()+"\Temp.rtf")
        if oDoc == nil
           MsgAlert("Fallo crear documento, verifique que no este en uso" , "Alerta"  )           
           return 
         endif
   endif   
   oDoc:PrintOut()
   oDoc:Close()

Continue the discussion