{"id":3706,"date":"2024-01-22T02:16:00","date_gmt":"2024-01-22T07:16:00","guid":{"rendered":"https:\/\/www.both.org\/?p=3706"},"modified":"2024-01-22T06:35:55","modified_gmt":"2024-01-22T11:35:55","slug":"supercharge-libreoffice-with-command-line-automation","status":"publish","type":"post","link":"https:\/\/www.both.org\/?p=3706","title":{"rendered":"Supercharge LibreOffice with Command Line Automation"},"content":{"rendered":"<div class=\"pld-like-dislike-wrap pld-template-1\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"3706\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-up\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">    <\/span>\r\n<\/div><\/div>\n<p>LibreOffice has all the productivity features you&#8217;d want from an office software suite, making it a popular open source alternative to Microsoft Office or Google Suite. One of LibreOffice&#8217;s powers is the ability to operate from the command line. For example, Seth Kenlon recently explained how he uses a global <a href=\"https:\/\/opensource.com\/article\/21\/2\/linux-workday\">command-line option to convert multiple files<\/a> from DOCX to EPUB with LibreOffice. His article inspired me to share some other LibreOffice command-line tips and tricks.<\/p>\n\n\n\n<p>Before we&nbsp;look at some hidden features of LibreOffice commands, you need to understand how to use options with applications. Not all applications accept options (aside from the basics like the <code>--help<\/code> option, which works in most Linux applications).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ libreoffice --help<\/code><\/pre>\n\n\n\n<p>This returns descriptions of other options LibreOffice accepts. Some applications don&#8217;t have many options, but LibreOffice has a few screens worth, so there&#8217;s plenty to play with.<\/p>\n\n\n\n<p>Here are five useful things you can do with LibreOffice at the terminal to make the software even more useful.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"1-customize-your-launch-options\">1. Customize your launch options<\/h2>\n\n\n\n<p>You can modify how you launch LibreOffice. For instance, if you want to open just LibreOffice&#8217;s word processor component:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ libreoffice --writer  #starts the word processor<\/code><\/pre>\n\n\n\n<p>You can open its other components similarly:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ libreoffice --calc  #starts the Calc document\n$ libreoffice --draw  #starts an empty Draw document\n$ libreoffice --web  #starts and empty HTML document<\/code><\/pre>\n\n\n\n<p>You also can access specific help files from the command line:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ libreoffice --helpwriter<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter is-resized\"><img decoding=\"async\" src=\"https:\/\/opensource.com\/sites\/default\/files\/uploads\/libreoffice-help.png\" alt=\"LibreOffice Writer help\" style=\"width:1101px;height:auto\" title=\"LibreOffice help\"\/><\/figure>\n\n\n\n<p>Or if you need help with the spreadsheet application:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ libreoffice --helpcalc<\/code><\/pre>\n\n\n\n<p>You can start LibreOffice without the splash screen:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ libreoffice --writer --nologo<\/code><\/pre>\n\n\n\n<p>You can even have it launch minimized in the background while you finish working in your current window:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ libreoffice --writer --minimized<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"2-open-a-file-in-read-only-mode\">2. Open a file in read-only mode<\/h2>\n\n\n\n<p>You can open files in read-only mode using <code>--view<\/code> to prevent accidentally making and saving changes to an important file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ libreoffice --view example.odt<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"3-open-a-document-as-a-template\">3. Open a document as a template<\/h2>\n\n\n\n<p>Have you ever created a document to use as a letterhead or invoice form? LibreOffice has a rich built-in template system, but you can make any document a template with the <code>-n<\/code> option:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ libreoffice --writer -n example.odt<\/code><\/pre>\n\n\n\n<p>Your document will open in LibreOffice and&nbsp;you can make changes to it, but you won&#8217;t overwrite the original file when you save it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"4-convert-documents\">4. Convert documents<\/h2>\n\n\n\n<p>When you need to do a small task like converting a file to a new format, it can take as long for the application to launch as it takes to do the task. The solution is the <code>--headless<\/code> option, which executes LibreOffice processes without launching the graphical user interface.<\/p>\n\n\n\n<p>For example, converting a document to EPUB is a pretty simple task in LibreOffice\u2014but it&#8217;s even easier with the <code>libreoffice<\/code> command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ libreoffice --headless --convert-to epub example.odt<\/code><\/pre>\n\n\n\n<p>Using wildcards means you can convert dozens of documents at once:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ libreoffice --headless --convert-to epub *.odt<\/code><\/pre>\n\n\n\n<p>You can convert files to several formats, including PDF, HTML, DOC, DOCX, EPUB, plain text, and many more.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"5-print-from-the-terminal\">5. Print from the terminal<\/h2>\n\n\n\n<p>You can print LibreOffice documents from the command line without opening the application:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ libreoffice --headless -p example.odt<\/code><\/pre>\n\n\n\n<p>This option prints to the default printer without opening LibreOffice; it just sends the document to your printer.<\/p>\n\n\n\n<p>To print all the files in a directory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ libreoffice -p *.odt<\/code><\/pre>\n\n\n\n<p>(More than once, I&#8217;ve issued this command and then run out of paper, so make sure you have enough paper loaded in your printer before you start.)<\/p>\n\n\n\n<p>You can also print files to PDF. There&#8217;s usually no difference between this and using the <code>--convert-to-pdf<\/code> option but it&#8217;s easy to remember:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ libreoffice --print-to-file example.odt --headless<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"bonus-flatpak-and-command-options\">Bonus: Flatpak and command options<\/h2>\n\n\n\n<p>If you installed LibreOffice as a <a href=\"https:\/\/www.libreoffice.org\/download\/flatpak\/\">Flatpak<\/a>, all of these command options work, but you have to pass them through Flatpak. Here&#8217;s an example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ flatpak run org.libreoffice.LibreOffice --writer<\/code><\/pre>\n\n\n\n<p>It&#8217;s a lot more verbose than a local install, so you might be inspired to <a href=\"https:\/\/opensource.com\/article\/19\/7\/bash-aliases\">write a Bash alias<\/a> to make it easier to interact with LibreOffice directly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"surprising-terminal-options\">Surprising terminal options<\/h2>\n\n\n\n<p>Find out how you can extend the power of LibreOffice from the command line by consulting the man pages:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ man libreoffice<\/code><\/pre>\n\n\n\n<p>Were you aware that LibreOffice had such a rich set of command-line options? Have you discovered other options that nobody else seems to know about? Share them &#8212; send an email to Open@Botrh.org and we&#8217;ll collect them into a follow-up article.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Did you know that one of LibreOffice&#8217;s powers is the ability to operate from the command line like converting documents from one format to another?<\/p>\n","protected":false},"author":32,"featured_media":3715,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[100,237],"tags":[133],"class_list":["post-3706","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-command-line","category-libreoffice","tag-libreoffice"],"modified_by":"David Both","_links":{"self":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/3706","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/users\/32"}],"replies":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3706"}],"version-history":[{"count":3,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/3706\/revisions"}],"predecessor-version":[{"id":3712,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/3706\/revisions\/3712"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/media\/3715"}],"wp:attachment":[{"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}