RFax 1.1 for .NET

 

Introduction

RFax for .NET is a .NET (developed in C#) component that can send and receive faxes to any group 3 fax machine.

RFax requires:

About the evaluation version

The evaluation version will always insert a watermark on the top of your fax pages when sending and will print some horizontal lines when receiving.

Sample application

RFax comes with a simple application you can use to send your first fax. In order to start the application you must just unzip rfax and execute the file FaxTest10.exe (for .NET 1.0) or FaxTest11.exe (for .NET 1.1):

now you can send a test fax::

  1. enter port name (COM1, COM2...)
  2. select dialing mode (tone or pulse)
  3. select Flow Control (RTS/CTS recommended)
  4. select Flow Control Command ( normally AT&K3 fo RTS/CTS, see your modem's documentation).
  5. enter destination of fax
  6. press "Send fax"

or receive faxes::

  1. enter port name (COM1, COM2...)
  2. select Flow Control (RTS/CTS recommended)
  3. select Flow Control Command ( normally AT&K3 fo RTS/CTS, see your modem's documentation).
  4. press "Receive" to wait for a fax. Incomming faxes will be stored in the current directory as TIFF files.
  5. press "Stop" and "Quit" to finish receiving faxes.

 

How to send faxes in your programs


The steps you must follow to send a fax are:

1. Implement the faxProducer interface

this interface will provide RFax with the pages that must be send. The format of the interface is very simple:

       Bitmap getFaxPage(int page);

Your class must return a image object that contains the image to be faxed. The maximum size the image is 1728 x 2387. If you  use a size smaller than that you can use the scaleFactor feature of the t4Encoder in order to scale your image. The scaled image shall not be larger than the maximum size.

For example, if you image is 800 x 1000 and you set scale to 2, the final image will be 1600 x 2000.

This is a simple implementation of a fax producer:

[c#]

// faxProducer Interface

public Bitmap getFaxPage(int page) {

 // we send only 1 page
if (page>0) return null;

// create an image and write something on it
Bitmap i=new Bitmap(800,1000);

Graphics g=Graphics.FromImage(pageImage);

// clear image
g.Clear(Color.White);

 

// define font and color
SolidBrush textBrush=new SolidBrush(Color.Black);
Font textFont= new Font(new FontFamily("Arial"),12);

PointF textPos=new PointF(50,50);

// paint text on page
g.DrawString("MY FIRST FAX", textFont,textBrush, textPos);

return i;

}


RFax also provides some ready to use faxProducers:

 
2. Use faxModem to send the fax

The second step is to create a FaxModem object, set up port and modem configurations and call the sendFax() method.

For example:

 

[c#]


using J4L.RFax;

class MainClass
{


public static void Main(string[] args)
{

MainClass m=new MainClass();
m.sendFax();
}

public void sendFax() {

TextFaxProducer fp=new TextFaxProducer();

fp.textFont= new Font(new FontFamily("Arial"),28);
fp.text="This is my first fax";
fp.prepare();

FaxModem m=new FaxModem();
m.ATFlowControlRTSCTS="AT&K3";
m.flowControl=FaxModem.FLOWCONTROL_RTSCTS;
m.port="COM3";
m.faxClass=1;
m.bitRate=FaxModem.BITRATE_9600;
m.debug=true;


if (m.open(fp)) {
m.sendFax("12345");
}
m.close();

}


}

 

or if you implement your own FaxProducer:

 

[c#]


using J4L.RFax;

class MainClass: IFaxProducer
{


public static void Main(string[] args)
{

MainClass m=new MainClass();
m.sendFax();
}

 

public Bitmap getFaxPage(int page) {

// implement faxProducer Interface here

}

public void sendFax() {

FaxModem m=new FaxModem();
m.ATFlowControlRTSCTS="AT&K3";
m.flowControl=FaxModem.FLOWCONTROL_RTSCTS;
m.port="COM3";
m.faxClass=1;
m.bitRate=FaxModem.BITRATE_9600;
m.debug=true;


if (m.open(this)) {
m.sendFax("12345");
}
m.close();

}


}

 

FileImageFaxProducer (faxing PDF or HTML Files).

RFax includes a fax producer that can read image files (jpeg, png, gif....) and fax them. For example:

 

[c#]

string[] iFiles={"page1.gif","page2.gif"};
FileImageFaxProducer fp=new FileImageFaxProducer();
fp.files=iFiles;

FaxModem m=new FaxModem();
...
if (m.open(fp)) {
m.sendFax("**");
}

 

The FileImageFaxProducer is very simple, it just has a property called "files" which must contain the list of files to be faxes (each file/image in one page).

You can use this fax producer to fax PDF or HTML files, but first of all you must convert your PDF or HTML file an image/s. The product comes with 2 example classes that can do this. Both classes are located in the "source" subdirectory.

[c#]

PDF2Image p=new PDF2Image();
p.outputDirectory="c:\\images\\"; // directory where jpeg files will be created
p.ghostscriptDir="c:\\Program Files\\gs\\gs8.00\\bin\\"; // bin directory of the ghostscript installation

string[] iFiles=p.toJPEG("c:\\input.pdf"); // convert now

// now you can use the FileImageFaxProducer with the list of generated files.
FileImageFaxProducer fp=new FileImageFaxProducer();
fp.files=iFiles;

 

Example of use:

[c#]

// parameters are, input html (as url or file), page length in pixels, output directory and prefix for output png files.
string[] iFiles= Html2Image.toPNG("http://www.java4less.com",800,"c:\\images\\","out");

// now you can use the FileImageFaxProducer with the list of generated files.
FileImageFaxProducer fp=new FileImageFaxProducer();
fp.files=iFiles;

 

How to receive faxes

 

You can use the FaxTest.cs file as a reference if you want to receive faxes in your application. Faxes are always stored as TIFF files.

    The steps you must follow are:

    1. create a FaxReceiverModem. it is a subclass of the FaxModem class, which is used for reception.
    2. set port and flow control configuration.
    3. Implement the IFaxReceiver interface so that your application can receive an event when a fax is received.

Example:

m=new FaxReceiverModem();

m.flowControl=FaxModem.FLOWCONTROL_RTSCTS;
m.ATFlowControlRTSCTS="AT&K3";
m.bitRate=FaxModem.BITRATE_9600;

m.port="COM1";

((FaxReceiverModem) m).faxReceiver=this; // your class must implement the IFaxReceiver interface
if (((FaxReceiverModem) m).openReception()) ((FaxReceiverModem) m).waitForFax();

 

The IFaxReceiver only implements one method:

void faxReceived(string callerId, bool success,string file,int pages);

the parameters are selfexplaining:

 

API

 

FaxModem Properties:

 

FaxModem Methods:

FaxReceiverModem Properties (extends FaxModem)

FaxReceiverModem methods (extends FaxModem)

 

T4Encoder Properties

 

IFaxStatusListener

IFaxReceiver