RTF to PDF

This forum is for ideas and or code to be contributed for general use.
Post Reply
Message
Author
User avatar
rdonnay
Site Admin
Posts: 4774
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

RTF to PDF

#1 Post by rdonnay »

Here is a handy little program that converts an RTF file to a PDF file.

It uses the XbpRtf() class and the Bullzip PDF Printer driver.

Code: Select all

#INCLUDE "dcdialog.CH"
#Pragma Library("ascom10.lib")

FUNCTION Main( cFileName )

LOCAL oRtf, cMemo := '', GetList[0], GetOptions, oPrinter, oBullZip, ;
      cOutFile, nChoice := 1

IF Empty(cFileName)
  cFileName := DC_PopFile(,,'*.rtf')
ELSEIF Empty(DC_Path(cFileName))
  cFileName := DC_CurPath() + '\' + cFileName
ENDIF

IF Empty(cFileName)
  QUIT
ENDIF

cOutFile := Strtran(cFileName,'.rtf','.Pdf')
cOutFile := Strtran(cOutFile,'.Rtf','.Pdf')
cOutFile := Strtran(cOutFile,'.RTF','.Pdf')

oBullZip := ActiveXObject():create('Bullzip.PDFPrinterSettings')
oBullZip:SetValue('Output',cOutFile)
oBullZip:SetValue('ShowSaveAs','never')
oBullZip:SetValue('ShowSettings','never')
oBullZip:SetValue('ShowPdf','no')
oBullZip:SetValue('ConfirmOverwrite','no')
oBullZip:SetValue('ShowProgressFinished','no')
oBullZip:SetValue('ShowProgress','no')
oBullZip:WriteSettings()

oPrinter := XbpPrinter():new()
oPrinter:create("Bullzip PDF Printer")
oPrinter:setPrintFile(cOutFile)

@ 0,0 DCRTF ;
   OBJECT oRTF ;
   SIZE 80,20 ;
   VAR cMemo ;
   EVAL {|o|o:loadFile(cFileName), ;
            o:Print(oPrinter)}

DCGETOPTIONS ;
   HIDE ;
   RESIZE

DCREAD GUI FIT TITLE 'RTF to PDF' ;
   EXIT ;
   OPTIONS GetOptions

DCMSGBOX 'File Created: ' + cOutFile ;
   BUTTONS {'View PDF File','Exit'} CHOICE @nChoice

IF nChoice == 1
  DC_SpawnUrl(cOutFile)
ENDIF

RETURN nil

* --------

PROC appsys ; RETURN
The eXpress train is coming - and it has more cars.

Post Reply