jacob.dll 不相容)jacob.jar + jacob.dll)jacob.dll 複製到 C:\Windows\System32(或 JVM java.library.path 目錄)。jacob.jar;同步將 jar、dll 放入 JRE/lib 或設定 -Djava.library.path。import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.*;
public class FaxSender {
public void sendFax(String filePath, String faxNumber) {
// 1. 連接 FAX 服務 (ProgID 需對應登錄表)
ActiveXComponent faxServer = new ActiveXComponent("FaxServer.FaxServer.1");
Dispatch faxObj = faxServer.getObject();
// 2. 開啟連線
Dispatch.call(faxObj, "Connect", "");
// 3. 建立文件物件
Dispatch doc = Dispatch.call(faxObj, "CreateDocument", filePath).toDispatch();
// 4. 設定收件資訊
Dispatch.put(doc, "RecipientName", "Someone");
Dispatch.put(doc, "FaxNumber", faxNumber); // 格式需符合 Modem 驅動要求
Dispatch.put(doc, "DisplayName", "SenderName");
// 5. 發送
Dispatch.call(doc, "Send");
// 6. 斷開
Dispatch.call(faxObj, "DisConnect");
}
public static void main(String[] args) {
try {
new FaxSender().sendFax("https://www.bt285.cn/WW.doc", "028886666");
System.out.println("ok fax transfer successfully!");
} catch (Exception e) {
e.printStackTrace();
}
}
}
| 錯誤 | 原因 | 解決 |
|---|---|---|
No ProgID / Can't create object | ProgID 錯誤或 Fax 服務未註冊 | 用 regedit 搜尋 FaxServer 確認正確 ProgID |
UnsatisfiedLinkError | jacob.dll 版本與 JDK/JRE 不匹配 | 換用 Jacob 1.9 + JDK 1.4~1.6,或升級 Jacob 至新版 |
| 傳真發送失敗 | Modem 不支援 Class 1/2 指令集 | 確認 Modem 驅動支援 Fax Class 1.0/2.0 |
Java → JNI → jacob.dll → Windows COM → FaxServer.FaxServer.1 (Windows Fax Service) → Modem 發送。適用於需整合傳統傳真伺服器的企業系統。