Code: Select all
#include "fivewin.ch"
function Main()
TPreview():bSaveAsPDF := { | oPreview | FWSavePreviewToPDF( oPreview ) }
XBrowse( "CUSTOMER.DBF" )
return nil
Code: Select all
#include "fivewin.ch"
function Main()
TPreview():bSaveAsPDF := { | oPreview | FWSavePreviewToPDF( oPreview ) }
XBrowse( "CUSTOMER.DBF" )
return nil
Code: Select all
// Generate a PDF from a PRINTER object without preview
#include "FiveWin.ch"
function Main()
local oPrn
PRINT oPrn PREVIEW NAME "ORCAM"
PAGE
oPrn:CmSay( 2, 2, "Hello world" )
ENDPAGE
oPrn:lMeta = .F.
ENDPRINT
FWSavePreviewToPDF( oPrn )
return nil
Code: Select all
METHOD SaveAs( lPDF, cFile, lView ) CLASS TPreview
CATCH
lWordPDF := .f.
// MsgInfo( FWString( "PDF Plugin Error" ), FWString( "Information" ) )
END
Code: Select all
METHOD SaveAs( lPDF ) CLASS TPreview
local oWord, nVer, oDoc
local cFile, cExt, cMsg, lView
if lPDF
if ValType( ::bSaveAsPDF ) == 'B'
return Eval( ::bSaveAsPDF, Self )
endif
else
if ValType( ::bSaveAsWord ) == 'B'
return Eval( ::bSaveAsWord, Self )
endif
endif
oWord := WinWordObj()
if oWord == nil
return FWSavePreviewToPDF( Self )
endif
nVer := Val( oWord:Version )
if lPDF
/*
if nVer < 12.0
MsgInfo( "This option requires Word 2007 or later" )
return nil
elseif !WordHasPDFPlugIn()
MsgInfo( "Download and Install" + CRLF + ;
"SaveAsPDF plugin from" + CRLF + ;
"Microsoft Office Online Website" )
return nil
endif
*/
if nVer >= 12.0 .and. WordHasPDFPlugIn()
cExt := "*.pdf"
else
return FWSavePreviewToPDF( Self )
endif
else
cExt := If( nVer < 12.0, "*.doc", "*.docx; *.doc" )
endif
cMsg := If( lPDF, "PDF", "Doc" ) + ;
" File to Save( " + cExt + ") |" + cExt + "|"
if Empty( cFile := cGetFile( cMsg, "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
lView := MsgYesNo( "View " + cFile + "?" )
oDoc := ConvertToWordDoc( Self )
if oDoc != nil
TRY
oDoc:ExportAsFixedFormat( cFile, 17, lView )
CATCH
MsgInfo( "PDF Plugin Error" )
END
if lPDF
oDoc:Close( .f. )
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 nil
Code: Select all
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