Convert .xls to .pdf using LibreOffice via Command Line
Asked Answered
T

3

7

I'm trying to convert a .xls file to .pdf using LibreOffice via command line on Ubuntu. I have a kind of report on the .xls file with some colors in the background of the cells and etc.

The problem is when I convert the .xls file, the .pdf loses the original format. Each page is broken almost in the half and the content of one page is displayed in two different pages.

  • Does anybody know how to convert the .xls file to .pdf via command line with keeping the original format?
  • Or some trick to set the size of the .pdf page to not break pages? (Also via command line)

The code I used to make the conversion was:

soffice --headless --convert-to pdf:"impress_pdf_Export" filename.xls
Thematic answered 16/9, 2014 at 21:49 Comment(3)
See if this helps with the format.Stryker
FYI calligraconverter is calligra's equivalent. I'm less familiar with the lo one.Bubbly
+1 as an answer not a question ;)Kesler
N
2

If you use LibreOffice to convert Microsoft Excel (XLS) files to PDF documents, this is a two-step process (even if your command does look like it is a one-step process):

  1. Import the XLS into LibreOffice (even if started with --headless).
  2. Export the PDF from LibreOffice.

If the result does not look like you expect (not similar enough to Excel's native PDF export), then start with debugging the first step from above:

  • Open the XLS file with LibreOffice in a GUI. Does it look like you expect it to look? Or are some formatting options looking weird?

    Export the PDF from there (with the GUI). Are the page dimensions as you expect? Did you set them up how you prefer? The margins like you want them? etc.pp. ...


If you are working on Windows, you may also want to consider OfficeToPDF.exe. It is hosted on CodePlex, licensed with the Apache 2.0 License and available in binary and in source code.

It requires a working Office 2013, Office 2010 or Office 2007 installation. But then it can commandline- and batch-convert to PDF various MS Office-based file formats, including XLS(X), PPT(X), DOC(X), VSD(X) and PUB as well as Libre/OpenOffice-based ODT, ODS and ODC files.

Nimrod answered 16/4, 2015 at 16:6 Comment(0)
P
0

Although this is a little bit off from the initial question (you don't _really need Office Libre if you have the Office suite and on a Windows machine)

I do appreciate the follow-up provided by Kurt. It prompted me to post the following Gist offering some clear instructions on how to go about using the .exe in a for loop.

https://gist.github.com/einsty/2189cae4175f619cff0f

Pul answered 19/1, 2016 at 14:54 Comment(0)
C
0

Try copying appropriate font file (for me it's a simsun.ttc file) to your libreoffice installing directory like '/opt/libreoffice4.2/share/fonts/truetype'.But if the width of a single excel sheet is too much for a print page(sth like 'A4'),it'll still collapse.

Challis answered 25/10, 2022 at 11:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.