Set papersize when converting from HTML to ODT or Word

I want to convert an HTML file to an ODT (Writer file) via the (Linux) command line. This is easy and can be done like this:

libreoffice --headless --convert-to odt test.html

This will create a new ODT file called test.odt. That is great except that I cannot control the papersize of the new test.odt file.

I want to be able to set the papersize in the created ODT file. By default, on my system, it will be A4. But sometimes I want to convert it to US Letter. I do not want to change any other files on the system, I just want to know if I can do this with command line options.

How can I force the papersize in the command line when converting?

Paper size on Linux is controlled by, guess what, libpaper’s papersize and paperconf, so
/etc/papersize
File location can be overridden by the PAPERCONF environment variable.
Actual paper size can be overridden by the PAPERSIZE environment variable.

man 5 papersize
man 1 paperconf
man 8 paperconfig

Setting LANG to a locale that uses a different papersize works only by chance if not overridden by other means, including the LC_ALL or LC_PAPER locale assignments.

man 7 locale
man 1 locale
locale
locale LC_PAPER

Resulting LibreOffice commands would be

PAPERSIZE=letter libreoffice --headless --convert-to odt test.html
PAPERSIZE=a4 libreoffice --headless --convert-to odt test.html

2 Likes

I just found one solution myself at least for A4 or Letter on the command line.

If you want to force the creation of a US Letter when converting from HTML to ODT, you need to use a locale prefix on the Linux command line. This probably only works on Linux, but it is a solution:

LANG=en_US.UTF-8 libreoffice --headless --convert-to odt test.html

This will create a Writer file called test.odt and is in US Letter format.

If you want instead an A4 page, you can do this:

LANG=en_GB.UTF-8 libreoffice --headless --convert-to odt test.html

This will create a Writer file called test.odt and is in A4 format.

1 Like