Convert odt to pdf linux

How to convert libreoffice ODT to PDF in bash

I am using libreoffice under CentOS 6. I can convert ODT files to PDF with: libreoffice —headless —convert-to pdf *.odt but the problem is that it only works when no document is open in libreoffice. When I specify —env:UserInstallation=file:///path/to/some/directory as suggested in one of the comments of this question , it doesn’t help. What am I doing wrong? It is a nuisance to close all libreoffice instances before running the before command.

4 Answers 4

One possible approach is to install unoconv (if not already installed) and

Please see man unoconv for details

unoconv is a command line utility that can convert any file format that LibreOffice can import, to any file format that LibreOffice is capable of exporting. unoconv uses the LibreOffice’s UNO bindings for non-interactive conversion.

In some platforms it is also necessary to install libreoffice-headless \thanks

Under CentOS7, I also had to add the package libreoffice-headless to have it automated. If the user has never used it before, the first call to unoconv fails with error 81 after creating a bunch of files in ~/.config/ .

@AaronD.Marasco, thank you very much for this important information! Probably there is a dependency missing in the spec file. I will add your tip to the answer.

Not a spec dependency. just a use case. The error 81 issue is supposedly fixed but I don’t know what version; I guess CentOS doesn’t have it yet.

That is unlikely going to work, as the suggestion in the comment is both incomplete (you cannot just specify some directory) and incorrect ( —env. should be -env. . Here is what I recommend you do:

  1. Stop all instances of libreoffice
  2. Start libreoffice from the commandline without specifying —headless :
libreoffice -env:UserInstallation=file:///home/username/.config/libreoffice-alt 

Now start another libreoffice from the command-line (doing so allows you to see some useful messages if things go wrong when starting the second instance), without the -env. , and while that is still running start the conversion using:

libreoffice -env:UserInstallation=file:///home/username/.config/libreoffice-alt --headless --convert-to pdf *.odt 

Instead of stopping all instances, you can simply log in as a different user, create the .config-files and copy those to your own home dir.

On an Ubuntu 16.04 machine, I just ran libreoffice —headless —convert-to pdf .odt and it did it, without those prep steps. It did print a warning about Java tho.

Here is a totally different approach.

It is possible, because in recent times a series of new conversion paths were opened by Pandoc’s newly acquired capability to read ODT files.

When Pandoc reads in a file format, it converts it into an internal format, «native» (which is a form of JSON).

From its native form, it can then export the document into a whole range of other formats. Not only PDF, but also DocBook, HTML, EPUB, DOCX, ASCIIdoc, DokuWiki, MediaWiki and what-not.

Since here the wanted output format is PDF, we have another choice of different paths, provided by what Pandoc is calling a pdf-engine. Here is the list of currently available PDF engines (valid for Pandoc v2.7.2 and later — previous versions may support only a smaller list):

  • pdflatex: This requires LaTeX to be installed in addition to Pandoc.
  • xelatex: This requires XeLaTeX to be installed in addition to Pandoc (also available as an additional package to general TeX distributions).
  • context: This requires ConTeXt to be installed in addition to Pandoc; ConTeXt is available as an additional package to most general TeX distributions).
  • lualatex: This requires LuaTeX to be installed in addition to Pandoc (also available as an additional package to general TeX distributions).
  • pdfroff: This requires GNU Roff to be installed in addition to Pandoc.
  • wkhtml2pdf: This requires wkhtmltopdf to be installed in addition to Pandoc.
  • prince: This requires PrinceXML to be installed in addition to Pandoc.
  • weasyprint: This requires weasyprint to be installed in addition to Pandoc.

There are some more and newer PDF engines now integrated into Pandoc, which I have not yet used myself and which I currently cannot describe in more detail: tectonic and latexmk.

WARNING: Do not expect that the appearance of your original document will be identical in all the PDF outputs to the print preview or PDF export of the ODT! Pandoc, when converting does not preserve layouts, it preserves the contents and the structure of documents: paragraphs remain paragraphs, emphasized words remain emphasized, headings remain headings, etc. But the overall look can change considerably.

Example commands

 pandoc -f odt -o mydoc.pdf mydoc.odt --pdf-engine=pdflatex 
 pandoc -f odt -o mydoc.pdf mydoc.odt --pdf-engine=xelatex 
 pandoc -f odt -o mydoc.pdf mydoc.odt --pdf-engine=lualatex 
 pandoc -f odt -o mydoc.pdf mydoc.odt --pdf-engine=context 
 pandoc -f odt -o mydoc.pdf mydoc.odt --pdf-engine=pdfroff 

wkhtmltopdf:

 pandoc -f odt -o mydoc.pdf mydoc.odt --pdf-engine=wkhtml2pdf 
 pandoc -f odt -o mydoc.pdf mydoc.odt --pdf-engine=prince 
 pandoc -f odt -o mydoc.pdf mydoc.odt --pdf-engine=weasyprint 

Above commands are the most basic for the conversion. Depending on the PDF engine you pick, there may be many other options possible to control the appearance of the output PDF file. For example, the following additional parameters may be added to all those paths routing through LaTeX:

 -V geometry:"paperwidth=23.3cm, paperheight=1000pt, margin=11.2mm, top=2cm" 

which will use a custom page size (a bit larger than DIN A4) with margins of 2cm on the top edge and 1.12cm at the other three edges).

Источник

Как я могу преобразовать ODT файл в PDF?

Кто-нибудь знает, как конвертировать ODT файл (LibreOffice) для PDF ?

7 ответов

Просто откройте документ в libre office и выберите » Экспорт в PDF. «:

введите описание изображения здесь

Для решения командной строки есть unoconv который преобразует файлы из командной строки:

unoconv -f pdf mydocument.odt 

