RFax requires:
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:
public java.awt.Image getFaxPage(int page);
You class must return a 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 scale 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:
2. Use faxModem to send the fax// 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
The second step is to create a faxModem object, 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);
}
}
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.