RichType Print

RichType Print

Postby Rick Lipkin » Tue May 09, 2017 6:24 pm

To All

I am trying to print a RichType letter saved as a variable cRtf ... I know I can use the Print and Preview methods, however, I am adding a stored custom masthead to my RichText. I am struggling to be able to insert richtext after the image .. I can print the image, but trying to adapt The RichText Print method is not working ..

What I am trying to do is print the Custom MastHead then print the RichText after the image .. here is my code ..
Code: Select all  Expand view

//--------------------------------
Static Func _LetterPrint( cRtf, oRsLetter )

Local oPrint,nRowStep,nColStep,nMargin,Line,nPage
Local cPicFileName,cDefa,lPicFileName,oImg
Local nTopR,nTopL,nBotR,nBotL
Local nLinCnt,x,cText
Local oFontB,aMargins,nPrint

aMargins := PageGetMargins()
cDefa := set(7)

lPicFileName := .t.
If empty( oRsLetter:Fields("PicFileName"):Value) .or.;
   oRsLetter:Fields("PicFileName"):Value = " "
   lPicFileName := .f.
Else
   cPicFileName := oRsLetter:Fields("PicFileName"):Value
Endif

PRINTER oPRINT FROM USER                ;
PREVIEW MODAL                           ;
NAME "Print Routine for TEST LETTER"

IF EMPTY( oPRINT:hDC )
   MsgInfo ( "Report Cancelled" )
   Return(.f.)
ENDIF

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

oPRINT:StartPage()

nMargin := Int(oPrint:nLogPixelX()*0.2)
LINE    := nMargin
nPage   := 1

oFontB  := TFont():New("Ms Sans Serif",,-6,.F.,.T. ,,,,.F. ) // just used for spacing

If lPicFileName = .t.

   cPicFileName := cDefa+"\MastHead\"+alltrim(cPicFileName)
   DEFINE IMAGE oImg FILENAME cPicFileName

   nTopR  := 0
   nTopL  := 100
   nBotR  := oPrint:nHorzRes()*.9375 // 4500
   nBotL  := oPrint:nVertRes()*.1563 // 1000

   oPrint:SayImage( nTopR, nTopL, oImg, nBotR,nBotL )
   oImg:End()

   // calc for cRtf text to start
   Line := (oPrint:nVertRes()*.1570)  // 5331
   msginfo( Line )

Endif

/* ... this is rem'd out and does not work properly
 // Print letter text            123 - 100
*nLinCnt := MlCount( cRtf, 110 )

*msginfo( "
nLinCnt" )
*msginfo( nLinCnt )

*IF nLinCnt > 0
*   FOR x := 1 to nLinCnt
*      cText := MemoLine( cRtf, 110, x )
*       oPrint:Say( LINE,(oPrint:nHorzRes()*.07), cText ) //, oFont10b )  // 200
*      Line += oFontb:nHeight
*       Line += oFontb:nHeight
*      Line += oFontb:nHeight
*       Line += oFontb:nHeight
*       Line += oFontb:nHeight
*   NEXT
Endif
*/

aMargins := PageGetMargins()

nPrint := 0
*nLen   := ::Len()

*msginfo( nLen )

nLen := 1

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

*      do while nPrint < nLen
*         PAGE
            nPrint := REPreview5( ::hWnd, oPrint:hDC, oPrint:hDCOut, aMargins, nPrint )  // obvious self error
*         ENDPAGE
*      enddo


oPRINT:EndPage()
RELEASE FONT oFontB

oPRINT:Preview()

Return(nil)


Any Ideas ... I get the Image to print ( a masthead logo ) but I cannot figure out how to print cRtf out and preserve the formatting and text. Any help would be appreciated.

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2616
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: RichType Print

Postby cnavarro » Tue May 09, 2017 8:09 pm

Rick
Insert image before into cRtf and try
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6500
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: RichType Print

Postby Rick Lipkin » Wed May 10, 2017 4:09 pm

Cristobal

Your idea is sound .. I have manually cut and pasted a .png image into my richtext with no problem ..

Image

Unfortunitly when I save the file back to the Access Memo field .. the image does not save .. just the text .. here is my code:
Code: Select all  Expand view

REDEFINE BTNBMP oBtn1 ID 111 of oUSERS   ;     // ok
         RESOURCE "OK", "DOK", "DOK" ;
         PROMPT "&Ok" LEFT 2007;
         ACTION ( lOk := .t.,;
                  If( lOk = .t., (cLetter := oRtf:GetText(),;
                                  oRsLetter:Fields("Body"):Value := cLetter,;
                                  oRsLetter:Update()),  ),;
                  If( lOk = .t., oUSERS:END(),)  )
 


Is there another method to save Image and text to an Access Memo type Field ?

Thanks
Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2616
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: RichType Print

Postby cnavarro » Wed May 10, 2017 4:16 pm

Rick, please use METHOD INsertPictureFile or any METHOD Insert..... of Class
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6500
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: RichType Print

Postby Rick Lipkin » Wed May 10, 2017 4:20 pm

Cristobal

I am going to tackle the insert picture in code later .. as a test I cut and pasted manually the image..to test .. I just want to save the entire cRtf ( with image ) to the Access Memo type .. ..

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2616
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: RichType Print

Postby cnavarro » Wed May 10, 2017 8:27 pm

Rick, try with

after paste image

Code: Select all  Expand view

cLetter := oRtf:SaveAsRTF()
 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6500
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: RichType Print

Postby Rick Lipkin » Wed May 10, 2017 9:03 pm

Chrstobal

I got a very unexpected result to this code ..
Code: Select all  Expand view


#include "RichEdi5.ch"

