Skip to content
Snippets Groups Projects
Commit dc128f7450e8 authored by Alexis de Lattre's avatar Alexis de Lattre
Browse files

Add support for PDF export options

parent bfb7bf06e2a6
No related branches found
No related tags found
1 merge request!2Add support for PDF export options
......@@ -14,5 +14,5 @@
export JOOO_HOME=/usr/share/java
fi
export CLASSPATH="$JOOO_HOME/juh.jar:$JOOO_HOME/jurt.jar:$JOOO_HOME/ridl.jar:$JOOO_HOME/unoloader.jar:$JOOO_HOME/java_uno.jar:$JUNO_HOME/unoil.jar:./bin/py3oconverter/.:.:/usr/bin"
export CLASSPATH="$JOOO_HOME/juh.jar:$JOOO_HOME/jurt.jar:$JOOO_HOME/ridl.jar:$JOOO_HOME/unoloader.jar:$JOOO_HOME/java_uno.jar:$JUNO_HOME/unoil.jar:$JOOO_HOME/gson.jar:./bin/py3oconverter/.:.:/usr/bin"
......@@ -18,6 +18,6 @@
javac py3oconverter/Launch.java -Xlint:deprecation
javac py3oconverter/Convertor.java -Xlint:deprecation
javac py3oconverter/Launch.java -Xlint:unchecked
javac py3oconverter/Convertor.java -Xlint:unchecked
#java py3oconverter/Launch
......
......@@ -35,6 +35,8 @@
import java.io.*;
import java.lang.*;
import java.util.Map;
import com.google.gson.*;
public class Convertor {
......@@ -49,10 +51,10 @@
}
public void convert(String source_file_path, String target_file_path,
String filter_name)throws ConnectException, Exception{
String filter_name, String pdf_options, String pdf_options_types)throws ConnectException, Exception{
XDesktop xDesktop = null;
XComponent xComponent = null;
xDesktop = connect(this.server_host, this.server_port);
xComponent = openDocument(source_file_path, xDesktop);
......@@ -53,10 +55,10 @@
XDesktop xDesktop = null;
XComponent xComponent = null;
xDesktop = connect(this.server_host, this.server_port);
xComponent = openDocument(source_file_path, xDesktop);
convert_document(target_file_path, filter_name, xComponent);
convert_document(target_file_path, filter_name, xComponent, pdf_options, pdf_options_types);
}
private String createUNOFileURL(String filelocation)
......@@ -109,7 +111,7 @@
}
private void convert_document(String targetFilename, String conversionFilter, XComponent xComponent)
private void convert_document(String targetFilename, String conversionFilter, XComponent xComponent, String pdf_options, String pdf_options_types)
{
// How to get the XComponent, see ../Office/Office.OpenDocumentFromURL.snip
XStorable xStorable = (XStorable)
......@@ -121,7 +123,7 @@
refreshIndexes(xComponent);
// Set properties for conversions
PropertyValue[] conversionProperties = new PropertyValue[2];
PropertyValue[] conversionProperties = new PropertyValue[3];
conversionProperties[0] = new PropertyValue();
conversionProperties[0].Name = "Overwrite";
......@@ -131,6 +133,37 @@
conversionProperties[1].Name = "FilterName";
conversionProperties[1].Value = conversionFilter;
Map<String, String> pdf_options_map = new Gson().fromJson(pdf_options, Map.class);
Map<String, String> pdf_options_types_map = new Gson().fromJson(pdf_options_types, Map.class);
PropertyValue[] aFilterData = new PropertyValue[pdf_options_map.size()];
int i = 0;
for (Map.Entry<String, String> entry : pdf_options_map.entrySet()) {
String property_name = entry.getKey();
String property_type = pdf_options_types_map.get(property_name);
String property_value = entry.getValue();
// System.out.println(property_name + "|" + property_value + "|" + property_type);
aFilterData[i] = new PropertyValue();
aFilterData[i].Name = property_name;
if (property_type.equals("boolean") && property_value.equals("true")) {
aFilterData[i].Value = true;
}
else if (property_type.equals("boolean") && property_value.equals("false")) {
aFilterData[i].Value = false;
}
else if (property_type.equals("integer")) {
aFilterData[i].Value = Integer.parseInt(property_value);
}
else if (property_type.equals("string")) {
aFilterData[i].Value = property_value;
}
i++;
}
conversionProperties[2] = new PropertyValue();
conversionProperties[2].Name = "FilterData";
conversionProperties[2].Value = aFilterData;
// Convert
try {
// See ../Office/Office.CreateUNOCompatibleURL.snip for method createUNOFileURL(targetFilename);
......
package py3oconverter;
import com.sun.star.frame.XDesktop;
import com.sun.star.lang.XComponent;
import com.sun.star.io.ConnectException;
public class Launch {
......@@ -17,5 +16,7 @@
String source_file_path = "py3o_example.odt";
String target_file_path = "toto.pdf";
String filter_name = "writer_pdf_Export";
String pdf_options = "";
String pdf_options_types = "";
try{
......@@ -21,5 +22,10 @@
try{
c.convert(source_file_path, target_file_path, filter_name);
c.convert(
source_file_path,
target_file_path,
filter_name,
pdf_options,
pdf_options_types);
System.out.println("Conversion done");
}
......@@ -32,6 +38,6 @@
e.printStackTrace();
}
System.exit(0);
}
}
......@@ -3,6 +3,7 @@
from jpype import JPackage
import os
import json
import platform
import logging
import pkg_resources
......@@ -10,8 +11,15 @@
log = logging.getLogger(__name__)
# define some hard coded jar resource we will try to find when starting the JVM
ureitems = ["juh.jar", "jurt.jar", "ridl.jar", "unoloader.jar", "java_uno.jar"]
basisitems = ["unoil.jar", ]
ureitems = [
"juh.jar",
"jurt.jar",
"ridl.jar",
"unoloader.jar",
"java_uno.jar",
"gson.jar",
]
basisitems = ["unoil.jar"]
def get_oo_context():
......@@ -29,8 +37,6 @@
context = dict()
if os.name in ('nt', 'os2', 'ce'): # Windows
# tested to work with OpenOffice 3.2, we need to confirm
# it works with LibreOffice
context['java_classpath_sep'] = ";"
context['ure_subpath'] = os.path.join('URE', 'java')
context['oooclasses_subpath'] = os.path.join(
......@@ -118,7 +124,7 @@
jconvertor_package = JPackage('py3oconverter').Convertor
self.jconvertor = jconvertor_package(host, port)
def convert(self, infilename, outfilename, filtername):
def convert(self, infilename, outfilename, filtername, pdf_options):
"""convert the input file using a certain filter produce a result
in outputfile.
......@@ -133,6 +139,9 @@
:param filtername: a LibreOffice filter name to use for conversion
:type filtername: string
:param pdf_options: a dict with PDF export options
:type pdf_options: dict
:returns: nothing
:raises: jpype._jexception
"""
......@@ -136,4 +145,27 @@
:returns: nothing
:raises: jpype._jexception
"""
pdf_options_types = {}
pdf_options_fullstr = {}
for option_name, option_val in pdf_options.items():
if not isinstance(option_name, (str, unicode)):
log.error(
'The keys of the pdf_options dict must be strings.'
'(wrong key: %s type %s', option_name, type(option_name))
continue
if isinstance(option_val, bool):
pdf_options_types[option_name] = 'boolean'
pdf_options_fullstr[option_name] = str(option_val).lower()
elif isinstance(option_val, (int, long)):
pdf_options_types[option_name] = 'integer'
pdf_options_fullstr[option_name] = str(option_val)
elif isinstance(option_val, (str, unicode)):
pdf_options_types[option_name] = 'string'
pdf_options_fullstr[option_name] = option_val
else:
log.error(
'Unsupported option type: %s type %s',
option_name, type(option_val))
pdf_options_json = json.dumps(pdf_options_fullstr)
pdf_options_types_json = json.dumps(pdf_options_types)
# use our java lib...
......@@ -139,2 +171,7 @@
# use our java lib...
self.jconvertor.convert(infilename, outfilename, filtername)
self.jconvertor.convert(
infilename,
outfilename,
filtername,
pdf_options_json,
pdf_options_types_json)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment