Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


  • XFRX ships with its own report previewer. The previewer allows for:
  • Directing the report generation to the previewer or to preview an existing XFF file
  • Searching the document
  • Exporting the document to any of the supporting output formats
  • Printing the document
  • Navigation via hyperlinks and bookmarks
  • Invoking FoxBase code on hyperlink click (custom events)

The previewer is implemented as a container object, so it can be very easily added inside any VFP form.

Warning

XFF files don’t have to be stored as physical files. You can also create temporary XFF files that will be automatically released when you close the previewer. (Please see Creating temporary XFF files on page 45 for more information).


Table of Contents

Setting up the XFRX previewer

Info

This section has been added to reflect changes in XFRX ver. 11.3. If you are using previous XFRX versions, please see Using XFCont class paragraph below in this chapter.

There are several ways how you can setup the XFRX previewer. You can either use the already prepared standalone previewing component or start with the basic classes of the previewer component to add the previewing capabilities to your own forms.

The following subchapters describe using three classes implemented in XFRXLIB.VCX which you can use as a starting point to implement the XFRX previewer in your application:

 

frmMPPreviewer

cntXFRXMultiPage

XFCont

Implemented as a form (the easiest setup)

Yes

No

No

Implemented as a container (can be embedded into existing forms)

No

Yes

Yes

supports multi-tab interface

Yes

Yes

No

supports embedded toolbar

Yes

Yes

No

 

  • XFCont is the basic XFRX previewer class. It is implemented as a container object and supports searching, hyperlinks, bookmarks, printing and exporting.
  • cntXFRXMultiPage class extends the XFCont class functionality with multi-tab interface – it can display multiple previewer tabs in a page frame class. It also supports a (fake) embedded toolbar, which is a toolbar-like control at the top of the container, which is very useful if the previewer form is not inside the main VFP screen.
  • frmMPPreviewer is a form class that implements cntXFRXMultiPage and serves as a “proxy” to the cntXFRXMultiPage class features. If all you need is a full screen report previewer, this one is the easiest to setup.

Default settings


A new objects-type property has been added to the XFCont, cntXFRXMultipage and frmMPPreviewer classes:

NameDescriptionXFRX
version 
cImageFolder Folder with images for XFRX preview. 16.1.4 
oDisplayDefaultsDisplay default options. 
oPrinterOptionsPrint default options.17.0.0 
oExportOptionsExport default options.17.0.0
oEmailOptionsE-mail default options.17.0.0 

Object oDisplayDefaults has the following properties:

NameTypeDescriptionXFRX
version 
StartingPageinteger The 1st page to show in the previewer. Default value is 1.
DefaultOutputFileNamestring The default output file name when exporting from the previewer.
PagesPerSheetstring Encoded pages per sheet layout value. Default value: 1x1.
Allowed values: 1x1, 2x1, 2x2, 3x1, 3x2, 4x2.

ZoomFactorinteger the zoom factor. default value = 100. -1 = fit to width, -2 = fit page.
The zoom factor will be used only of PagesPerSheet is 1x1, otherwise it defaults to -2.

FindColor 

integerbackground color  of searched text17.0.0 


Example:

Code Block
linenumberstrue
m.loPreview = CREATEOBJECT("frmMPPreviewer")
m.loPreview.oDisplayDefaults.StartingPage = 2
m.loPreview.oDisplayDefaults.DefaultOutputFileName = "invoice15_09"
m.loPreview.oDisplayDefaults.ZoomFactor = -1
m.loPreview.oDisplayDefaults.PagesPerSheet = "1x1"
m.loPreview.PreviewXFF(loXFF)
m.loPreview.show(1)

Common methods and properties

Even though you can use different classes to provide the previewing capabilities in your application, all classes share most of the properties and methods you can use to control and customize them.

Controlling multi-tab preview features

Info

The properties and methods described in this paragraph are implemented in cntXFRXMultiPage and frmMPPreviewer classes. The multi-tab features are not implemented in XFCont class.


Property / Method

Usage

lShowTabForOneReport

(property)

Possible values:

  • .F. (default) – the tab with page captions is hidden if only one report is previewed. It will became automatically visible when the second report gets previewed.
  • .T. – the tab with page captions is always visible.

PreviewXFF

(method)

Syntax:

PreviewXFF(toXFF, tcCaption, tnPageNo)

Call this method to preview the XFF file in the previewer. You can call this method multiple times, which would either add new reports as new pages or replace existing pages, depending on parameters.

Parameters:

   toXFF

    The reference of a XFF file that is going to be previewed 

  tcCaption (optional)

The caption of the page with this report if previewing multiple reports. 

  tnPageNo(optional)

    The page on which the XFF file is going to be previewed. If this parameter is empty or greater than the number of existing pages, a new page is added. If a page with this number already exists, it will be replaced.

RemovePage

(method)

Syntax:

RemovePage(tnPageNo)

Removes a page from the previewer. 

