Prompt
How do I convert Word documents to PDF automatically?
Latest observation
Oct 12, 2026
OpenAI APIWeb search: off
You can automate Word-to-PDF conversion in a few common ways, depending on your environment.
1) Using Microsoft Word itself
If you have Word installed, you can script it to open .docx files and export them as PDFs.
VBA macro
Sub ConvertToPDF()
Dim doc As Document
Set doc = ActiveDocument
doc.ExportAsFixedFormat OutputFileName:=Replace(doc.FullName, ".docx", ".pdf"), _
ExportFormat:=wdExportFormatPDF
End Sub
PowerShell via COM
$word = New-Object -ComObject Word.Application
$word.Visible = $false
$doc = $word.Documents.Open("C:\Docs\file.docx")
$pdf = "C:\Docs\file.pdf"
$doc.SaveAs([ref] $pdf, [ref] 17) # 17 = PDF
$doc.Close()
$word.Quit()
2) Using LibreOffice from the command line
Good for server or batch use, especially on Linux.
soffice --headless --convert-to pdf --outdir आउटुट_फोल्डर input.docx
Batch example:
for f in *.docx; do
soffice --headless --convert-to pdf --outdir pdfs "$f"
done
3) Using Python
With LibreOffice
import subprocess
from pathlib import Path
input_file = Path("file.docx")
output_dir = Path("pdfs")
output_dir.mkdir(exist_ok=True)
subprocess.run([
"soffice", "--headless", "--convert-to", "pdf",
"--outdir", str(output_dir), str(input_file)
], check=True)
With Word on Windows
import win32com.client as win32
word = win32.Dispatch("Word.Application")
word.Visible = False
doc = word.Documents.Open(r"C:\Docs\file.docx")
doc.SaveAs(r"C:\Docs\file.pdf", FileFormat=17)
doc.Close()
word.Quit()
4) Cloud APIs
If you want a managed solution, services like:
- Microsoft Graph / OneDrive / SharePoint
- Aspose Words
- Adobe PDF Services
- CloudConvert
These are useful if you don’t want to manage Office/LibreOffice installs.
Which option should you use?
- Windows + Office installed: Word automation or PowerShell
- Linux/server/batch jobs: LibreOffice headless
- Need scaling or no local software: Cloud API
If you want, I can give you a ready-to-run script for:
- Windows
- Linux
- Python batch conversion
- Folder watcher that auto-converts new Word files to PDF