Permalink
Browse files

- Added -e/--export to set export filter options (eg. PageRange, Qual…

…ity, UseLosslessCompression, ...)

- Added -i/--import to set import filter options (eg. utf8)
  • Loading branch information...
dagwieers committed Aug 8, 2010
1 parent e4b7b1a commit 72779055b892337fab488eb53033576abb0a56cf
Showing with 107 additions and 54 deletions.
  1. +3 −1 ChangeLog
  2. +5 −3 TODO
  3. +24 −0 docs/filters.txt
  4. +28 −8 docs/unoconv.1
  5. +47 −42 unoconv
View
@@ -2,7 +2,7 @@
- Now properly check if there is a GUI attached and terminate() or -unaccept instance
- Added official OpenOffice path '/opt/openoffice*/program'
- Added support for OpenOffice on Windows (Fernando Lucas Rodriguez)
-- Added -i/--pipe option to communicate with UNO pipe (Fernando Lucas Rodriguez)
+- Added --pipe option to communicate with UNO pipe (Fernando Lucas Rodriguez)
- Added -o/--outputpath option to modify the output path (Fernando Lucas Rodriguez)
- Added support for MediaWiki output (txt)
- Added OpenOffice path to LD_LIBRARY_PATH env var
@@ -19,6 +19,8 @@
- Update indexes when converting (Winfried Rohr)
- Find soffice.bin binary (once) similarly to finding uno library
- Use soffice.bin binary instead of soffice wrapper so we can more reliable terminate the process
+- Added -e/--export to set export filter options (eg. PageRange, Quality, UseLosslessCompression, ...)
+- Added -i/--import to set import filter options (eg. utf8)
* 0.3 - released 31/08/2007
- Determine doctype from input filename (if not specified)
View
8 TODO
@@ -20,10 +20,12 @@ contact me as well. :) Send an email to: Dag Wieers <dag@wieers.com>
- Change/force the document size during conversion
- Change/force the document encoding during conversion (UTF-8)
- Change/force style template (eg. when input format is ODT)
-- Allow to only convert a selection of pages/sheets
-- Add possibility to set options of filters (eg. image quality, ...)
+- Allow to only convert a selection of sheets in a spreadsheet
- Add an --stdin option to read content from stdin
-### Known bugs
+### Documentation
+- Add information about import and export filter options
+
+### Known issues
- On some systems loading (older) OpenOffice is slow and this could lead to random errors
(this is heavily influenced by version of OpenOffice and python UNO bindings)
View
@@ -0,0 +1,24 @@
+= Import and export filters
+
+== Generic export filter options
+
+== PDF export filter options
+See also:
+ - http://specs.openoffice.org/appwide/pdf_export/PDFExportDialog.odt[PDF Export Dialog Specification]
+
+|==========================================================
+|Option name |Default |Values
+|CompressMode | |
+|ExportFormFields | |
+|FirstPagOnLeft |False |boolean
+|InitialView | |
+|IsSkipEmptyPages | |
+|MaxImageResolution |300 |int (300 - 1200)
+|PageLayout |0 |int (0 - 4)
+|PageRange |any |string (eg 1-7)
+|Quality |90 |int (0 - 100)
+|ReduceImageResolution |False |boolean
+|Selection | |
+|Size | |
+|UseLosslessCompression |False |boolean
+|===========================================================
View
@@ -2,7 +2,7 @@
.\" It was generated using the DocBook XSL Stylesheets (version 1.69.1).
.\" Instead of manually editing it, you probably should edit the DocBook XML
.\" source for it and then use the DocBook XSL Stylesheets to regenerate it.
-.TH "UNOCONV" "1" "07/03/2008" "" ""
+.TH "UNOCONV" "1" "08/08/2010" "\ 0.3" "\ "
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
@@ -17,7 +17,7 @@ unoconv \- convert any document from and to any OpenOffice supported format
.SH "DESCRIPTION"
unoconv is a command line utility that can convert any file format that OpenOffice can import, to any file format that OpenOffice is capable of exporting.
.sp
-unoconv uses the OpenOffice's UNO bindings for non\-interactive conversion of documents and therefor needs an OpenOffice instance to communicate with. Therefore if it cannot find one, it will start its own instance for temporary usage. If desired, one can start a \(lqlistener\(rq instance to use for subsequent connections or even for remote connections.
+unoconv uses the OpenOffice\(cqs UNO bindings for non\-interactive conversion of documents and therefor needs an OpenOffice instance to communicate with. Therefore if it cannot find one, it will start its own instance for temporary usage. If desired, one can start a \(lqlistener\(rq instance to use for subsequent connections or even for remote connections.
.sp
.SH "OPTIONS"
.TP
@@ -137,23 +137,43 @@ unoconv is very useful together with the following tools:
.sp
.TP
Asciidoc
-http://www.methods.co.nz/asciidoc/
+[1]\&\fIhttp://www.methods.co.nz/asciidoc/\fR
.TP
docbook2odf
-http://open.comsultia.com/docbook2odf/
+[2]\&\fIhttp://open.comsultia.com/docbook2odf/\fR
+A list of possible import and export formats is available from:
+.sp
+.TP
+OpenOffice 2.1
+[3]\&\fIhttp://wiki.services.openoffice.org/wiki/Framework/Article/Filter/FilterList_OOo_2_1\fR
+.TP
+OpenOffice 3.0
+[4]\&\fIhttp://wiki.services.openoffice.org/wiki/Framework/Article/Filter/FilterList_OOo_3_0\fR
.SH "AUTHOR"
-Written by Dag Wieers, <[1]\&\fIdag@wieers.com\fR>
+Written by Dag Wieers, <[5]\&\fIdag@wieers.com\fR>
.sp
.SH "RESOURCES"
-Main web site: [2]\&\fIhttp://dag.wieers.com/home\-made/unoconv/\fR
+Main web site: [6]\&\fIhttp://dag.wieers.com/home\-made/unoconv/\fR
.sp
.SH "COPYING"
Copyright (C) 2007 Dag Wieers. Free use of this software is granted under the terms of the GNU General Public License (GPL).
.sp
.SH "REFERENCES"
.TP 3
-1.\ dag@wieers.com
+1.\ http://www.methods.co.nz/asciidoc/
+\%http://www.methods.co.nz/asciidoc/
+.TP 3
+2.\ http://open.comsultia.com/docbook2odf/
+\%http://open.comsultia.com/docbook2odf/
+.TP 3
+3.\ http://wiki.services.openoffice.org/wiki/Framework/Article/Filter/FilterList_OOo_2_1
+\%http://wiki.services.openoffice.org/wiki/Framework/Article/Filter/FilterList_OOo_2_1
+.TP 3
+4.\ http://wiki.services.openoffice.org/wiki/Framework/Article/Filter/FilterList_OOo_3_0
+\%http://wiki.services.openoffice.org/wiki/Framework/Article/Filter/FilterList_OOo_3_0
+.TP 3
+5.\ dag@wieers.com
\%mailto:dag@wieers.com
.TP 3
-2.\ http://dag.wieers.com/home\-made/unoconv/
+6.\ http://dag.wieers.com/home\-made/unoconv/
\%http://dag.wieers.com/home\-made/unoconv/
View
89 unoconv
@@ -14,25 +14,24 @@
### Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
### Copyright 2007-2008 Dag Wieers <dag@wieers.com>
-import getopt, sys, os, glob, time
+import getopt, sys, os, glob, time, socket
global convertor, oobin, oobinpath, oolibpath, oopid
### The first thing we ought to do is find a suitable OpenOffice installation
### with a compatible pyuno library that we can import.
-extralibpaths = glob.glob('/usr/lib*/openoffice*/program') + \
- glob.glob('/usr/lib*/openoffice/basis*/program') + \
- glob.glob('/usr/lib*/openoffice.org/basis*/program') + \
- glob.glob('/usr/lib*/ooo*/program') + \
- glob.glob('/opt/openoffice*/program') + \
- glob.glob('C:\\Program Files\\OpenOffice.org *\\program\\') + \
- [ '/Applications/NeoOffice.app/Contents/program', '/usr/bin' ]
-
-extrabinpaths = glob.glob('/usr/lib*/openoffice.org*/program')
+extrapaths = glob.glob('/usr/lib*/openoffice*/program') + \
+ glob.glob('/usr/lib*/openoffice*/basis*/program') + \
+ glob.glob('/usr/lib*/ooo*/program') + \
+ glob.glob('/usr/lib*/ooo*/basis*/program') + \
+ glob.glob('/opt/openoffice*/program') + \
+ glob.glob('/opt/openoffice*/basis*/program') + \
+ glob.glob('C:\\Program Files\\OpenOffice.org*\\program\\') + \
+ [ '/Applications/NeoOffice.app/Contents/program', '/usr/bin' ]
binaries = ( 'soffice.bin', 'soffice', )
-for oolibpath in extralibpaths:
+for oolibpath in extrapaths:
if os.path.exists(os.path.join(oolibpath, "pyuno.so")):
filename = "pyuno.so"
elif os.path.exists(os.path.join(oolibpath, "pyuno.dll")):
@@ -54,7 +53,7 @@ else:
sys.exit(1)
oobin = None
-for oobinpath in extralibpaths + extrabinpaths:
+for oobinpath in extrapaths:
for binary in binaries:
bin = os.path.join(oobinpath, binary)
if os.path.exists(bin):
@@ -303,8 +302,10 @@ class Options:
def __init__(self, args):
self.connection = None
self.doctype = None
+ self.exportfilter = []
self.filenames = []
self.format = None
+ self.importfilter = ""
self.listener = False
self.outputpath = None
self.pipe = None
@@ -317,10 +318,11 @@ class Options:
### Get options from the commandline
try:
- opts, args = getopt.getopt (args, 'c:d:f:hi:Llo:p:s:T:t:v',
- ['connection=', 'doctype=', 'format=', 'help', 'listener',
- 'outputpath=', 'pipe=', 'port=', 'server=', 'timeout=',
- 'show', 'stdout', 'verbose', 'version'] )
+ opts, args = getopt.getopt (args, 'c:d:e:f:hi:Llo:p:s:T:v',
+ ['connection=', 'doctype=', 'export', 'format=', 'help',
+ 'import', 'listener', 'outputpath=', 'pipe=', 'port=',
+ 'server=', 'timeout=', 'show', 'stdout', 'verbose',
+ 'version'] )
except getopt.error, exc:
print 'unoconv: %s, try unoconv -h for a list of all the options' % str(exc)
sys.exit(255)
@@ -335,14 +337,28 @@ class Options:
self.connection = arg
elif opt in ['-d', '--doctype']:
self.doctype = arg
+ elif opt in ['-e', '--export']:
+ l = arg.split('=')
+ if len(l) == 2:
+ (name, value) = l
+ if value in ('True', 'true'):
+ self.exportfilter.append( PropertyValue( name, 0, True, 0 ) )
+ elif value in ('False', 'false'):
+ self.exportfilter.append( PropertyValue( name, 0, False, 0 ) )
+ else:
+ self.exportfilter.append( PropertyValue( name, 0, value, 0 ) )
+ else:
+ print >>sys.stderr, 'Warning: Option %s cannot be parsed, ignoring.' % arg
elif opt in ['-f', '--format']:
self.format = arg
- elif opt in ['-i', '--pipe']:
- self.pipe = arg
+ elif opt in ['-i', '--import']:
+ self.importfilter = arg
elif opt in ['-l', '--listener']:
self.listener = True
elif opt in ['-o', '--outputpath']:
self.outputpath = arg
+ elif opt in ['--pipe']:
+ self.pipe = arg
elif opt in ['-p', '--port']:
self.port = arg
elif opt in ['-s', '--server']:
@@ -423,10 +439,14 @@ unoconv options:
-c, --connection=string use a custom connection string
-d, --doctype=type specify document type
(document, graphics, presentation, spreadsheet)
+ -e, --export=name=value set export filter options
+ eg. -e PageRange=1-2
-f, --format=format specify the output format
- -i, --pipe=name alternative method of connection using a pipe
+ -i, --import=string set import filter option string
+ eg. -i utf8
-l, --listener start a listener to use by unoconv clients
-o, --outputpath=name output directory
+ --pipe=name alternative method of connection using a pipe
-p, --port=port specify the port (default: 2002)
to be used by client or listener
-s, --server=server specify the server address (default: localhost)
@@ -542,6 +562,7 @@ class Convertor:
inputprops = (
PropertyValue( "Hidden", 0, True, 0 ),
PropertyValue( "ReadOnly", 0, True, 0 ),
+ PropertyValue( "FilterOptions", 0, op.importfilter, 0 ),
)
inputurl = unohelper.absolutize(self.cwd, unohelper.systemPathToFileUrl(inputfn))
@@ -550,21 +571,6 @@ class Convertor:
if not doc:
raise UnoException("File could not be loaded by OpenOffice", None)
-# standard = doc.getStyleFamilies().getByName('PageStyles').getByName('Standard')
-# pageSize = Size()
-# pageSize.Width=1480
-# pageSize.Height=3354
-# standard.setPropertyValue('Size', pageSize)
-# standard.setPropertyValue('MaxImageResolution', 1200)
-# for property in doc.getPropertySetInfo().Properties:
-# print property
-
-# print dir(doc.getPropertySetInfo())
-# for property in doc.getDocumentInfo().DocumentProperties():
-# print property
-# print dir(doc.getDocumentInfo())
-# print dir(doc.getDocumentInfo().DocumentProperties())
-
error(1, "Selected output format: %s" % outputfmt)
error(1, "Selected ooffice filter: %s" % outputfmt.filter)
error(1, "Used doctype: %s" % outputfmt.doctype)
@@ -578,15 +584,13 @@ class Convertor:
doc.updateLinks()
-# outputprops = doc.getOutProperties(outputfmt.filter, OutputStream())
-
### Write outputfile
outputprops = (
- PropertyValue( "FilterName", 0, outputfmt.filter, 0),
- PropertyValue( "Overwrite", 0, True, 0 ),
-# PropertyValue( "MaxImageResolution", 0, 1200, 0),
-# PropertyValue( "Size", 0, "A3", 0 ),
- PropertyValue( "OutputStream", 0, OutputStream(), 0 ),
+ PropertyValue( "FilterData", 0, uno.Any("[]com.sun.star.beans.PropertyValue", tuple( op.exportfilter ), ), 0 ),
+ PropertyValue( "FilterName", 0, outputfmt.filter, 0),
+# PropertyValue( "SelectionOnly", 0, True, 0 ),
+ PropertyValue( "OutputStream", 0, OutputStream(), 0 ),
+ PropertyValue( "Overwrite", 0, True, 0 ),
)
if not op.stdout:
@@ -670,8 +674,9 @@ def die(ret, str=None):
except DisposedException:
error(2, 'OpenOffice instance successfully terminated.')
- ### Try to clean up OpenOffice process when stuck
+ ### OpenOffice processes may get stuck and we have to kill them
try:
+ ### Is it still running ?
os.kill(oopid, 0)
error(2, 'Taking down OpenOffice with pid %s.' % oopid)
os.kill(oopid, 9)

0 comments on commit 7277905

Please sign in to comment.