I need to merge multiple documents into a single PDF in a web application running on Ubuntu Server. I've merged PDFs in the past so that shouldn't be an issue, but the documents can also contain doc, docx, xls, and xlsx files. I'm guessing my best bet it to convert those to PDF first.

After searching around a bit it seems the most popular way of doing this is to run LibreOffice from the command line to convert them. I've tested it and it works, however it seems that installing that requires installing X11 on the server, which is less than ideal.

Even beyond that issue, when I've tested it will Excel documents it seems to just page break the spreadsheet by columns in a way that makes it impossible to follow.

So I guess my questions are:

  1. Is approach the best choice for this?
  2. If so, is there a way to install LibreOffice without x11?
  3. Is there a way to more gracefully handle how it converts spreadsheets?
  • Not sure if it can be installed without X11 (as it also includes a GUI) or how it deals with Excel, but maybe Calibre could be an option?
    – Izzy
    Nov 10 '20 at 22:50

If you cannot find a suitable software that solves your requirements, you might need to write it yourself. The DocumentConverter class from the LEADTOOLS SDK is specifically designed to convert from any document format to any other document format, including Office formats and PDF, and it can even perform OCR automatically for raster based files. It’s supported for both Java and .NET Core, and contains fully functional command line demos for both. Just as a disclaimer, I work for the company that writes this library.

The code is very simple for basic conversion, but can also be fully customized for more complex tasks. The following .Net code could be used (Java is very similar):

using (DocumentConverter converter = new DocumentConverter()){
    converter.SetDocumentWriterInstance(new DocumentWriter());
    DocumentConverterJobData jobData = new DocumentConverterJobData{
        InputDocumentFileName = @”C:\temp\InputFile.docx”,
        OutputDocumentFileName = @”C:\temp\OutputFile.pdf”,
        DocumentFormat = DocumentFormat.Pdf,
        RasterImageFormat = RasterImageFormat.Unknown, // To not output to a raster based image
    DocumentConverterJob converterJob = converter.Jobs.CreateJob(jobData);

NOTE FROM MODERATORS: Links below go through third-party redirection servers. A request has been made to the poster to update all links to direct links. All non-direct links below have been temporarily disabled until this has been completed.

Syncfusion provides .NET Core libraries to convert Excel (XLS, XLSX) and Word (DOC, DOCX) to PDF without the need of LibreOffice, Adobe SDK, or Microsoft Office. You can give it a try.

Word to PDF conversion docs

Word to PDF demo

Excel to PDF conversion docs

Excel to PDF demo

Syncfusion Excel to PDF converter library provides the following options to customize the page/column break behavior.

• Automatic – Prints sheets at their actual size. The default one. • Custom Scaling – Print sheets at specified scaling option (i.e.) zoom value set in page setup. • Fit all columns on one page • Fit all rows on one page • Fill the entire sheet on one page

Please refer to this documentation page to know about customizing the Layout and other options.


  • 1
    Welcome Johnson! Do you have any affiliation with this product? If so, please disclose it in your answer in full. Also, please edit all your links to be direct links without going through third-party redirection services. Feb 25 at 15:43
  • Johnson Manickam, I would happily edit your post, but I think it would look better if you would do it.
    – peterh
    Feb 26 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.