Customizing file formats with unoconv
Flexible Import/Export
![© Photo by Hudson Hintze on Unsplash © Photo by Hudson Hintze on Unsplash](/var/linux_magazin/storage/images/issues/2018/208/command-line-unoconv/photobyhudsonhintzeonunsplash-268381.png/722206-1-eng-US/PhotobyHudsonHintzeonUnsplash-268381.png_medium.png)
© Photo by Hudson Hintze on Unsplash
A hidden utility in the LibreOffice toolbox, unoconv offers a wide array of import and export filter options for use at the command line.
LibreOffice is designed to save, import, or export one file at a time, using standard filter settings. The File menu allows you to choose PDF export options, but for most other types of files, you must use the default filter settings. If you want to save multiple files, or adjust the filter settings, you need to shift to the command line and run unoconv [1], a little known Python script that gives you greater control, both with a wide array of import and export filter options.
Unoconv is short for Universal Network Objects (UNO) conversion, a reference to the UNO API used by both LibreOffice and OpenOffice [2]. Bindings for UNO are available for most C++, Java, and Python compilers, and the API is used to create extensions, as well as to provide support for formats not visible in the LibreOffice desktop window, such as the obsolete LibreOffice 1.0 file formats.
Unsurprisingly, unoconv requires access to LibreOffice's resources. The easiest way to provide this access is to install unoconv on a system that already has LibreOffice installed. However, as detailed in the man page, you can also use the --connect
(-c
) option followed by a comma-separated list to define and connect to the location of a remote LibreOffice instance or --listener
(-l
) to have unoconv detect one.
Unoconv's basic command structure (Figure 1) is:
![](/var/linux_magazin/storage/images/issues/2018/208/command-line-unoconv/figure-1/722209-1-eng-US/Figure-1_large.png)
unoconv [FILE].EXTENSION
Other files can be added, either in a space-separated list or by using regular expressions. The command structure assumes that you are exporting the file(s) to PDF format, which is probably the most widely used operation for the command. The extension is the quickest way to specify the type of file, although alternatively you can use the option --doctype
(-d
) [TYPE]
, specifying document, graphics, presentation, or spreadsheet. Formulas, databases, or charts are not supported by unoconv – no doubt due to lack of demand, since these types of documents have existed in LibreOffice and its predecessor OpenOffice.org for over a decade. If you prefer to see confirmation that the command has been successfully carried out, you can also add up to three --verbose
(-v
) options – without at least one, unoconv only displays error messages, and the only sign of a completed conversion is the return to the command prompt.
If you want to change the export format, add the option --format=
(-f
). The supported formats for both exports and imports are displayed by running unoconv --show
. Supported formats include text, CSV, dBase, HTML, PDF, several versions of Microsoft Office formats, StarOffice formats (LibreOffice's original ancestor), common graphic formats, and, of course, current LibreOffice formats (Figure 2).
![](/var/linux_magazin/storage/images/issues/2018/208/command-line-unoconv/figure-2/722212-1-eng-US/Figure-2_large.png)
In addition, unoconv also includes several different housekeeping options. If a file's attributes matter, you can add --preserve
so that the output file has the same attributes as the original file. For batch conversions, you might want to use --output
(-o
) to place all the output files in a separate directory, rather than have them mixed together with the original files. The output file can also be password protected by adding:
--password= [PASSWORD]
Still another interesting option is to set the output file to the same format as the original, then add --template
(-t
) [FILE]
to add styles from another file to the output – a command-line version of the Load Styles feature in the Styles and Formatting window on LibreOffice's desktop interface.
Import and Export Filter Settings
For many users, the default filter settings are all that is needed. However, you can adjust both import and filter settings to your own preferences, using --export
(-e
) [SETTING]
or --import
(-i
) [SETTING]
. Among other purposes, this ability can be used as an easy method for adjusting the character encoding or date formats in the original file.
Filter settings are added directly after --export
(-e
) or --import
(-i
), with a separate option for each setting. For text and CSV files, these settings are introduced by FilterOptions=
and completed by a comma-separated list unique to the format. In the list, settings can be left blank (,,
) or at the end of the list omitted altogether, forcing the use of the default settings.
By contrast, PDF and graphics exports and imports are added after --export
(-e
) or --import
(-i
), with a separate option for each setting. In other words, to set a password and set the highest image resolution to 300dpi in a PDF file, the command would include:
--export PermissionPassword=abcdef --export MaxImageResolution=300
A complete list of standard import and export settings is available online [3], but it is far too long to mention here. However, different types of files have their own set of filter options.
Text Export and Import
For text import, the most common setting to customize is the encoding. A single value can be entered, such as
--import FilterOptions=76
which would set the encoding to UTF-8. However, for exporting text from a spreadsheet, the FilterOptions
fields are encoding, field-separator, text-delimiter, quote-all-text-cells, and save-cell-content-as-shown.
CSV Text File Import
CSV files have four basic settings. In order, they are the field separator, the text delimiter, the encoding, and the first line in the file to convert to or from a spreadsheet. For example,
--export FilterOptions=44,34,76,2
will set commas as the field separator, a double quotation mark as the text delimiter, UTF-8 as the encoding, and the first line in the file to the second. In theory, at the end of the settings, you could add the date format for each column, so that:
--export FilterOptions=44,34,76,2,1/5,2/5,3/5
would specify that the date formats for the first three columns would be YY/MM/DD. Any other columns would use the date format already specified for them.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
![Learn More](https://www.linux-magazine.com/var/linux_magazin/storage/images/media/linux-magazine-eng-us/images/misc/learn-more/834592-1-eng-US/Learn-More_medium.png)
News
-
NVIDIA Released Driver for Upcoming NVIDIA 560 GPU for Linux
Not only has NVIDIA released the driver for its upcoming CPU series, it's the first release that defaults to using open-source GPU kernel modules.
-
OpenMandriva Lx 24.07 Released
If you’re into rolling release Linux distributions, OpenMandriva ROME has a new snapshot with a new kernel.
-
Kernel 6.10 Available for General Usage
Linus Torvalds has released the 6.10 kernel and it includes significant performance increases for Intel Core hybrid systems and more.
-
TUXEDO Computers Releases InfinityBook Pro 14 Gen9 Laptop
Sporting either AMD or Intel CPUs, the TUXEDO InfinityBook Pro 14 is an extremely compact, lightweight, sturdy powerhouse.
-
Google Extends Support for Linux Kernels Used for Android
Because the LTS Linux kernel releases are so important to Android, Google has decided to extend the support period beyond that offered by the kernel development team.
-
Linux Mint 22 Stable Delayed
If you're anxious about getting your hands on the stable release of Linux Mint 22, it looks as if you're going to have to wait a bit longer.
-
Nitrux 3.5.1 Available for Install
The latest version of the immutable, systemd-free distribution includes an updated kernel and NVIDIA driver.
-
Debian 12.6 Released with Plenty of Bug Fixes and Updates
The sixth update to Debian "Bookworm" is all about security mitigations and making adjustments for some "serious problems."
-
Canonical Offers 12-Year LTS for Open Source Docker Images
Canonical is expanding its LTS offering to reach beyond the DEB packages with a new distro-less Docker image.
-
Plasma Desktop 6.1 Released with Several Enhancements
If you're a fan of Plasma Desktop, you should be excited about this new point release.