Skip to Content.
Sympa Menu

idok-commit - [idok-commit] idok commit r47 - in trunk: java/ch/idok/qtgui lib

idok-commit AT lists.psi.ch

Subject: Commit emails of the iDok project

List archive

[idok-commit] idok commit r47 - in trunk: java/ch/idok/qtgui lib


Chronological Thread 
  • From: "Apache" <apache AT savannah.psi.ch>
  • To: idok-commit AT lists.psi.ch
  • Subject: [idok-commit] idok commit r47 - in trunk: java/ch/idok/qtgui lib
  • Date: Mon, 17 Mar 2008 17:10:17 +0100
  • List-archive: <https://lists.web.psi.ch/pipermail/idok-commit/>
  • List-id: Commit emails of the iDok project <idok-commit.lists.psi.ch>

Author: huebner AT PSI.CH
Date: Mon Mar 17 17:10:16 2008
New Revision: 47

Log:
The JODConverter (http://www.artofsolving.com/opensource/jodconverter) will
now be used to convert various document formats into PDF for previewing
purposes.

Added:
trunk/java/ch/idok/qtgui/Convert.java
trunk/lib/commons-io-1.3.1.jar (contents, props changed)
trunk/lib/jodconverter-2.2.1.jar (contents, props changed)
trunk/lib/slf4j-api-1.4.3.jar (contents, props changed)
trunk/lib/slf4j-jdk14-1.4.3.jar (contents, props changed)
Modified:
trunk/java/ch/idok/qtgui/PreviewWidget.java

Added: trunk/java/ch/idok/qtgui/Convert.java
==============================================================================
--- (empty file)
+++ trunk/java/ch/idok/qtgui/Convert.java Mon Mar 17 17:10:16 2008
@@ -0,0 +1,98 @@
+package ch.idok.qtgui;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.ConnectException;
+import java.net.Socket;
+
+import com.artofsolving.jodconverter.DefaultDocumentFormatRegistry;
+import com.artofsolving.jodconverter.DocumentConverter;
+import com.artofsolving.jodconverter.DocumentFamily;
+import com.artofsolving.jodconverter.DocumentFormat;
+import
com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
+import
com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
+import
com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;
+import
com.artofsolving.jodconverter.openoffice.converter.StreamOpenOfficeDocumentConverter;
+
+public class Convert {
+
+ private static int unoPort = 8016;
+
+ public static void ensureStartedOpenOfficeService() {
+ try {
+ new Socket("127.0.0.1", unoPort);
+ } catch (Exception e) {
+ ProcessBuilder processBuilder = new ProcessBuilder("bash", "-c",
+ "/usr/bin/ooffice -accept='socket,host=127.0.0.1,port="
+ + unoPort
+ + ";urp;' -headless -invisible
-nofirststartwizard");
+ try {
+ processBuilder.start();
+ Thread.sleep(500);
+ System.out.println("OO started");
+ } catch (IOException ioe) {
+ throw new RuntimeException(ioe);
+ } catch (InterruptedException e1) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public static void convert(InputStream source,String
sourceFileExtension, OutputStream dest) {
+ ensureStartedOpenOfficeService();
+ OpenOfficeConnection connection = null;
+ DefaultDocumentFormatRegistry registry = new
DefaultDocumentFormatRegistry();
+ DocumentFormat jpg = new DocumentFormat("JPEG",
DocumentFamily.DRAWING, "image/jpeg", "jpg");
+ registry.addDocumentFormat(jpg);
+ DocumentFormat png = new DocumentFormat("Portable Network Graphics",
DocumentFamily.DRAWING, "image/x-png", "png");
+ registry.addDocumentFormat(png);
+ DocumentFormat tiff = new DocumentFormat("TIFF",
DocumentFamily.DRAWING, "image/tiff", "tif");
+ registry.addDocumentFormat(tiff);
+ DocumentFormat gif = new DocumentFormat("GIF",
DocumentFamily.DRAWING, "image/gif", "gif");
+ registry.addDocumentFormat(gif);
+ DocumentFormat sourceFormat =
registry.getFormatByFileExtension(sourceFileExtension);
+ DocumentFormat destFormat =
registry.getFormatByFileExtension("pdf");
+ try {
+ connection = new SocketOpenOfficeConnection(unoPort);
+ connection.connect();
+ System.out.println("connected");
+ DocumentConverter converter = new
StreamOpenOfficeDocumentConverter(connection,registry);
+ converter.convert(source,sourceFormat,dest,destFormat);
+ System.out.println("converted");
+ try {
+ source.close();
+ dest.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ } catch (ConnectException e) {
+ throw new RuntimeException(e);
+ } finally {
+ connection.disconnect();
+ }
+ }
+ public static void convert(String source, String dest) {
+ ensureStartedOpenOfficeService();
+ OpenOfficeConnection connection = null;
+ File outputFile = null;
+ File inputFile = null;
+ try {
+ connection = new SocketOpenOfficeConnection(unoPort);
+ connection.connect();
+ System.out.println("connected");
+ DocumentConverter converter = new
OpenOfficeDocumentConverter(connection);
+ outputFile = new File( dest );
+ inputFile = new File( source );
+ converter.convert(inputFile, outputFile);
+ System.out.println("converted");
+ } catch (ConnectException e) {
+ throw new RuntimeException(e);
+ } finally {
+ connection.disconnect();
+ }
+ }
+
+}

Modified: trunk/java/ch/idok/qtgui/PreviewWidget.java
==============================================================================
--- trunk/java/ch/idok/qtgui/PreviewWidget.java (original)
+++ trunk/java/ch/idok/qtgui/PreviewWidget.java Mon Mar 17 17:10:16 2008
@@ -21,11 +21,13 @@

import java.awt.Rectangle;
import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
@@ -243,6 +245,42 @@
QMessageBox.warning(null, tr("iDok Warning"),
tr("General PDF decoding problem:") +
e.getMessage());
}
+ } else if (ext.equals("odt") | ext.equals("sxw") | ext.equals("rtf")
+ | ext.equals("doc")| ext.equals("wpd")| ext.equals("ods")
+ | ext.equals("sxc")| ext.equals("xls")| ext.equals("csv")
+ | ext.equals("tsv")| ext.equals("odp")| ext.equals("sxi")
+ | ext.equals("ppt")| ext.equals("jpg")| ext.equals("gif")
+ | ext.equals("tif")) {
+ try {
+// QTime time = new QTime();
+// int convertTime = 0;
+// int displayTime = 0;
+// time.start();
+ File file = new File(fileName_);
+ RandomAccessFile randomInputAccessFile = new
RandomAccessFile(file, "r");
+ byte[] byteInputArray = new
byte[(int)randomInputAccessFile.length()];
+ randomInputAccessFile.read(byteInputArray);
+ InputStream inStream = new
ByteArrayInputStream(byteInputArray);
+ ByteArrayOutputStream outStream = new
ByteArrayOutputStream();
+ Convert.convert(inStream,ext,outStream);
+// convertTime = time.restart();
+// System.out.println("Conversion time: "+
convertTime + " ms");
+ ByteBuffer outBuffer =
ByteBuffer.wrap(outStream.toByteArray());
+ pdfFile_ = new PDFFile(outBuffer);
+ numPages_ = pdfFile_.getNumPages();
+ pdfPageSpinBox_.setRange(1, numPages_);
+ previewPdfFile(1);
+ pdfPageSpinBox_.show();
+ pdfPageSpinBox_.setValue(1);
+// displayTime = time.elapsed();
+// System.out.println("Display time: "+ displayTime+
" ms");
+// System.out.println("Conversion+Display= "+
(convertTime+displayTime) + " ms");
+ } catch (Exception e) {
+ QMessageBox.warning(null, tr("iDok Warning"),
+ tr("General PDF decoding problem:") +
e.getMessage());
+ }
+
+
} else {
textView_
.setText("<b> Sorry, preview not yet supported </b> <br>
(Doubleclick on document to start external viewer)");

Added: trunk/lib/commons-io-1.3.1.jar
==============================================================================
Binary file. No diff available.

Added: trunk/lib/jodconverter-2.2.1.jar
==============================================================================
Binary file. No diff available.

Added: trunk/lib/slf4j-api-1.4.3.jar
==============================================================================
Binary file. No diff available.

Added: trunk/lib/slf4j-jdk14-1.4.3.jar
==============================================================================
Binary file. No diff available.



  • [idok-commit] idok commit r47 - in trunk: java/ch/idok/qtgui lib, Apache, 03/17/2008

Archive powered by MHonArc 2.6.19.

Top of Page