How to Convert DOCX to PDF in Bulk with the LibreOffice Command Line

If you have dozens of Word documents, opening each one in LibreOffice and exporting it separately is slow and easy to interrupt. A command such as soffice --convert-to pdf can convert a batch, but common snags include sending PDFs to the wrong folder, losing filenames with spaces, having LibreOffice attach the job to an already-open window, or producing PDFs whose layout differs from Word. The workflow below starts with one test file, moves to a safe batch command, and ends with checks for missing or malformed output.

These examples use the current LibreOffice command-line syntax documented in LibreOffice 26.8 Help, checked October 6, 2026. They use writer_pdf_Export, the PDF export filter for Writer documents. Conversion is suitable for ordinary DOCX files, but complex layouts still need review because LibreOffice and Microsoft Word may render some fonts and page layouts differently.

Before you convert a folder

Install LibreOffice on the computer that will run the conversion. On a server, use the package manager or installer for that system and confirm that soffice is available in the command shell. On Windows, the executable is commonly under C:\Program Files\LibreOffice\program\soffice.exe; the installation path can differ.

Prepare two separate folders: one for the source DOCX files and one for the resulting PDFs. Start with a new or empty output folder. If you convert into a folder that already contains PDFs with the same base names, LibreOffice may ask about overwriting or fail to replace them, depending on the process and environment. Keeping source and output separate also prevents an accidental conversion loop when scripts scan a directory.

For documents with uncommon typefaces, install the same fonts used by the original author before conversion. Missing fonts can change line breaks, page count, table widths, and pagination even when the DOCX opens without an error.

1. Test one DOCX first

Convert a representative document before running a large batch. In the examples below, replace the sample paths with your own:

mkdir -p "/srv/docs/converted"
soffice --headless --convert-to pdf:writer_pdf_Export --outdir "/srv/docs/converted" "/srv/docs/incoming/Annual Report.docx"

--headless runs LibreOffice without opening its graphical interface. --convert-to selects the output format and optional filter, while --outdir names the destination. LibreOffice’s filter table lists writer_pdf_Export for PDF output from Writer. Review the test PDF before converting everything: check page breaks, headers and footers, tables, images, hyperlinks, and special characters.

If the test produces no PDF, confirm that the source path is correct, the file is readable, and the output folder is writable. Also check that LibreOffice is installed for the same account that runs the command. Official references: LibreOffice file conversion filters and LibreOffice command-line parameters.

2. Convert all DOCX files in one Bash command

On Linux or macOS, open Bash in a terminal and use a filename pattern. Make sure soffice is on your PATH; on macOS, you may need to call the executable inside the LibreOffice application bundle. This example handles DOCX files directly inside one input folder:

src="/srv/docs/incoming"
out="/srv/docs/converted"

