RFax 1.2.2

 

 

Introduction

RFax is a Java[TM] component that can send 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. On reception it will add some horizontal lines accross the page.

Installation

Installation of RFax is made of 2 steps:

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 following file: now you can send a test fax by doing this:

you can receive faxes by:

 


 

How to send faxes in your programs


The steps you must follow to send a fax are:

1. Implement the FaxProducer interface or use one of the existing providers

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

       public java.awt.Image getFaxPage(int page);

Your class must return an image object that contains the data to be faxed. The maximum size the image is 1728 x 2387. If you  use a size smaller than that you can use the scale 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. You must selec the resolution mode in FaxModem depending on the height of the image.

This is a simple implementation of a fax producer:

// FaxProducer Interface
public java.awt.Image getFaxPage(int page) {

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

// create an image and write something on it
  java.awt.Image i=this.createImage(800,1000);

 Graphics g=i.getGraphics();

 // clear background
   g.setColor(java.awt.Color.white);
   g.fillRect(0,0,pageImage.getWidth(null),pageImage.getHeight(null));
 
   g.setColor(java.awt.Color.black);
  g.setFont(new Font("Serif",Font.PLAIN,20));
  g.drawString("This is my first fax",100,100);

  return i;
 }


RFax also provides some ready to use faxProducers:

// acrobat fax producer
AcrobatFaxProducer pdf=new AcrobatFaxProducer();
pdf.setPDFFile("c:\\report.pdf");
pdf.pageImage=new java.awt.image.BufferedImage(800,1290,java.awt.image.BufferedImage.TYPE_INT_RGB);

// create html fax producer
producer p=new HtmlTextProducer();
String[] t= new String[2]; // 2 pages
t[0]="<HTML><BODY>page 1</BODY></HTML>";
t[1]="<HTML><BODY>page 2</BODY></HTML>";
p.text=t;
p.pageImage=this.createImage(800,1290); // create working image, it can also be a Buffered image
2. Use faxModem to send the fax

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

For example:

 
import java.awt.*;
import java.io.*;
import com.java4less.rfax.*;
import java.util.*;

public class Example extends Frame  implements FaxProducer {

 public static void main(String[] args) {
  Example c=new Example();
  c.setBackground(java.awt.Color.white);
  c.send();
 }

// faxProducer Interface
public java.awt.Image getFaxPage(int page) {

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

// create an image and write something on it
  java.awt.Image i=this.createImage(800,1000);

  Graphics g=i.getGraphics();

 // clear background
   g.setColor(java.awt.Color.white);
   g.fillRect(0,0,pageImage.getWidth(null),pageImage.getHeight(null));

  g.setColor(java.awt.Color.black);
  g.setFont(new Font("Serif",Font.PLAIN,20));
  g.drawString("This is my first fax",100,100);

  return i;
 }

// send fax
public void send() {

 FaxModem m=new FaxModem();
 m.setPortName("COM1");
 m.faxClass=2;

// set RtsCts flow Control
m.flowControl=FLOWCONTROL_RTSCTS;
// command required by the modem to set RtsCts flow control. This will depend on your Modem, check your modem manual.
m.ATFlowControlRTSCTS="AT&K3"; // another commoun command is AT\Q3

// set vertical resolution to 98 dpi (aprox. 1190 pixels)
m.resolution=m.RESOLUTION_NORMAL;

 m.open(this); // "this" implements fax producer
if (m.sendFax("123456789")) System.out.println("Success ***");
else System.out.println("Failure: " + m.lastError);

m.close();
System.exit(0);
}
}

 

How to receive faxes in your programs


The steps you must follow to receive faxes are:

1. Implement the IFaxReceiver interface

this interface is used to receive a notification when a fax has been received. The only function you must implement is:

public void faxReceived(String callerId, boolean success,String file,int pages);
2. Use FaxReceiverModem to wait for a fax

The second step is to create a FaxReceiverModem object  (or a FaxReceiverModemRXTX object for RXTX), set up port and modem configurations , and call the waitForFax() method.

For example:

 
import java.awt.*;
import java.io.*;
import com.java4less.rfax.*;
import java.util.*;

public class Example extends Frame  implements IFaxReceiver{

 public static void main(String[] args) {

 

FaxReceiverModem m= new FaxReceiverModem();
m.ATFlowControlRTSCTS="AT&K3";
m.flowControl=m.FLOWCONTROL_RTSCTS;
m.setPortName("COM3");
m.debug=true;
m.faxClass=1;
m.faxReceiver=new Example();
if (m.openReception()) m.waitForFax(); // the waitForFax() method will create a thread that will wait for faxes.


 }

// IFaxReceiver Interface
public void faxReceived(String callerId, boolean success,String file,int pages) {

System.out.println("");
System.out.println("Fax from " +callerId);
System.out.println("Success " +success);
System.out.println("File " +file);

 }

}

If you want to stop the thread that is listening to the modem and waiting for faxes, you must execute:

m.close();


Java, JSP, JDBC, JDK and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. J4L Components is independent of Sun Microsystems, Inc.