Parameters:

  tnPageNo (optional)

    The number of the page to remove. If the parameter is empty or the number is greater than the number of existing pages, the last one is removed.

Registering an extension handler

The extension handler allows for extending the functionality of the basic classes without need of creating subclasses. All you need is to create a custom class, which implements certain methods. The custom class is registered with the XFRX previewer class (using SetExtensionHandler method) and the previewer calls the extension methods on appropriate events.

Currently supported event methods are:

Method

Usage

 Comment
KeyPress

This method is called from KeyPress() method od xfcont class.

Parameters:

   toXFF – the handler of the XFF file that is being previewed

   nKeyCode – Contains a number that identifies the key pressed

   nShiftAltCtrl - Sets a particular bit if a modifier key is held down while pressing the key specified by nKeyCode

 

 


Code Block
languagevb
title Example 1: Defining the export output options list, intercepting the XLS export
linenumberstrue
USE invoices ORDER customer
LOCAL m.loSession, m.lnRetval, m.loXFF, m.loPreview, m.loScripts
m.loSession=EVALUATE([xfrx("XFRX#LISTENER")])
m.lnRetVal = m.loSession.SetParams("",,,,,,"XFF") && no name = just in memory
IF m.lnRetVal = 0
   REPORT FORM invoices OBJECT m.loSession
             
   m.loXFF = m.loSession.oxfDocument
   *
   * initialize the previewer
   *
   SET CLASSLIB TO xfrxlib ADDITIVE
   m.loPreview = CREATEOBJECT("frmMPPreviewer")
   m.loPreview.setExtensionHandler(CREATEOBJECT("MyExtensionHandler"))
   m.loPreview.windowType = 0
   m.loPreview.iBook = 0
   m.loPreview.PreviewXFF(loXFF)
   m.loPreview.show(1)
ENDIF
 
 
DEFINE CLASS MyExtensionHandler AS Custom
 
   PROCEDURE Export
      LPARAMETERS m.toXFF
      IF USED("_xfExportTypes")
         USE IN _xfExportTypes
      ENDIF
      *
      * define my export options list
      *
      CREATE CURSOR _xfExportTypes (name C(50), extension C(4), targetCode C(10))
      INSERT INTO _xfExportTypes VALUES ("HTML",  "html",  "HTML")
      INSERT INTO _xfExportTypes VALUES ("PDF",   "pdf",   "PDF")
      INSERT INTO _xfExportTypes VALUES ("Excel", "xls",   "XLS")
   ENDPROC
 
   PROCEDURE ExportOptions
      LPARAMETERS m.toXFF, m.toOptions
      IF m.toOptions.cTarget = "XLS"
         *
         * my own code to handle output to Excel
         *
         =MESSAGEBOX("exporting to "+m.toOptions.cOutputFile)
         RETURN .F.   && suppress the default behavior
      ELSE
         RETURN .T.   && continue with the default behavior
      ENDIF
 
  ENDPROC

ENDDEFINE


Code Block
languagevb
titleExample 2
linenumberstrue
SET PATH TO xfrxlib
SET CLASSLIB TO xfrxlib
 
LOCAL m.loPreview, m.loSession, m.loExtensionHandler
 
m.loExtensionHandler = CREATEOBJECT("myExtensionHandler")
 
m.loPreview = CREATEOBJECT("frmMPPreviewer")
m.loSession=EVALUATE([xfrx("XFRX#LISTENER")])
 
*
* create a memory XFF file
*
m.lnRetVal = m.loSession.SetParams(,,,,,,"XFF")
IF m.lnRetVal = 0
   SELECT * ;
     FROM customers INNER JOIN orders ON customers.customerid = orders.customerid ;
                    INNER JOIN orderdetails ON orders.orderid = orderdetails.orderid ;
     orderORDER byBY customers.companyname, customers.customerID, orders.orderID ;
     INTO CURSOR custlist
           
   REPORT FORM custlist OBJECT loSession
ENDIF
 
*
* assign the extension handler
*
m.loPreview.setExtensionHandler(loExtensionHandler)
*
* preview the report
*
m.loPreview.previewXFF(m.loSession.oxfdocument)
m.loPreview.show(1)
 
DEFINE CLASS myExtensionHandler asAS CustomCUSTOM
   PROCEDURE Print
      LPARAMETERS m.toXFF
      RETURN .t. && continue with the default behavior
   ENDPROC
 
   PROCEDURE Export
      LPARAMETERS m.toXFF
      *
      * now you can process the XFF file
      *
      RETURN .F. && override the default behavior
   ENDPROC
ENDDEFINE