mkdir -p "$out"
soffice --headless --convert-to pdf:writer_pdf_Export --outdir "$out" "$src"/*.docx

Bash expands *.docx into separate file arguments before starting LibreOffice. Because each pathname is passed as one argument, spaces in directory names and filenames are preserved. The output PDF keeps the source filename stem, so Annual Report.docx becomes Annual Report.pdf. The command processes files in that folder only; it does not search child folders.

Use an empty destination for the first run. Before you run the wildcard command, check that the input folder contains the intended files and that you have enough disk space for the PDFs. In Bash, an unmatched wildcard can remain literal unless you configure shell options; if the folder might be empty, first test for at least one DOCX or use the per-file loop in the next section.

3. Use a loop for large folders or explicit error handling

A shell may reject a very long argument list when a folder contains thousands of documents. A loop avoids sending every filename to the operating system in one command and handles spaces safely when the paths are quoted:

src="/srv/docs/incoming"
out="/srv/docs/converted"
mkdir -p "$out"

found=false
for file in "$src"/*.docx; do
  [ -f "$file" ] || continue
  found=true
  soffice --headless --convert-to pdf:writer_pdf_Export --outdir "$out" "$file" || {
    printf 'Conversion failed: %s\n' "$file" >&2
  }
done
[ "$found" = true ] || { echo 'No DOCX files found.' >&2; exit 1; }

The quoted for loop handles filenames with spaces and does not send the entire file list as one large argument. It runs one LibreOffice conversion per file, so it can take longer than the single wildcard command. It scans only files directly inside the input folder. To include subfolders, use a recursive file search and preserve each input folder in the output layout; otherwise two files with the same base name can produce colliding PDF names.

4. Convert a folder in Windows PowerShell

In PowerShell, pass each full path as a single argument. The following loop reports files for which LibreOffice returns a nonzero exit code:

$soffice = 'C:\Program Files\LibreOffice\program\soffice.exe'
$inputDir = 'C:\Documents\incoming'
$outputDir = 'C:\Documents\converted'

New-Item -ItemType Directory -Force -Path $outputDir | Out-Null
$files = Get-ChildItem -LiteralPath $inputDir -Filter '*.docx' -File
if ($files.Count -eq 0) {
    throw "No DOCX files found in $inputDir"
}

$failed = @()
foreach ($file in $files) {
    & $soffice --headless --convert-to pdf:writer_pdf_Export --outdir $outputDir $file.FullName
    if ($LASTEXITCODE -ne 0) {
        $failed += $file.FullName
    }
}
if ($failed.Count -gt 0) {
    Write-Warning "Review failed conversions: $($failed -join '; ')"
}

Change $soffice if LibreOffice is installed in another location. PowerShell’s Get-ChildItem example is not recursive; add -Recurse only if you have also planned how to avoid duplicate output names from nested folders. A nonzero exit status is a useful warning, but it does not replace checking that each expected PDF exists and opens correctly.

5. Prevent profile conflicts and overwrite surprises

LibreOffice needs write access to its user profile. If an interactive LibreOffice window is already running, a command-line conversion may reuse that instance or wait on a locked profile. Close other LibreOffice windows before a one-off job. For automation or jobs that must run separately, give the conversion a dedicated user profile with the -env:UserInstallation bootstrap option. LibreOffice documents the option for selecting a non-default profile:

soffice -env:UserInstallation=file:///tmp/lo-bulk-profile \
  --headless --convert-to pdf:writer_pdf_Export \
  --outdir "/srv/docs/converted" "/srv/docs/incoming/Annual Report.docx"

Use a profile directory writable by the account running the conversion. Do not run two simultaneous LibreOffice processes against the same profile; use a different profile for each concurrent worker. Keep automation serial until you have tested your installed version and storage setup.

Do not run a conversion into a production folder without deciding how existing PDFs should be handled. Back up or move prior results, or write into a fresh timestamped directory. A batch export should not silently replace a signed, approved, or previously reviewed PDF.

6. Troubleshoot common batch-conversion failures

  • No output files: verify the input glob or PowerShell filter, quote paths that contain spaces, and confirm the output directory exists and is writable. Run the single-file test again to separate a path problem from a batch issue.
  • The command exits but some files are missing: check the terminal output and exit status, then compare the source list with the PDFs created. A damaged or password-protected DOCX may need to be repaired or opened manually before conversion.
  • LibreOffice hangs or reports that a profile is locked: close any interactive LibreOffice process or retry with a dedicated -env:UserInstallation profile. Do not delete a profile directory while LibreOffice is using it.
  • Fonts or pagination differ from Word: install the required fonts and compare a representative PDF with the original. For documents where exact Word rendering is contractually important, verify the layout in the authoring application or an approved rendering service.
  • Existing PDFs remain unchanged: convert into an empty output folder and confirm the command points to it. Avoid assuming that rerunning a batch always overwrites an earlier PDF.

LibreOffice also accepts PDF export options after the filter name, such as page ranges or accessibility-related settings. These options are useful when all files should share the same export behavior, but test them on a sample before applying them to a batch. See the official PDF export command-line parameters.

7. Verify the finished batch

Do not judge success only by whether the command returned to the prompt. Compare the number of source DOCX files with the number of PDFs in the output folder, then inspect a few PDFs from different parts of the batch. Confirm each opens, has the expected page count, and includes the final page, tables, images, headers, footers, and characters such as accented letters or symbols.

On Linux, you can count the nonrecursive input and output files with:

find "/srv/docs/incoming" -maxdepth 1 -type f -iname '*.docx' | wc -l
find "/srv/docs/converted" -maxdepth 1 -type f -iname '*.pdf' | wc -l

Matching counts are a useful first check, not proof that every file is correct. If the counts differ, compare filenames to identify missing conversions. For a high-volume or regulated workflow, log each source path, return code, output path, and validation result, and keep the source files until the PDFs have been reviewed. LibreOffice’s command-line workflow removes repetitive manual exporting, while a separate validation pass catches the layout and file-level issues that automation cannot reliably judge on its own.

Leave a Comment

How to Create and Send a Meeting Invite in Outlook

How to Create and Send a Meeting Invite in Outlook

Create an Outlook meeting invite, add required or optional attendees, choose a time, add Teams details, set recurrence, and check replies in new or classic Outlook.

How to Add a Character Limit to Cells in Excel

How to Add a Character Limit to Cells in Excel

Use Excel's Data Validation settings to set a maximum, minimum, exact length, or character range, then add clear prompts and error alerts.

How to Fix the “We Can’t Schedule the Meeting” Error in Outlook

How to Fix the “We Can’t Schedule the Meeting” Error in Outlook

Fix the Outlook “We can’t schedule the meeting” error by checking account support, refreshing Teams sign-in, and repairing the Classic Outlook add-in.

How to Change the Language in Office 365 (Microsoft 365)

How to Change the Language in Office 365 (Microsoft 365)

Change Office 365 menus, spelling and grammar settings, or keyboard input in desktop apps and Microsoft 365 for the web.

How to Auto-Forward Emails in Outlook 365

How to Auto-Forward Emails in Outlook 365

Learn how to auto-forward all or selected emails in Outlook 365 using Forwarding settings or Rules, plus how to stop forwarding and fix blocked external forwards.

How to Use Microsoft Editor in Word for Microsoft 365

How to Use Microsoft Editor in Word for Microsoft 365

Use Microsoft Editor in Word for Microsoft 365 to check spelling, grammar, clarity, and conciseness, review suggestions, and tune proofing settings.

How to Add an RSS Feed to Outlook 365 in Classic Outlook

How to Add an RSS Feed to Outlook 365 in Classic Outlook

Learn how to add an RSS feed to Outlook 365 in classic Outlook for Windows, find the correct feed URL, manage subscriptions, and fix common RSS issues.

How to Go to a Page in Word for Microsoft 365

How to Go to a Page in Word for Microsoft 365

Jump straight to any page in Word for Microsoft 365 with Ctrl+G or F5, relative page numbers, or the Navigation pane, with Windows and Mac shortcuts.

How to Add Contacts to Outlook on Web, Windows, and Mobile

How to Add Contacts to Outlook on Web, Windows, and Mobile

Learn how to add contacts to Outlook on the web, new Outlook, classic Outlook, and mobile, plus how contact syncing and CSV imports work.

How to Change the Microsoft Word Background Color or Add an Image

How to Change the Microsoft Word Background Color or Add an Image

Change a Word page color, add a picture background, remove either, and enable background printing on Windows or Mac with clear, current steps.