JodConverterの問題
-
11-12-2019 - |
質問
JodConverter Library V 3.0 Beta 4をOpen Office 3.4とともに使用しています。ファイルをPDF / A-1形式に変換しようとしています。ただし、Office Managerプロセスが起動した後、それは単にハングアップし、何も起こりません。これが出力:です
Jul 26, 2012 12:04:03 PM org.artofsolving.jodconverter.office.ProcessPoolOfficeManager <init>
INFO: ProcessManager implementation is PureJavaProcessManager
C:\Users\Chris\AppData\Local\Temp\ArFile\PDF\blah.pdf : C:\Users\Chris\Documents\blah.txt
Jul 26, 2012 12:04:04 PM org.artofsolving.jodconverter.office.OfficeProcess start
INFO: starting process with acceptString 'socket,host=127.0.0.1,port=2002,tcpNoDelay=1' and profileDir 'C:\Users\Chris\AppData\Local\Temp\.jodconverter_socket_host-127.0.0.1_port-2002'
Jul 26, 2012 12:04:04 PM org.artofsolving.jodconverter.office.OfficeProcess start
INFO: started process
.
真ん中の線は、出力ファイル名とコロンで区切られた入力ファイル名を印刷すると、それらが有効な値...
これは私のコンバータクラスです:
package com.allcare.arfile;
import com.sun.star.beans.PropertyValue;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import org.artofsolving.jodconverter.OfficeDocumentConverter;
import org.artofsolving.jodconverter.document.DocumentFamily;
import org.artofsolving.jodconverter.document.DocumentFormat;
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration;
import org.artofsolving.jodconverter.office.OfficeManager;
public class FileConverter
{
OfficeManager officeManager;
String tempFilePath;
public FileConverter()
{
officeManager = new DefaultOfficeManagerConfiguration()
//.setRetryTimeout(30000L)
//.setTaskExecutionTimeout(60000L)
.buildOfficeManager();
tempFilePath = System.getProperty("java.io.tmpdir") + "\\ArFile\\PDF\\";
}
// if possible this function converts a file to a PDF/A-1 compliant file
public File convertToPdf(File inputFile, Log logger, User user)
{
if (isConvertableToPDF(inputFile.getName())) // REMEMBER TO CHANGE THE IF STATEMENT IN THE createMetadata() section to reflect this
{
new File(tempFilePath).mkdirs();
String filename = inputFile.getName();
filename = filename.substring(0, filename.lastIndexOf("."));
File outputFile = new File(tempFilePath + filename + ".pdf");
System.out.println(outputFile + " : " + inputFile);
officeManager.start(); // may tweak the start and stop code to appear elsewhere for additional efficiency
DocumentFormat docFormat = new DocumentFormat("Portable Document Format", "pdf", "application/pdf");
Map map = new HashMap();
map.put("FilterName", "writer_pdf_Export");
PropertyValue[] aFilterData = new PropertyValue[1];
aFilterData[0] = new PropertyValue();
aFilterData[0].Name = "SelectPdfVersion";
aFilterData[0].Value = 1;
map.put("FilterData", aFilterData);
docFormat.setStoreProperties(DocumentFamily.TEXT, map);
OfficeDocumentConverter docConverter = new OfficeDocumentConverter(officeManager);
docConverter.convert(inputFile, outputFile, docFormat);
officeManager.stop();
return outputFile;
}
return inputFile;
}
// returns true if the file format is known to be convertible into the PDF/A-1 format
public boolean isConvertableToPDF(String filename)
{
if (filename.endsWith(".doc") || filename.endsWith(".txt") || filename.endsWith(".xls")
|| filename.endsWith(".ppt") || filename.endsWith(".docx"))
{
return true;
}
return false;
}
}
.
Javaソケットを使用しています。なぜ...
解決
問題はここにあるかもしれません:
officeManager.start(); // may tweak the start and stop code ...
.
始動プロセスが終了するのを待っている場合は、OpenOfficeサービスを強制終了するまで待機することがあります。
必ずバックグラウンドサービスでサービスを開始するようにしてください。メインプログラムは続行できます。またはOpenOfficeサーバーを手動で起動します(プログラムの外部)。サービスが終了することはありませんのでwaitFor()
を作成しないでください。
上記のSystem.out.println()
は印刷されますので、それでもまだ動作しています。
他のヒント
問題はPCを再起動した後、それ自体が解決したので、理由はわかりません....
ハエの変革力を持つプロジェクトを開発しており、この奇妙な問題を越えてもつまずいています。ソリューションは、純粋なJava Process ManagerよりもSigar Process Managerを使用することでした。それはより堅牢で一貫していますが、ネイティブのライブラリが必要です。
あなたが選んだあなたの港に問題があるようです、私はJavaソケットオブジェクトを使用しているそのようなファンキーなものを渡って走ったことを知っています。