Примечание: только начиная с Ubuntu 11.10 unoconv зависит от Libre Office. Предыдущие версии unoconv (из Ubuntu 79

Вы также можете использовать командную строку libreoffice для вашей цели. Это дает вам преимущество пакетного преобразования. Но отдельные файлы также возможны. Этот пример преобразует все файлы ODT в текущем каталоге в PDF:

libreoffice --headless --convert-to pdf *.odt 

Получите больше информации о параметрах командной строки с:

Вот еще несколько подробностей о методе «не-GUI».

  1. Вы можете использовать этот метод не только для преобразования файлов ODT в PDF. Он также будет работать для файлов MS Word DOCX (он будет работать так же, как LibreOffice способен обрабатывать определенный ODT), и, в общем, для всех типов файлов, которые LibreOffice может открыть.
  2. Я не думаю, что есть двоичный файл с именем libreoffice как один из других предложенных ответов. Тем не менее, есть soffice(.bin) — двоичный файл, который можно использовать для запуска LibreOffice из командной строки. Обычно находится в /usr/lib/libreoffice/program/ ; и очень часто, символическая ссылка /usr/bin/soffice указывает на это место.
  3. Тогда в большинстве случаев параметры —headless —convert-to pdf не достаточно. Это должно быть:
--headless --convert-to pdf:writer_pdf_Export 
 "-env:UserInstallation=file:///tmp/LibreOffice_Conversion_$" 
/path/to/soffice \ --headless \ "-env:UserInstallation=file:///tmp/LibreOffice_Conversion_$" \ --convert-to pdf:writer_pdf_Export \ --outdir $/lo_pdfs \ /path/to/test.docx 
$ /path/to/libreoffice -h # if that path exists, which I doubt! $ /path/to/soffice -h $ /path/to/soffice.bin -h 
  • Вы получаете вывод здесь?
  • Для какой из трех двоичных / символических ссылок?
  • Запишите результаты.
  • Расскажите нам свои выводы.

Сравните их с командной строкой, которую вы использовали:

  • Есть ли какие-либо изменения в именах параметров, заглавных буквах, количестве используемых тире и т. Д.

Для сравнения, мой собственный вывод (Mac OS X) здесь:

 $ /Applications/LibreOffice.app/Contents/MacOS/soffice -h LibreOffice 5.1.2.2 d3bf12ecb743fc0d20e0be0c58ca359301eb705f Usage: soffice [options] [documents. ] Options: --minimized keep startup bitmap minimized. --invisible no startup screen, no default document and no UI. --norestore suppress restart/restore after fatal errors. --quickstart starts the quickstart service --nologo don't show startup screen. --nolockcheck don't check for remote instances using the installation --nodefault don't start with an empty document --headless like invisible but no user interaction at all. --help/-h/-? show this message and exit. --version display the version information. --writer create new text document. --calc create new spreadsheet document. --draw create new drawing. --impress create new presentation. --base create new database. --math create new formula. --global create new global document. --web create new HTML document. -o open documents regardless whether they are templates or not. -n always open documents as new files (use as template). --display Specify X-Display to use in Unix/X11 versions. -p print the specified documents on the default printer. --pt  print the specified documents on the specified printer. --view open the specified documents in viewer-(readonly-)mode. --show open the specified presentation and start it immediately --accept= Specify an UNO connect-string to create an UNO acceptor through which other programs can connect to access the API --unaccept= Close an acceptor that was created with --accept= Use --unnaccept=all to close all open acceptors --infilter=[:filter_options] Force an input filter type if possible Eg. --infilter="Calc Office Open XML" --infilter="Text (encoded):UTF8,LF. " --convert-to output_file_extension[:output_filter_name[:output_filter_options]] [--outdir output_dir] files Batch convert files (implies --headless). If --outdir is not specified then current working dir is used as output_dir. Eg. --convert-to pdf *.doc --convert-to pdf:writer_pdf_Export --outdir /home/user *.doc --convert-to "html:XHTML Writer File:UTF8" *.doc --convert-to "txt:Text (encoded):UTF8" *.doc --print-to-file [-printer-name printer_name] [--outdir output_dir] files Batch print files to file. If --outdir is not specified then current working dir is used as output_dir. Eg. --print-to-file *.doc --print-to-file --printer-name nasty_lowres_printer --outdir /home/user *.doc --cat files Dump text content of the files to console Eg. --cat *.odt --pidfile=file Store soffice.bin pid to file. -env:[=] Set a bootstrap variable. Eg. -env:UserInstallation=file:///tmp/test to set a non-default user profile path. Remaining arguments will be treated as filenames or URLs of documents to open. 
--infilter="Microsoft Word 2007/2010/2013 XML" 
--infilter="Microsoft Word 2007/2010/2013 XML" --infilter="Microsoft Word 2007-2013 XML" --infilter="Microsoft Word 2007-2013 XML Template" --infilter="Microsoft Word 95 Template" --infilter="MS Word 95 Vorlage" --infilter="Microsoft Word 97/2000/XP Template" --infilter="MS Word 97 Vorlage" --infilter="Microsoft Word 2003 XML" --infilter="MS Word 2003 XML" --infilter="Microsoft Word 2007 XML Template" --infilter="MS Word 2007 XML Template" --infilter="Microsoft Word 6.0" --infilter="MS WinWord 6.0" --infilter="Microsoft Word 95" --infilter="MS Word 95" --infilter="Microsoft Word 97/2000/XP" --infilter="MS Word 97" --infilter="Microsoft Word 2007 XML" --infilter="MS Word 2007 XML" --infilter="Microsoft WinWord 5" --infilter="MS WinWord 5" 

Источник

Читайте также:  Intel uhd 730 linux
Оцените статью
Adblock
detector