How to Convert RTF to PDF

Post Reply
User avatar
vilian
Posts: 795
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil
Contact:

How to Convert RTF to PDF

Post by vilian »

Guys,

Do you know some way to convert RTF files to PDF files without open them ?
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
Rick Lipkin
Posts: 2397
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: How to Convert RTF to PDF

Post by Rick Lipkin »

Vilian

Have a look at TRichEdit5 class ( triched5.prg in \samples\classes ) METHOD SaveToPDF( cName, cFile, lView ).

Rick Lipkin
User avatar
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: How to Convert RTF to PDF

Post by cnavarro »

Rick Lipkin wrote:Vilian

Have a look at TRichEdit5 class ( triched5.prg in \samples\classes ) METHOD SaveToPDF( cName, cFile, lView ).

Rick Lipkin
Yes, but function used for print need ::hWnd of control
C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
User avatar
vilian
Posts: 795
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil
Contact:

Re: How to Convert RTF to PDF

Post by vilian »

Thank You guys, I will try.
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: How to Convert RTF to PDF

Post by cnavarro »

Create and hide control ?
C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
User avatar
vilian
Posts: 795
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil
Contact:

Re: How to Convert RTF to PDF

Post by vilian »

Yes, I will try using something like this ;)
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
RAMESHBABU
Posts: 591
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Re: How to Convert RTF to PDF

Post by RAMESHBABU »

Dear Cristobal,

I have a problem with the oRTF:SaveToPdf(...) Method of TRichEdit5 Class.
It is creating the PDF, but the contents of the PDF File are blurry and not
readable as shown in the picture here.

Image

Pleease help me.

Regards,

-Ramesh Babu P
User avatar
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: How to Convert RTF to PDF

Post by cnavarro »

Dear Ramesh
The image is not visible.
Please put your image or send me your file pdf
C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
User avatar
RAMESHBABU
Posts: 591
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Re: How to Convert RTF to PDF

Post by RAMESHBABU »

Dear Cristobal,

The image I have posted above is the exact PDF generated
using the "TESTRTF5.PRG" under FWH\Samples.

The Menu Path used to generated the PDF is "File -> To RTF".
And the RTF file is "TESTRTF.RTF"

You can try it yourself.

Regards,

-Ramesh Babu P
User avatar
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: How to Convert RTF to PDF

Post by cnavarro »

Dear Ramesh
For me it's OK

Image

Please put or send me your pdf
C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: How to Convert RTF to PDF

Post by nageswaragunupudi »

cnavarro wrote:Create and hide control ?
This is an attempt to use RichEdit5 control to silently convert RTF to PDF without displaying the control.

Code: Select all

#include "fivewin.ch"

function Main()

   local oWnd, oBar

   DEFINE WINDOW oWnd TITLE "MY APPLICATION"
   DEFINE BUTTONBAR oBar OF oWnd SIZE 100,32 2010
   DEFINE BUTTON OF oBar PROMPT "RTFTOPDF" ;
      ACTION RTFTOPDF( "c:\fwh\samples\fiveodbc.rtf" )
   ACTIVATE WINDOW oWnd CENTERED

return nil

static function RTFTOPDF( cRTF, cPDF, lOpen )

   local oWnd, oRtf, cTxt := ""

   if Empty( cRtf ) .or. !File( cRTF ) .or. Lower( cFileExt( cRtf ) ) != "rtf"
      return .f.
   endif
   DEFAULT cPDF := cRTF, lOpen := .t.
   cPDF  := cFileSetExt( cPDF, "pdf" )

   FErase( cPDF )

   DEFINE WINDOW oWnd
   @ 0,0 RICHEDIT5 oRtf VAR cTxt OF oWnd FILE cRTF
   oWnd:oClient := oRtf

   ACTIVATE WINDOW oWnd HIDDEN ON INIT ;
      ( oRtf:SaveToPDF( cFileNoExt( cPdf ), cPDF, lOpen ), oWnd:End() )

return File( cPDF )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
ricbarraes
Posts: 49
Joined: Tue Jun 30, 2015 2:26 am
Location: Brazil

Re: How to Convert RTF to PDF

Post by ricbarraes »

Hello everyone,
I'm trying to convert a RTF file into a PDF File. I already tried all your code suggestions and it now I'm able to preview it.
Everything works, except that I got some tables in the RTF File, and I don't know why the convertion to PDF is affecting the columns alignment.
Does anybody know what's happening?

Code: Select all

RtfToPdf(cNovo)

FUNCTION RtfToPdf( cRTF, cPDF, lOpen )
LOCAL oWnd, oRtf, cTxt := ""

   IF Empty( cRtf ) .or. !File( cRTF ) .or. Lower( cFileExt( cRtf ) ) != "rtf"
      return .f.
   ENDIF
   DEFAULT cPDF := cRTF, lOpen := .t.
   cPDF  := cFileSetExt( cPDF, "pdf" )

   FErase( cPDF )


   DEFINE WINDOW oWnd
   @ 0,0 RICHEDIT5 oRtf VAR cTxt OF oWnd FILE cRTF
   oWnd:oClient := oRtf

   ACTIVATE WINDOW oWnd HIDDEN ON INIT ;
      ( oRtf:SaveToPDF( cFileNoExt( cPdf ), cPDF, lOpen ), oWnd:End() )


RETURN File( cPDF )


METHOD SaveToPDF( cName, cFile, lView ) CLASS TRichEdit5

   local aMargins := PageGetMargins()
   local nLen     := ::Len()
   local nPrint   := 0
   local oPrn
   //local aPrinters := aGetPrinters()

   ?::cFileName,cFileNoExt( ::cFileName ) + ".pdf", cName, cFile

   DEFAULT cName := cFileNoExt( ::cFileName ) + " Report" //"FWH RichEdit Report"
   DEFAULT cFile := cFileNoExt( ::cFileName ) + ".pdf"
   DEFAULT lView := .F.

   if ::IsSelection()
      nPrint   := ::GetPos()
      nLen     := ::GetSelection()[ 2 ] - nPrint
      //? nPrint, ::GetSelection()[ 2 ], nLen
   endif

   if !Empty( cFile )
      if lView
         PRINT oPrn NAME cName PREVIEW FILE cFile
      else
         PRINT oPrn NAME cName FILE cFile
      endif

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

      CursorWait()

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

      do while nPrint < nLen
         PAGE
            nPrint := REPreview5( ::hWnd, oPrn:hDC, oPrn:hDCOut, aMargins, nPrint )
         ENDPAGE
      enddo

      CursorArrow()

      ENDPRINT

   else
      MsgStop( "Not file name is implemented", "Error" )
   endif
return nil
 

Image
Post Reply