Is there a CLI-only package to convert MS Office files to PDF?

9

Is there a command-line interface only package to convert Microsoft Office files to PDF? Specifically, I need to be able to export

  • doc/docx (Word),
  • ppt/pptx (PowerPoint),
  • xls/xlsx (Excel), and
  • vsd/vsdx (Visio).

I am aware that an installation of LibreOffice comes with a CLI to convert documents, but it does not appear to support Visio diagrams. Is there a package that does?


Ideally I'd like a solution that works on Linux, but I could find a way to use Windows if it would be far more practical. What I will very likely not have is a license to any MS products.

Sean Allred

Posted 2013-08-21T13:18:38.150

Reputation: 910

Question was closed 2017-04-17T09:18:57.523

@SeanAllred PDF export was introduced originally as a downloadable add-in for 2007, then later incorporated as a built-in feature of 2007 in the first service pack; later versions have PDF export built in. 2003 and earlier did not have any PDF export other than what was added by Adobe Acrobat or other products. – Steve Rindsberg – 2019-03-30T15:56:34.947

For macOS, you can use my docx2pdf tool: https://github.com/AlJohri/docx2pdf. If you're on windows, it's fairly easy to extend this approach for other Office tools using the win32com interface.

– Al Johri – 2019-12-24T07:51:12.350

what version of office? – Keltari – 2013-08-21T13:20:52.057

@Keltari I'm not sure. I don't think I will be working with anything pre-2003, but I think 2007 is a safe baseline. – Sean Allred – 2013-08-21T13:24:49.537

1I dont have an office 2007 app to see, but check to see if you can save as PDF from the Save As. If so, then you can write a VBScript to convert to PDF. I know this can be done for 2010 and up. – Keltari – 2013-08-21T13:27:40.817

@Keltari I believe every version from 2003 on supports export as PDF. 2007 confirmed. Note though that I do not have a version of Office available, as I mentioned in the bit @-terdon edited out... – Sean Allred – 2013-08-21T13:30:15.390

1

Since 4.0, LO has a Visio import filter. I never used it myself, so i can't tell how "powerful" it is, but it may be worth a try.

– tohuwawohu – 2013-08-21T15:01:51.707

Answers

1

You can use powershell. You can write your own, but often MS already has such scripts written for you, because all recent office supports powershell and thus can be operated on by powershell scripts. Here are some examples, and you can find more in technet.

http://gallery.technet.microsoft.com/office/Script-to-convert-Word-f702844d

http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/06/save-a-microsoft-excel-workbook-as-a-pdf-file-by-using-powershell.aspx

first, you probably can read this:

http://technet.microsoft.com/en-us/scriptcenter/dd742371.aspx

johnshen64

Posted 2013-08-21T13:18:38.150

Reputation: 4 399

1

You can use docto its a really simple command line utility that allows you to convert Word Documents to pdf or any other format.

https://github.com/tobya/DocTo

as simple as

docto -f C:\Directory\MyFile.doc -O "C:\Output Directory\MyTextFile.pdf" -T wdFormatPDF

Toby Allen

Posted 2013-08-21T13:18:38.150

Reputation: 2 634

0

Try setting up a PDF printer and make it default, then

Winword.exe  some.doc /q /n /mFilePrintDefault /mFileExit

user218473

Posted 2013-08-21T13:18:38.150

Reputation:

1Per the original question, I do not have a license for (therefore no copies of) any Microsoft Office products. winword.exe is definitely a Microsoft Office product. – Sean Allred – 2013-08-21T16:11:31.597

just saw the case, bare in mind that you probably will suffer formatting lost in most case for any method other than using a actual MS word to print to "PDF", even if print with a MS word viewer suffer formatting lost. – None – 2013-08-22T14:26:29.190

I realize that, and it's something we took under consideration before embarking on this. – Sean Allred – 2013-08-22T14:43:13.323

alternatively, you can simply unzip it, then grep the document.xml, and use sed to get all the text between <w:t> and </w:t> – None – 2013-08-22T14:59:09.953

that's how we read a docx in unix. – None – 2013-08-22T15:01:15.070

While formatting is not a major concern, there needs to be some formatting. We've also considered Pandoc for this purpose, but feel it is best to keep as close to the original formatting as possible. – Sean Allred – 2013-08-22T15:10:26.303

-1

You may use VeryDOC DOC to Any Converter Command Line software, that software does convert office files to PDF file in command line.

such as,

doc2any.exe D:\test.doc D:\out.pdf
doc2any.exe D:\test.docx D:\out.pdf
doc2any.exe D:\test.xls D:\out.pdf
doc2any.exe D:\test.ppt D:\out.pdf

Frank

Posted 2013-08-21T13:18:38.150

Reputation: 1

I'm not the downvoter, but it would probably help to link to the software and mention what it's license is. – Sean Allred – 2017-04-18T16:19:45.627

The software is not free btw – Xsmael – 2017-06-28T18:40:12.003

1It appears that doc2any requires a resident copy of Office. – Steve Rindsberg – 2019-03-30T16:01:58.443