METHOD SaveAs( lPDF, cFile, lView ) CLASS TPreview
static lWordPDF := .t.
local oWord, nVer, oDoc
local cExt, cMsg
if lPDF
if ValType( ::bSaveAsPDF ) == 'B'
return Eval( ::bSaveAsPDF, Self, cFile, lView )
elseif ! lWordPDF // tested earlier and found Word with PDF plugin not availble
return FWSavePreviewToPDF( Self, cFile, lView )
endif
else
if ValType( ::bSaveAsWord ) == 'B'
return Eval( ::bSaveAsWord, Self, cFile, lView )
endif
endif
oWord := WinWordObj()
if oWord == nil
lWordPDF := .f.
if lPDF
return FWSavePreviewToPDF( Self, cFile, lView )
ELSE
return ToWordDocViaWriter( Self, , "W" )
Endif
endif
nVer := Val( oWord:Version )
if lPDF
if nVer >= 12.0 .and. WordHasPDFPlugIn()
cExt := "*.pdf"
else
lWordPDF := .f.
return FWSavePreviewToPDF( Self, cFile, lView )
endif
else
cExt = If( nVer < 12.0, "*.doc", "*.docx; *.doc" )
endif
cMsg = If( lPDF, "PDF", "Doc" ) + " " + ;
FWString( "File to Save" ) + "( " + cExt + ") |" + cExt + "|"
if Empty( cFile ) .and. Empty( cFile := cGetFile( cMsg, FWString( "File to Save" ), 1, CurDir(), , .t. ) )
return nil
endif
if !( Lower( cFileExt( cFile ) ) $ cExt )
cFile = cFilePath( cFile ) + cFileNoExt( cFile ) + ;
If( lPDF, ".pdf", If( nVer < 12.0, ".doc", ".docx" ) )
endif
DEFAULT lView := MsgYesNo( FWString( "View" ) + " " + cFile + "?", FWString( "Please select" ) )
oDoc = ConvertToWordDoc( Self )
if oDoc != nil
TRY
oDoc:ExportAsFixedFormat( cFile, 17, lView )
CATCH
lWordPDF := .f.
// MsgInfo( FWString( "PDF Plugin Error" ), FWString( "Information" ) )
END
if lPDF
oDoc:Close( .f. )
if ! lWordPDF
// word failed to save as PDF due to PDF Plugin Error
return FWSavePreviewToPDF( Self, cFile, lView )
endif
else
if nVer >= 12.0
oDoc:SaveAs( cFile, If( Lower( cFileExt( cFile ) ) == 'doc', 0, 16 ) )
else
oDoc:SaveAs( cFile )
endif
if lView
oDoc:Application:Visible := .t.
else
oDoc:Close( .f. )
endif
endif
endif
return cFile