How to send fax in Java prog via astrsik & hylafax

Discussion in 'General' started by haamed, Oct 5, 2009.

  1. haamed

    Joined:
    Jul 23, 2007
    Messages:
    251
    Likes Received:
    0
    Hi my friends,

    I want to share my experience in sending fax via asterisk & Hylafax,
    you can use this tutorial on AsteriskNow, ELastix, Trixbox and ... any java programs

    at first you should know GNU-hylafax package,
    The GNU-HylaFAX package is a pure Java API designed to implement the client protocol portion of the hfaxd client-server protocol server.
    this is a website and you can download this java package from here[/list]

    it will help you to make hylafax job from your java codes at the follow there is a sample code to make a job on hylafax,
    this is my sendingFax.java class you can use this as exist but at fist don't forget to add gnu-hylafax jar file to your project,
    note: you can pass the parameter to this class or define them locally, all of them are String
    Code:
    
    package org.ivr.faxing;
    
    import java.io.IOException;
    import gnu.hylafax.*;
    import gnu.inet.ftp.FtpClientProtocol;
    
    public class faxSending {
    
    	public static String Send (String number, String notifyEmail, String Killtime, String MaximumDials, String MaximumTries, String Retrytime, String documentPath ) throws IOException{
    		String result = "sent";
    		try {
    
    		Client c = new HylaFAXClient();
            String host = "localhost";
            String user = "IranArgham";
    		
            //Open the host.
            c.open(host);
    	c.user(user);
            c.mode(FtpClientProtocol.MODE_ZLIB);
            c.type(FtpClientProtocol.TYPE_IMAGE);
            Job job = c.createJob();
            job.setFromUser("ivr");
            job.setNotifyAddress(notifyEmail);
            job.setKilltime(Killtime);
            job.setMaximumDials(Integer.parseInt(MaximumDials));
            job.setMaximumTries(Integer.parseInt(MaximumDials));
            job.setRetrytime(Retrytime);
            //The number to wish to fax
            job.setDialstring(number);
            //Path of pdf file, the root dir is your hylafax dir /var/spool/hyfalax
            job.addDocument(documentPath);
            //System.out.println("BIIIIB");
            c.submit(job);
    
    		} catch (Exception e) {
    	        e.printStackTrace();
    	        result = "ER";
    	}
    	return(result);	
    	}
    }//End class
    
    

    may be you get good idea to use this code in any java code,
    i hope it help you,

    GoodLuck
     

Share This Page