Code Block
languagevb
titleBeforeExport & AfterExport Example
linenumberstrue
useUSE demoreps\invoices orderORDER customer
localLOCAL m.loSession, m.lnRetval, m.loXFF, m.loPreview, m.loScripts
m.loSession=EVALUATE([xfrx("XFRX#LISTENER")])
m.lnRetVal = m.loSession.SetParams(,,,,,,"XFF") && no name = just in memory
IfIF m.lnRetVal = 0
   REPORT FORM demoreps\invoices object m.loSession		
   *
   * the XFRX#DRAW object reference is stored in oxfDocument property
   *
   m.loXFF = m.loSession.oxfDocument
   *
   * initialize the previewer 
   *
   SET PATH TO xfrxlib
   SET CLASSLIB TO xfrxlib ADDITIVE 
   m.loPreview = CREATEOBJECT("frmMPPreviewer")
   *
   * setup the extension handler
   *
   m.loPreview.oExtensionHandler = CREATEOBJECT("SampleExtensionHandler")
   m.loPreview.windowtype = 1 
   m.loPreview.iTool = 2 && embedded toolbar
   m.loPreview.PreviewXFF(m.loXFF)
   m.loPreview.show(1)
ENDIF

DEFINE CLASS SampleExtensionHandler as Custom

   PROCEDURE BeforeExport
      LPARAMETERS m.toSession, m.toExportParameters

      m.toSession.setAuthor("Martin") && set the document author property
      IF m.toExportParameters.cTarget = "XLS" && (XLS or XLSPLAIN)
	 
         m.toSession.SetOtherParams("DISPLAY_GRID_LINES",.F.) && do not display gridlines in excel
      ENDIF
   ENDPROC


   PROCEDURE AfterExport
      LPARAMETERS m.toSession, m.toOptions
      IF m.toOptions.cTarget = "XLS"
         *COPY FILE (m.toOptions.coutputfile) TO ([anybackupfolder]\[anyfile.xls])
      ENDIF
   ENDPROC
	

ENDDEFINE 


Code Block
titleKeyPress example
linenumberstrue
useUSE demoreps\invoices orderORDER customer
localLOCAL m.loSession, m.lnRetval, m.loXFF, m.loPreview, m.loScripts
m.loSession=EVALUATE([xfrx("XFRX#LISTENER")])
m.lnRetVal = m.loSession.SetParams(,,,,,,"XFF") && no name = just in memory
IfIF m.lnRetVal = 0
   REPORT FORM demoreps\invoices objectOBJECT m.loSession		
   *
   * the XFRX#DRAW object reference is stored in oxfDocument property
   *
   m.loXFF = m.loSession.oxfDocument
   *
   * initialize the previewer 
   *
   SET PATH TO xfrxlib
   SET CLASSLIB TO xfrxlib ADDITIVE 
   m.loPreview = CREATEOBJECT("frmMPPreviewer")
   *
   * setup the extension handler
   *
   m.loPreview.oExtensionHandler = CREATEOBJECT("SampleExtensionHandler")
   m.loPreview.windowtype = 1 
   m.loPreview.iTool = 2 && embedded toolbar
   m.loPreview.PreviewXFF(loXFF)
   m.loPreview.show(1)
ENDIF

DEFINE CLASS SampleExtensionHandler asAS CustomCUSTOM

   PROCEDURE KeyPress(m.loXFCont, m.nKeyCode, m.nShiftAltCtrl)
      * hotkey for print P (112-p, 80-P)
      IF INLIST(m.nKeyCode, 112, 80)
         m.loXFCont.Print()
      ENDIF
   ENDPROC


 ENDDEFINE 

Showing / hiding bookmarks

The bookmark panel behavior is controlled by the iBook property:

Property

Usage

iBook

Controls if the bookmark should be displayed in the previewer. The allowed values are:

  • -1 = Disable bookmarks
  • 0 = Enable bookmarks but hide them (users need to click on the bookmark button to see them)
  • 1 = Enable bookmarks, always showing them (default)
  • 2 = Enable bookmarks, but show or hide them automatically based on whether or not there are bookmarks defined in the report to preview (default)

Showing / hiding previewer toolbars

There are two toolbars in the previewer control – one is placed at the bottom of the control, the other one is available as a floating toolbar panel, which by default docks at the top of the main window, or, alternatively, as an “embedded toolbar”. All three classes implement iTool and ShowStatus properties that control visibility of the toolbars:

Property

Usage

classMainToolbar

The class name of the toolbar. The default value is “xfrxToolbar”. You can create a child of the default xfrxToolbar class (defined in xfrxlib.vcx) and use this property to instruct the previewer to use your class rather than the default one.

This property works for the “real” toolbar – if iTool property is 0 or 1. if iTool is set to 2, cmdEmbeddedToolbar container class is used as the “embedded” toolbar.

iTool

