Convert PDF to Word Document on Linux Command Line

To convert a PDF to a Word document from the Linux command line, use LibreOffice in headless mode: soffice --headless --infilter="writer_pdf_import" --convert-to docx file.pdf. It writes file.docx next to the original.

The result is only as good as the PDF. Layouts with columns, tables and images often need cleaning up afterwards. If you don't want to install anything, a browser tool is the easy option and you can use it right below; this page covers both.

or drag and drop

PDF files only

1 file, max 50MB

A file from your device is converted in your browser and is not uploaded.

Convert PDF to Word document Linux command line with LibreOffice

  1. Install LibreOffice with your package manager, for example sudo apt install libreoffice-writer on Debian or Ubuntu.
  2. Open a terminal in the folder that contains your PDF.
  3. Run: soffice --headless --infilter="writer_pdf_import" --convert-to docx file.pdf
  4. Wait for the command to finish. LibreOffice creates file.docx in the current folder.
  5. Open the DOCX in LibreOffice Writer or Word and check the layout, fonts and tables.

Convert many PDFs at once

LibreOffice accepts several files in one command, and you can use a loop to process a whole folder. Use a separate output folder so the originals are not mixed with the results.

  • Convert every PDF in a folder: for f in *.pdf; do soffice --headless --infilter="writer_pdf_import" --convert-to docx --outdir out "$f"; done
  • The --outdir option sets the folder for the converted files.
  • Quote file names that contain spaces.

Limits of PDF to DOCX conversion on the command line

LibreOffice opens a PDF through its drawing import, which places text in boxes rather than flowing paragraphs. The DOCX can look right but be hard to edit, with text split across many frames.

Scanned PDFs contain pictures of pages, not text, so the output will contain images or nothing useful. Text recognition (OCR) is a separate step that these commands don't perform.

Fonts that are not installed on your system are substituted, which changes line breaks and page counts.

Troubleshooting on Linux

  • soffice: command not found: install libreoffice-writer, or use the full path such as /usr/bin/soffice or /opt/libreoffice/program/soffice.
  • Nothing happens or a lock error appears: close any running LibreOffice window, or use a separate profile with -env:UserInstallation=file:///tmp/lo_profile.
  • No output file: check that the file name and path are correct, and that you can write to the folder.
  • Weird characters: install the fonts used in the PDF, or use a font package such as fonts-liberation.

The easy option: convert PDF to Word online

If you only have a file or two, or you are on a machine where you can't install software, use the PDF to Word tool at the top of this page. It runs in your browser, so your PDF is not uploaded to our servers, and it creates a real .docx file.

It works differently from LibreOffice. It extracts the text and groups it into paragraphs, and it doesn't reproduce images or exact layout. For documents where the words matter more than the design, that is often cleaner to edit than a frame-based conversion.

Which approach should you choose?

FeatureLibreOffice command lineOnline tool
Install neededYesNo
Batch conversionYes, with a shell loopOne file at a time
Keeps layoutTries to; text sits in framesNo, text only
ScriptingYesNo
Files leave your machineNoNo, runs in the browser

LibreOffice convert PDF to DOCX: useful options

Because LibreOffice handles one profile at a time, running several conversions in parallel can fail with a lock error. Give each job its own profile directory with -env:UserInstallation, or run them one after another.

  • --headless runs LibreOffice without opening a window, which is what you need on servers and in scripts.
  • --infilter="writer_pdf_import" tells LibreOffice to open the PDF as a text document rather than as a drawing.
  • --convert-to docx chooses the output format. Newer versions also accept a filter name after a colon.
  • --outdir folder sets where the converted files are written.

Other command line tools for PDFs on Linux

If you only need the text, the pdftotext tool from the poppler-utils package is simpler and faster: pdftotext -layout file.pdf file.txt keeps columns roughly aligned. You can then paste the text into a Word document.

For merging, splitting or rotating PDFs from the terminal, tools such as qpdf and pdftk exist, but they are separate packages and not part of this conversion.

Using the conversion in scripts and on servers

  • Check the exit code of soffice after each file, and log failures.
  • Set a timeout around the command, because some PDFs can hang the import.
  • Write to a separate output folder so a failed run never overwrites an original.
  • Don't convert PDFs from untrusted sources on a machine that holds sensitive data without isolating the process.

Check that LibreOffice is installed

Run soffice --version to confirm that the command is available and to see which release you have. If the command is missing but LibreOffice is installed, look in its program folder for the soffice binary, and call it with the full path.

Newer releases generally import PDFs better than old ones, so update LibreOffice if the output looks unusually broken.

Containers and servers without a screen

The headless mode doesn't need a display, so it runs in containers and on servers. Install libreoffice-writer plus a set of common fonts, and mount a volume for the input and output folders. Missing fonts are the usual cause of different line breaks in the DOCX, so include the fonts your PDFs use.

Frequently asked questions

How do I convert a PDF to Word on Linux from the terminal?

Run soffice --headless --infilter="writer_pdf_import" --convert-to docx file.pdf. LibreOffice must be installed.

How do I get a PDF to DOCX conversion with the command line for a whole folder?

Use a shell loop over *.pdf with the same soffice command and set --outdir to keep the results separate.

Why does the DOCX look different from the PDF?

PDF stores positions, not paragraphs. LibreOffice converts it into text frames, and missing fonts get replaced.

Can I convert a scanned PDF to Word on Linux?

Not with these commands. A scanned PDF needs text recognition (OCR) first, which is a separate step.

Is there a PDF to DOCX Linux GUI option?

Open the PDF in LibreOffice Draw and export, or open it in Writer. The online tool is another option and works in any browser.

Does the online tool upload my file?

No. The conversion runs in your browser.

Related tools

More guides

No terminal needed: convert your PDF to Word right in the browser.

Convert PDF to Word