3

I'm trying to send a fax programatically with java by using the fax4j library (http://fax4j.sourceforge.net) and I am unfortunately unable to do so.

I used the sample code provided in the javadoc to try it and ended up modifying it to try and get a feel of the library.

This code WORKS, as in, the program complete its execution without throwing any exception, but it doesn't really send the fax, which is what I'm trying to achieve.

package com.myclasses;

import java.io.*;
import java.util.Properties;

import org.fax4j.FaxClient;
import org.fax4j.FaxClientFactory;
import org.fax4j.FaxJobStatus;
import org.fax4j.FaxJob;
import org.fax4j.FaxJob.FaxJobPriority;

public class MyTestClass
{
    public static void main(String[] args)
    throws InterruptedException, IOException
    {
        File file = new File("Drive:\\Directory\\MyFile.pdf");
        System.out.println("File Opened");

        FaxClient faxClient = FaxClientFactory.createFaxClient();
        System.out.println("Client created");

        System.out.println(faxClient.getProvider().getName());
        System.out.println(faxClient.getProvider().getDescription());

        FaxJob faxJob = faxClient.createFaxJob();
        System.out.println("Job Created");

        faxJob.setFile(file);
        System.out.println("file added");

        faxJob.setPriority(FaxJobPriority.HIGH_PRIORITY);
        System.out.println("priority set");

        faxJob.setTargetAddress(recipient);
        System.out.println("recipient set");

        faxClient.submitFaxJob(faxJob);
        System.out.println("Fax Job Sumbitted: " + faxJob.getID());


        while (faxClient.getFaxJobStatus(faxJob) == FaxJobStatus.PENDING)
        {
            System.out.println("STATUS: "
                + faxClient.getFaxJobStatus(faxJob).toString());

            for (int i = 0; i < 100; i++)
            {
                Thread.sleep(100);
                System.out.print(".");
            }
        }

        System.out.println("STATUS: "
            + faxClient.getFaxJobStatus(faxJob).toString());

    }
}

It does more or less exactly the same than the sample code except that it provides output to the console to mark the points.

I also added the loop at the end to periodically check on the job's status and keep the program running until the job is not "pending" any more. Since that doesn't happen, what I get is an endless loop.

Although quite complete, the javadoc is a bit obscure and difficult to wade through since I do not know exactly what I'm looking for. I couldn't find no tutorial online so any help would be greatly appreciated.

Or if someone knows of a fax sending app using fax4j of which the sources are available (even if it's just consultation only) that would be amazing because that way I could see how it is properly used.


EDIT

When I wrote the question first, I forgot to add a detail which, in retrospect may have some importance.

When the faxClient.sumbitFaxJob(faxJob) instruction is executed, Adobe Reader is opened but no file is loaded. But looking at the file history in Adobe Reader, I get that is is probably located in %HOMEDIR%\AppData\Local\Temp\long-randomly-generated-name.pdf (can't get the full directory with Adobe Reader and file is non-existant when I try to reload it).

Similarly, when I change the source file to a non-pdf, I get an exception within Java about a null file at %HOMEDIR%\AppData\Local\Temp called `fax4j_random-suite-of-digit.vbs :

Exception in thread "main" org.fax4j.FaxException: Error while invoking VBS script, error found at line 145: faxJobID=faxDocumentInstance.Send,  script output:
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation 1996-2001. Tous droits réservés.

[fax4j-vbs][DEBUG] Sending fax

Script error:
C:\Users\8809898B\AppData\Local\Temp\fax4j_1590168650663566246.vbs(145, 1) (null): Données non valides. 


at org.fax4j.spi.vbs.VBSFaxClientSpi.invokeScript(VBSFaxClientSpi.java:722)
at org.fax4j.spi.vbs.VBSFaxClientSpi.submitFaxJobImpl(VBSFaxClientSpi.java:416)
at org.fax4j.spi.AbstractFaxClientSpi.submitFaxJob(AbstractFaxClientSpi.java:204)
at org.fax4j.spi.adapter.AdapterFaxClientSpi.submitFaxJobImpl(AdapterFaxClientSpi.java:505)
at org.fax4j.spi.AbstractFaxClientSpi.submitFaxJob(AbstractFaxClientSpi.java:204)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.fax4j.spi.AbstractFaxClientSpiProxy.invoke(AbstractFaxClientSpiProxy.java:202)
at $Proxy0.submitFaxJob(Unknown Source)
at org.fax4j.FaxClient.submitFaxJob(FaxClient.java:211)
at com.myclasses.MyTestClass.main(MyTestClass.java:43)
2
  • Have you tried setting sender details to see if that makes a difference? I'm admittedly clutching at straws here and have no experience with this library, but just a thought. May 15, 2013 at 11:18
  • @berry120 I did and it produced no visible change (apart from being able to retrieve sender details with the get methods. :( May 15, 2013 at 12:11

1 Answer 1

0

i see you use windows so i suggest to use the windows SPI. basically you just need to make sure the fax4j.dll and fax4j.exe are on the native path (either set via java.library.path or windows PATH)

also acrobat is not a good third party when it comes to printing and has many issues. go to the official fax4j forum and you will see recommendation to other pdf readers that support better printing. with acrobat things won't work good.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.