J'utilise la bibliothèque JODConverter V 3.0 Beta 4 avec Open Office 3.4 et j'essaie de convertir certains fichiers au format PDF/A-1. Cependant, après le démarrage du processus de gestionnaire de bureau, il suffit de se bloquer et rien ne se passe. Voici le résultat:Problèmes JODConverter
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
La ligne au milieu, il y a la sortie de l'impression du nom du fichier de sortie et le nom du fichier d'entrée séparés par deux points, comme vous pouvez le voir, ils sont des valeurs valides ...
Voici ma classe de conversion:
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;
}
}
J'utilise java sockets, et avant je prises le convertisseur fonctionnait très bien, mais après avoir changé pour les sockets, il a commencé à accrocher. Je ne sais pas pourquoi ...
Ok, alors quand devrais-je appeler start() et comment l'exécuter en arrière-plan? Dois-je l'appeler quand je lance mon programme, puis le tuer quand le programme a terminé l'exécution? –
ive maintenant depuis essayé en utilisant simplement un cas extrêmement simple comme dans l'exemple qu'ils donnent sur leur site web. Le programme se bloque toujours après la fonction start(). Ive essayé de réinstaller JODConverter et Open Office sans succès, il semble déterminé à ne pas fonctionner ... quelque chose a cassé quelque part je pense .. –