FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour RichType Print
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
RichType Print
Posted: Tue May 09, 2017 06: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 (fw): Select all Collapse
//--------------------------------
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
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: RichType Print
Posted: Tue May 09, 2017 08: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
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: RichType Print
Posted: Wed May 10, 2017 04:09 PM
Cristobal

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



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 (fw): Select all Collapse
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
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: RichType Print
Posted: Wed May 10, 2017 04: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
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: RichType Print
Posted: Wed May 10, 2017 04: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

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: RichType Print
Posted: Wed May 10, 2017 08:27 PM
Rick, try with

after paste image

Code (fw): Select all Collapse
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
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: RichType Print
Posted: Wed May 10, 2017 09:03 PM
Chrstobal

I got a very unexpected result to this code ..
Code (fw): Select all Collapse
#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(),)  )




Rick Lipkin
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: RichType Print
Posted: Thu May 11, 2017 01: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
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: RichType Print
Posted: Thu May 11, 2017 02: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

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: RichType Print
Posted: Thu May 11, 2017 05: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
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: RichType Print
Posted: Thu May 11, 2017 05: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

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: RichType Print
Posted: Thu May 11, 2017 05: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
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: RichType Print
Posted: Thu May 11, 2017 05:34 PM
Cristabol

As Created :


As retrieved :


Rick Lipkin
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: RichType Print
Posted: Thu May 11, 2017 05: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
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: RichType Print
Posted: Thu May 11, 2017 05: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 (fw): Select all Collapse
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 )