How to Convert RTF to PDF

How to Convert RTF to PDF

Postby vilian » Tue May 09, 2017 7:47 pm

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
vilian
 
Posts: 975
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: How to Convert RTF to PDF

Postby Rick Lipkin » Tue May 09, 2017 8:04 pm

Vilian

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

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

Re: How to Convert RTF to PDF

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

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
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: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: How to Convert RTF to PDF

Postby vilian » Tue May 09, 2017 8:25 pm

Thank You guys, I will try.
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
vilian
 
Posts: 975
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: How to Convert RTF to PDF

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

Create and hide control ?
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: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: How to Convert RTF to PDF

Postby vilian » Tue May 09, 2017 11:10 pm

Yes, I will try using something like this ;)
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
vilian
 
Posts: 975
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: How to Convert RTF to PDF

Postby RAMESHBABU » Fri Jul 26, 2019 1:31 pm

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
RAMESHBABU
 
Posts: 624
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Re: How to Convert RTF to PDF

Postby cnavarro » Fri Jul 26, 2019 3:03 pm

Dear Ramesh
The image is not visible.
Please put your image or send me your file pdf
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: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: How to Convert RTF to PDF

Postby RAMESHBABU » Sat Jul 27, 2019 11:44 am

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
RAMESHBABU
 
Posts: 624
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Re: How to Convert RTF to PDF

Postby cnavarro » Sat Jul 27, 2019 12:31 pm

Dear Ramesh
For me it's OK

Image

Please put or send me your pdf
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: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: How to Convert RTF to PDF

Postby nageswaragunupudi » Sat Jul 27, 2019 9:01 pm

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  Expand view
#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
nageswaragunupudi
 
Posts: 10631
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: How to Convert RTF to PDF

Postby ricbarraes » Wed Mar 11, 2020 9:00 pm

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  Expand view
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
User avatar
ricbarraes
 
Posts: 55
Joined: Tue Jun 30, 2015 2:26 am
Location: Brazil


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 99 guests