Controls the visibility of the toolbar at the top. The allowed values are:

  • -1 = Disable toolbar
  • 0 = The toolbar will be enabled but hidden. It can be invoked via right click shortcut menu
  • 1 = The toolbar will be enabled and visible. (default)
  • 2 = The toolbar will be displayed as embedded to the form (available only in cntXFRXMultiPage and frmMPPreviewer classes.

ShowStatus

Controls the visibility of the toolbar at the status bar of the previewer container. The allowed values are:

  • .T. = show the toolbar (default)
  • .F. = hide the toolbar

Displaying progress bar 

 

PropertyUsage
oprogressThe object instance of XFRX progress bar


Code Block
linenumberstrue
useUSE demoreps\invoices orderORDER customer
localLOCAL m.loSession, m.lnRetval, m.loXFF, m.loPreview, m.loScripts
m.loSession=EVALUATE([xfrx("XFRX#LISTENER")])
m.lnRetVal = m.loSession.SetParams(,,,,,,"XFF") && no name = just in memory
IfIF m.lnRetVal = 0
   REPORT FORM demoreps\invoices objectOBJECT m.loSession		
   *
   * the XFRX#DRAW object reference is stored in oxfDocument property
   *
   m.loXFF = m.loSession.oxfDocument
   *
   * initialize the previewer 
   *
   SET PATH TO xfrxlib
   SET CLASSLIB TO xfrxlib ADDITIVE 
   m.loPreview = CREATEOBJECT("frmMPPreviewer")
   *
   * setup the extension handler
   *
   m.loPreview.oExtensionHandler = CREATEOBJECT("SampleExtensionHandler")
   m.loPreview.oprogress=createobject("progress")
   m.loPreview.PreviewXFF(loXFF)
   m.loPreview.show(1)
ENDIF

defineDEFINE classCLASS progress asAS customCUSTOM
   procedurePROCEURE updateProgress
      lparaLPARAM m.ta,m.tb, m.tc
      waitWAIT windowWINDOW nowaitNOWAIT "Page #: "+alltALLT(strSTR(m.tb))+" Report #: "+alltALLT(strSTR(m.ta))+" ("+alltALLT(strSTR(m.tc))+"%)"
   ENDPROC
enddefENDDEF

Using frmMPPreviewer class

This class serves as a standalone (fullscreen) previewer window. All you need to do to make it work is to pass it a reference to the XFF file to preview, using the previewXFF method, as described in Controlling multi-tab preview features paragraph above. (If you are not sure how to create a XFF file reference, please read chapters 17.0: Initializing the XFRX#DRAW class instance and 16.3: Creating temporary XFF files). Here is a very simple “Hello World” example:

Code Block
linenumberstrue
LOCAL m.loPreview
SET CLASSLIB TO XFRXLIB.VCX ADDITIVE 
m.loPreview = CREATEOBJECT("frmMPPreviewer") && create the previewer object
toViewer
m.loPreview.previewXFF(m.loXFF)                 && loXFF is XFF file reference
m.loPreview.show(1)                          && show the form as modal


Info

Make sure to set all properties (like iTool, ShowStatus, etc.) before you call PreviewXFF(…) otherwise they won’t be used.

Using cntXFRXMultiPage class

  1. Add an instance of cntXFRXMultiPage class (of XFRXLIB.VCX) into your form. Adjust the size of the cntXFRXMultiPage class object container as you need. The previewer, including the status bar, icons and scroll bars will be displayed in the container. If you resize the container in runtime, its content is automatically adjusted.
  2. When the form is about to be released, the cntXFRXMultiPage class instance needs to do some cleanup. To enable that please call the class instance’s clearLink() method from form’s destroy method:

    Code Block
    linenumberstrue
    procedurePROCEDURE Destroy
        thisformThisform.cntXFRX.clearLink()
    endprocENDPROC


  3. When running the form, make sure the XFRXLIB.VCX class library is referenced in SET CLASSLIB command:

    Code Block
    SET CLASSLIB TO XFRXLIB.VCX ADDITIVE


  4. Call the PreviewXFF method to preview a XFF file, as described in Controlling multi-tab preview features paragraph above.
  5. By default, cntXFRXMultiPage is using an instance of the XFCont class for each page. Should you like to make it use a different class (eg. a subclass of XFCont) put the class name to the ClassPreviewPage property of the cntXFRXMultiPage instance.

Using XFCont class

  1. Add an instance of XFCONT class (of XFRXLIB.VCX) into your form. Adjust the size of the XFCONT class container as you need. The previewer, including the status bar, icons and scroll bars will be displayed in the container. If you resize the container in runtime, its content is automatically adjusted.
  2. When the form is about to be released, the XFCONT class instance needs to do some cleanup. To enable that please call the XFCont class instance’s clearLink() method from form’s destroy method:


    PROCEDURE
    procedure
    Code Block
    linenumbers
    true
    PROCEDURE Destroy
        thisformThisform.cntXFRX.clearLink()
    endproc ENDPROC


  3. When running the form, make sure the XFRXLIB.VCX class library is referenced in SET CLASSLIB command:

    Code Block
    SET CLASSLIB TO XFRXLIB.VCX ADDITIVE


VFP 8.0 approach

In VFP 8.0, there are two options how to preview report in the previewer. The options differ in the calling mechanism, although internally they both work exactly the same.

15.1.5.1.1 Generating the “CNT” output type

The approach is using the standard syntax of calling XFRX, without explicitly using the XFRX#DRAW class (although it is used in the background). You cannot open an existing XFF file with this approach – you always need to run a report that will be previewed.

  1. Do not send anything as the output file name
  2. Use “CNT” as the output type parameter in the SetParams method call
  3. Call Reset method of the previewer container class
  4. Call SetOtherParams method of the XFRXSession class instance with the reference of XFCont instance as a parameter

 

Example:

Code Block
languagevb
linenumberstrue
localLOCAL m.loSession, m.lnRetval
loSession= xfrx("XFRX#INIT")
m.lnRetVal = m.loSession.SetParams(,,,,,,"CNT")
IF m.lnRetVal = 0
   *
   * we are assuming the XFCont container is
   * available as thisform.cntXFRX
   *
   thisformThisform.cntXFRX.reset()
   m.loSession.setotherparams(thisformThisform.cntXFRX)
   m.loSession.ProcessReport("report")
   m.loSession.finalize()
ENDIF
Using the XFRX#DRAW class

The advantage of this method is that you can preview an existing XFF file – the XFF file is opened and “converted” to “CNT” output type via the TransformReport method:

Example:

Code Block
languagevb
linenumberstrue
LOCAL m.loSession
m.loSession= xfrx("XFRX#INIT")
loReportThisform.oReport = xfrx("XFRX#DRAW")
IF thisformThisform.oReport.openDocument("file.xff")
   thisformThisform.cntXFRX.reset()
   m.lnRetVal = m.loSession.SetParams(,,,,,,"CNT")
   IF m.lnRetVal = 0
      m.loSession.setOtherParams(thisformThisform.cntXFRX)
      m.loSession.TransformReport(thisformThisform.oReport)
   ENDIF
ENDIF

VFP 9.0 Approach

In VFP 9.0 the logic is the same, just the syntax is a little bit different – the reference to the XFCont object is copied to XFRXPreviewer property of the XFRXListener class instance and then previewReport method with the XFRX#DRAW reference as parameter is called:

Code Block
languagevb
linenumberstrue
LOCAL m.loSession
m.loSession= xfrx("XFRX#LISTENER")
thisformThisform.oReport = xfrx("XFRX#DRAW")
IF thisformThisform.oReport.openDocument("file.xff")
   thisformThisform.cntXFRX.reset()
   m.loSession.XFRXPreviewer = thisformThisform.cntXFRX
   m.loSession.previewReport(thisformThisform.oReport)
ENDIF

Hyperlink decoration

A new property has been added to the XFCont, cntXFRXMultipage and frmMPPreviewer classes: UnderlineHyperlinksOnPrint. You can use the following values:
0 - no decoration for hyperlinks
1 - display "normal" hyperlinks in blue, but do not decorate custom event hyperlinks (green)
2 - (default value) decorate both blue and green hyperlinks

To support this in the print output, the PrintDocument method of the XFRX#DRAW class has a new parameter, tnUnderlineHyperlinksOnPrint, with the same values and logic.

Custom buttons

This feature is implemented using the extension handler mechanism: A new method is now supported - ToolbarOnInit, which is invoked at the time the toolbar is initialized. In this method the extension handler can add new buttons to the previewer and their click events can be bound with other methods in the extension handler. A new property is now supported, too - oPreviewContainer. If it is available, the previewer will automatically fill it with the XFCont object reference for easier access to the previewer properties in the custom buttons click event methods.

Example:


Code Block
languagevb
linenumberstrue
useUSE demoreps\sales
localLOCAL m.loSession, m.lnRetval, m.loXFF, m.loPreview, m.loScripts
m.loSession=EVALUATE([xfrx("XFRX#LISTENER")])
m.lnRetVal = m.loSession.SetParams(,,,,,,"XFF") && no name = just in memory
IF m.lnRetVal = 0
   REPORT FORM demoreps\sales objectOBJECT m.loSession
   *
   * the XFRX#DRAW object reference is stored in oxfDocument property
   *
   m.loXFF = m.loSession.oxfDocument
   *
   * initialize the previewer
   *
   SET PATH TO xfrxlib
   SET CLASSLIB TO xfrxlib ADDITIVE
   m.loPreview = CREATEOBJECT("frmMPPreviewer")
   *
   * setup the extension handler
   *
   m.loPreview.oExtensionHandler = CREATEOBJECT("SampleExtensionHandler")
   m.loPreview.windowtype = 1
   m.loPreview.iTool = 2 && embedded toolbar
*    *m.loPreview.iTool = 1 && standard toolbar
   m.loPreview.PreviewXFF(m.loXFF)
   m.loPreview.show(1)
ENDIF
 
DEFINE CLASS SampleExtensionHandler asAS CustomCUSTOM
 
   oPreviewContainer = null.NULL.
 
   PROCEDURE ToolbarOnInit
      LPARAMETERS m.toToolbar
      LOCAL m.button
      IF m.toToolbar.AddObject("mybutton", "commandbutton")
         BINDEVENT(m.toToolbar.mybutton, "click" , thisThis, "ButtonClicked")                       
         m.toToolbar.mybutton.tabindex = 1
         m.toToolbar.mybutton.Visible = .t.
         IF UPPER(m.totoolbar.BaseClass)!="TOOLBAR"
            m.toToolbar.mybutton.left = m.toToolbar.cmdQuit.left
            m.toToolbar.cmdQuit.left = m.toToolbar.mybutton.left + m.toToolbar.mybutton.width
         ENDIF                           
      ENDIF
   ENDPROC
 
   PROCEDURE ButtonClicked
      LOCAL m.lcString
      m.lcString = "thisThis.oPreviewContainer.Name: "+thisThis.oPreviewContainer.Name+CHR(13)
      m.lcString = m.lcString + "current page: "+TRANSFORM(thisThis.oPreviewContainer.nPageNo)+CHR(13)
      m.lcString = m.lcString + "XFRX#DRAW Object: "+thisThis.oPreviewContainer.oXFRXWriter.Name+CHR(13)
      m.lcString = m.lcString + "Page count: "+TRANSFORM(thisThis.oPreviewContainer.oXFRXWriter.PageCount)+CHR(13)
      WAIT WINDOW m.lcString
   
*      this*This.oPreviewContainer.oXFRXWriter.PrintDocument(...)
*      this*This.oPreviewContainer.oXFRXWriter.SavePicture(...)
   ENDPROC

ENDDEFINE


Printing from the previewer

By default, when users click the “Print” button in the previewer toolbar (), the Print method of the XFCont class is called. This method displays a dialog box with a printer selection and allows for entering a page range:


When a XFF file is previewed, the corresponding XFRX#DRAW reference is accessible via oXFRXWriter property of the previewer class instance.

If you would like to change the way the previewer reacts to the print event, you can either setup an extension handler (please see Registering an extension handler paragraph above in this chapter for more information) . There are three events that extension handler can implement:


NameDescriptionXFRX
version

Print

This method is called when the Print button is clicked in the toolbar.

Parameters:

     toXFF – the handler of the XFF file that is being previewed

 
BeforePrintOptions 

This method is called before the Printer Options dialog is opened.

Parameters:
   toXFF – the handler of the XFF file that is being previewed
   toParameters – the object containing the print options

 
16.1

PrintOptions

This method is called after the Printer Options dialog is closed, before the actual print.

Parameters:
   toXFF – the handler of the XFF file that is being previewed
   toParameters – the object containing the print options

 


The print parameter object has the following methods:

NameDesccriptionXFRX
version
ReadDEVMODE
Read DEVMODE data for selected printer by PrinterName property. 17.0.0
SetFieldSet field of DEVMODE data  for selected printer by PrinterName property. 
Parameters:
   tcField – Field name, such as "DM_COLOR", "DM_PRINTQUALITY" etc.
   tuValue – Fields' value
17.0.0


The print parameter object has the following properties:


NameType DesccriptionXFRX
version

AllOddEven

numberInclude all pages, odd or even only.  The allowed values are:

   1 ... all pages (default value)
   2 ... odd pages
   3 ... even pages


CopiesnumberThe number of copies.
Zoomnumber

The number of pages per sheet.


lShowDialog boolean Specifies whether a XFRX call "Print options" dialog. 17.0.0
PrinterNamestring The name of the printer to which the document will be sent.
PageRangestringEnter page numbers and/or page ranges separated by commas (e.g. 3,4,5-9 or CURRENT (page)).
cDevmodestring DEVMODE structure. 
lPrintbooleanSpecifies whether a XFRX call PrintDocument() method.17.0.0
cOutputFilestring Output file name for XPS Microsoft Document Writer or another PDF virtual driver.17.0.0
aFindStringarray A array contains strings for  highlight. The array  can has one column - than  background color will be yelow for all strings. Or cab has two columns - than second column contains background color for string.17.0.0


The printer job name generated by the Print method is stored in cJobName property of the XFCont class and can be changed both in design time and runtime. (The default value is “XFRX”).

See also: Printing XFF files chapter on page 46 for more information about printing the content of XFF files.

Exporting reports from the previewer

Similarly to printing, when users click the “Export” button in the previewer toolbar (), the Export method of the XFCont class is called. This method displays a dialog box with output type and a file name selection and converts the XFF file that is being previewed to the output document:

If you would like to create your own custom exporting solution, you can either setup an extension handler (please see Registering an extension handler paragraph above in this chapter for more information) or you can create a child of the XFCont class and override the Export method.  There are five events that extension handler can implement:

NameDescriptionXFRX
version
BeforeExport    

The method is executed right before the report is exported to the output format and can be used to parametrize the xfrx session object before exporting.

Parameters:
   toXFF – the handler of the XFF file that is being previewed
   toParameters – the object containing the export options

 
AfterExport

The method is executed right after the report is exported to the output format and can be used to copy output file to another folder.

  Parameters:
   toXFF – the handler of the XFF file that is being previewed
   toParameters – the object containing the export options 

 

Export

This method is called when the Export button is clicked in the toolbar.

Parameters:
    toXFF – the handler of the XFF file that is being previewed

 
BeforeExportOptions 

This method is called before the Export Options dialog is opened.

Parameters:
   toXFF – the handler of the XFF file that is being previewed
   toParameters – the object containing the export options 

16.1 

ExportOptions

This method is called after the Export Options dialog is closed, before the actual Export is executed

Parameters:
   toXFF – the handler of the XFF file that is being previewed
   toParameters – the object containing the export options

 

The export parameter object has the following properties:

NameTypeDescription GroupXFRX
version
cTarget string XFRX output type. General
cPageScopestringEnter page numbers and/or page ranges separated by commas (e.g. 3,4,5-9).General
cOutputFile string Output  file.General
lNotOpenFileboolean Specifies whether a XFRX open file after creating.General16.1.0
lShowDialog boolean Specifies whether a XFRX call "Print options" dialog. General17.0.0
lExportbooleanSpecifies whether a XFRX export to output.General 17.0.0
     

AllOddEven

numberInclude all pages, odd or even only.  The allowed values are:

   1 ... all pages (default value)
   2 ... odd pages
   3 ... even pages

Image 
CopiesnumberThe number of copies.Image
Zoomnumber

The number of pages per sheet.

Image
ImageDPI number

Image DPI.

Image  
aFindStringarray A array contains strings for  highlight. The array  can has one column - than  background color will be yelow for all strings. Or cab has two columns - than second column contains background color for string.Image17.0.0
     
nAppendMode number 

Append mode for PDF, RTF, FRTF and PLAIN.  The allowed values are:
  1 ... Append to end
  2 ... Insert at the beginning
  3 ... Replace (document)
  4 ... Insert from page
  5 ... Replace page(s) from:

Append mode16.1.0
nAMFromPage number 

 For nAppendMode 4 - The generated report will be inserted to the existing document at the given page number.

 For nAppendMode 5 - first page for replacing in original document.

Append mode16.1.0
nAMToPagenumber  For nAppendMode 5 - last page for replacing in original document.Append mode16.1.0
     
cArchivestringArchive (zip) file name.Archive16.1.0
lArchiveAdditivebooleanAppend to archive.Archive 16.1.0
lArchiveDeleteFileAfter boolean Delete file(s) after creating archive.  Archive 16.1.0

E-mail support in the XFRX previewer

An email icon has been added to the XFRX previewer toolbar. It is disabled by default for backward compatibility and can be enabled by setting the iEmail property of the previewer class [xfCont, cntXFRXMultiPage or frmMPPreviewer] to 1. If you click the email icon, it runs the Email method of the xfCont class. By default it displays a simple dialog box asking for email address, subject, body, etc. and uses VFPWinsock library to send the email.


Info

VFPWinsock is a free SMTP sendmail library written by a VFP MVP Francis Faure. It is not distributed together with XFRX and it can be downloaded from http://www.xfrx.net/vfpWinsock/index_e.asp. It is a nice little package written in VFP distributed as a single .prg.


The default behavior can be intercepted or overridden by an extension handler [Please find more information about extension handlers at 18.1.2.2 Registering an extension handler] - and, as the default dialog does not ask for all information VFPWinsock needs (eg. it does not ask for SMTP host) you actually need to create an extension handler to make it work in your environment. There are three events that extension handler can implement:

NameDescriptionXFRX
version 
BeforeEmailOptions

The event is fired before the dialog is displayed and user clicked "Send".
XFF file reference and options object is sent as a parameter.
Returning .F. will suppress the email to be sent.

Parameters:
   toXFF – the handler of the XFF file that is being emailed
   toParameters – the object containing the email options

 
EmailOptions

The event is fired after the dialog is displayed and user clicked "Send".
XFF file reference and options object is sent as a parameter.
Returning .F. will suppress the email to be sent.

Parameters:
   toXFF – the handler of the XFF file that is being emailed
   toParameters – the object containing the email options

 
Email

The event is fired when the icon is clicked, before the dialog is displayed.
XFF file reference, options object and progress object is sent as a parameter. 
If extension handler object has not Email event., then XFRX try run vfpWinsock automatically.

Parameters:
   toXFF – the handler of the XFF file that is being emailed
   toParameters – the object containing the email options.
   toProgress - XFRX progress objects.

 
Email_BeforeTransportReport

The event is fired before calling method TransformReport().
Parameters:
   toSession – the handler of the XFRX#SESSION object.
   toParameters – the object containing the email options.
     

17.0.0
Email_AfterTransportReportThe event is fired after calling method TransformReport().
Parameters:
   toSession – the handler of the XFRX#SESSION object.
   toParameters – the object containing the email options. 
17.0.0


The e-mail parameter object has the following properties:

Name

TypeDescriptionXFRX
version 

cSMTP_HOST

string SMTP host.

nSMTP_PORT

integerSMTP port, default value is 25.17.0.0

cAUTH_Login

string

ESMTP Login.

17.0.0 

cAUTH_Password

string ESMPT password.17.0.0

cFrom

string From email address.

cFROM_Name

string From email name.17.0.0

cTo

stringTo email address.

cTO_Name

string To email name.17.0.0

cCC

string Carbon copy  email address. 

cCC_Name

string Carbon copy  email name.17.0.0

cBCC

string Blind carbon copy  email address.

cBody

string Message as text.

cBodyHTML

string Message as HTML17.0.0

cDATA_MHTML 

string File name with MTH data. 17.0.0 

cSubject

string Subject.

cCodePage

stringCode page for subject, from name, message etc. Default value is "iso-8859-1".
But you can set "windows-1250" or "windows-1252". 
17.0.0
lSendbooleanSpecifies whether a XFRX call event Email or vfpWinsock.
lShowDialog boolean Specifies whether a XFRX call "E-mail options" dialog. 17.0.0


Following are sample of the two most common scenarios:

Suppress the default behavior and handle the email event on your own


Code Block
languagevb
linenumberstrue
LOCAL m.loPreview
m.loPreview = CREATEOBJECT("frmMPPreviewer")
m.loPreview.iEmail = 1 && show the email icon
m.loPreview.oExtensionHandler = CREATEOBJECT("SampleExtensionHandler")
m.loPreview.PreviewXFF(LOCAL m.loXFF) && preview the document 
m.loPreview.show(1)
 
DEFINE CLASS SampleExtensionHandler asAS CustomCUSTOM
 
   PROCEDURE Email
      LPARAMETERS  m.loXFF[, [m.opt[, m.oProgress]]
      * loXFF - XFF file reference
      * m.opt - email options (since XFRX 17.0.0)
      * m.oProgress - XFRX progress object (since XFRX 17.0.0)
      LOCAL m.loSession, m.lcFileName
      m.loSession=EVALUATE([xfrx("XFRX#INIT")])
      m.lcFileName = Addbs(Sys(2023))+"test.pdf" && temporary file name
      IF m.loSession.SetParams(m.lcFileName,,.T.,,,,"PDF") = 0 && the 3rd parameter says we do not want to preview the PDF
         m.loSession.TransformReport(m.loXFF)
      
         LOCAL m.sm
         SET PROCEDURE TO vfpwinsock ADDITIVE 
         m.sm = Createobject("vfp_winsock_send_mail")
         m.sm.smtp_host = "your.smtp.server.here" &&&<<<<<<<<<<<<<<<<<<<< put your smtp server here
         m.sm.From = "eqeus@eqeus.com" 
         m.sm.To = "eqeus@eqeus.com"
         m.sm.subject = "Email test"
         m.sm.silence = .T.
         m.sm.attaCHMENT = m.lcFileName
         IF !m.sm.Send()
            =MESSAGEBOX(m.sm.erreur,16,"xfrx test")
         ELSE
            =MESSAGEBOX("Message was sent",0,"xfrx test")
            ERASE (m.lcFileName)
         ENDIF
      ENDIF 
      RETURN .F.
   ENDPROC
 
ENDDEFINE



Use the default dialog box, use an extension handler to supply mail server parameters and let XFRX send the email

  

Code Block
languagevb
linenumberstrue
DEFINE CLASS SampleExtensionHandler asAS CustomCUSTOM
 
   PROCEDURE EmailOptions
      LPARAMETERS  m.loXFF, m.loOptions
      m.loOptions.cSMTP_HOST = "mail.your_domain.com"
      m.loOptions.cFrom = "eqeus@eqeus.com"
   ENDPROC
 
ENDDEFINE

Previewer localization

Each localization is stored in two files:

  • XFRXLIB_<localization_code>.dbf - strings translation
  • XFRXLIB_<localization_code>.vcx - find and page selection dialogs localization

The default localization is English. Another localization are CSY - Czech, SK - Slovak, FR - French, DE - Germany, TR - Turkey.  

To create a new localization, please follow these steps:

  1. Choose a code for your localization (e.g. DE for German)
  2. Create a copy of default localization DFB (localization\default\XFRXLIB_XXX.DBF (+CDX, +FPT)). Change the suffix according to your localization code. The default localization DBF contains English strings that need to be translated.
  3. Create XFRXLIB_<localization_code>.vcx visual class library using localization\default\locClass.prg. Send the localization code as a parameter. 
    Example: Copy locClass to the XFRXLIB directory and call:

    Code Block
    do locClass with "DE" 


which will create the XFRXLIB_DE class library. Translate the two dialog classes in the class library.

  1. Copy the localization files to XFRXLIB directory.

To activate the localization in your code, call setLanguage method of XFCont class. Send the localization code as a parameter.

Example:

Code Block
thisThis.cntXFRX.setLanguage("DE")

Error Logging

You can use method setLogFile() for create log (since XFRX 15.5).

 
Code Block
=m.loPreview.setLogFile(<tcLogFile>)
 
Parameters:
 tcLogFile
   the name of the log file to create.