.
.
.
 REDEFINE BTNBMP oBtn1 ID 111 of oUSERS   ;     // ok
         RESOURCE "OK", "DOK", "DOK" ;
         PROMPT "&Ok" LEFT 2007;
         ACTION ( lOk := .t.,;
                  If( lOk = .t., (cLetter := oRtf:SaveAsRTF(),oRsLetter:Fields("Body"):Value := cLetter,;
                                  oRsLetter:Update(),msginfo( cLetter )),  ),;
                  If( lOk = .t., oUSERS:END(),)  )
 


Image

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2616
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: RichType Print

Postby cnavarro » Thu May 11, 2017 1:59 am

Rick

I do not understand well your message
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6500
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: RichType Print

Postby Rick Lipkin » Thu May 11, 2017 2:00 pm

Cristobal

Using cLetter := oRtf:SaveAsRTF() ... then interrogating cLetter you get the output above with all the rtf encoding visible in the output.

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2616
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: RichType Print

Postby cnavarro » Thu May 11, 2017 5:16 pm

Rick Lipkin wrote:Cristobal

Using cLetter := oRtf:SaveAsRTF() ... then interrogating cLetter you get the output above with all the rtf encoding visible in the output.

Rick Lipkin


Rick
Then, I do not understand well your goal

If you save this code, you save text, format and any object included, no?
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6500
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: RichType Print

Postby Rick Lipkin » Thu May 11, 2017 5:25 pm

Cristabol

When you save the variable .. it looks like what you see above .. when you retrieve the value of the memo field as a variable .. it looks exactly the same with all the formatting ( garbage ) .. add an image .. and all you see is trash for the image and formatting garbage for the text ..

I am at a loss .. it seems like RichText is meant to be saved to a file to work properly .. not saved to any type of Memo field .. be it Access or Sql Server.

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2616
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: RichType Print

Postby cnavarro » Thu May 11, 2017 5:28 pm

Then, you only Do you want to save the text, nothing else?
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6500
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: RichType Print

Postby Rick Lipkin » Thu May 11, 2017 5:34 pm

Cristabol

As Created :
Image

As retrieved :
Image

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2616
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: RichType Print

Postby cnavarro » Thu May 11, 2017 5:41 pm

Rick

oRTF:SaveAsRTF(), return all code RichEdit
oRTF:GetText(), return text

Sorry, I do not understand what you need
What do you want to save to the database?
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6500
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: RichType Print

Postby Rick Lipkin » Thu May 11, 2017 5:54 pm

Cristabol

I want to create a RTF letter with an Image .. cLetter .. then save the letter to the database .. then re-call the Letter again from the database .. here is the code:
Code: Select all  Expand view

DEFINE DIALOG oUSERS RESOURCE "LETTER" ;
       TITLE cTITLE              ;

       REDEFINE SAY oSay1 ID 125 OF oUsers UPDATE     // double click
       oSay1:SetFont( oFontB )


       REDEFINE SAY oSay2 ID 126 OF oUsers UPDATE     // double click
       oSay2:SetFont( oFontB )
       oSay2:SetColor( nRgb(7,7,224)) // blue


       IF cMODE = "E" .or. cMode = "A"

          REDEFINE RICHEDIT5 oRtf VAR cRtf ID 130 of oUSERS //UPDATE

       ELSE     // view

          REDEFINE RICHEDIT5 oRtf VAR cRtf ID 130 of oUSERS //READONLY //COLOR CLR_BLACK, 15987697 READONLY
          oRtf:SetReadOnly( .T. )

       ENDIF

       oRtf:SetText( cRtf )
       oRtf:bGotFocus = { || oRtf:SetSel( 0, 0 ) }


       REDEFINE BTNBMP oBtn1 ID 111 of oUSERS   ;     // save to table
         RESOURCE "OK", "DOK", "DOK" ;
         PROMPT "&Ok" LEFT 2007;
         ACTION ( lOk := .t.,;
                  If( lOk = .t., (cLetter := oRtf:SaveAsRTF(),oRsLetter:Fields("Body"):Value := cLetter,;  // <---  save to access memo field
                                  oRsLetter:Update()),  ),;
                  If( lOk = .t., oUSERS:END(),)  )

       REDEFINE BTNBMP oBtn2 ID 112 of oUSERS   ;    // cancel
         RESOURCE "CANCEL", "DCANCEL", "DCANCEL" ;
         PROMPT "&Cancel" LEFT 2007;
         ACTION (lOk := .f., oUSERS:END())


       REDEFINE BTNBMP oBtn3 ID 113 of oUSERS   ;    // test print
         RESOURCE "PRINT25" ;
         PROMPT "Test"+CRLF+"Print" LEFT 2007;
         ACTION ( oRtf:Preview( cRtf ) )

         oUsers:bResized = { | nSizeType, nWidth, nHeight | ResizeControls( nSizeType, nWidth, nHeight, oUsers )}

ACTIVATE DIALOG oUSERS  ;
     ON INIT ( oUsers:Move(100,250) );
     ON PAINT ( GradientFill( hDC, 0, 0, oUsers:nHeight, oUsers:nWidth, xGrad, .T. ));     // note GradientFill
     VALID (!GETKEYSTATE( 27 )) ;  // do not allow esc key here

If cMode = "V"
   cLetter := cOldMemo
Endif

If lOk = .t.
   nLen  := Len( cLetter )

   Do Case
   Case nLen = 0
        cRtPrompt := "Create Letter"
   Case nLen > 0
        cRtPrompt := "View Letter"
   End Case

   oButt3:cCAPTION := cRtPrompt
   * oBtn3:SetColor( "R+/W*" )
   oButt3:ReFresh()
ENdif

LightGreyGrad()

RETURN( NIL )

 
User avatar
Rick Lipkin
 
Posts: 2616
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 94 guests

cron