{"id":5197,"library":"docx2pdf","title":"docx2pdf Library","description":"The docx2pdf library provides a simple Pythonic way to convert Microsoft Word .docx files to PDF format. It works exclusively on Windows and macOS, leveraging an installed version of Microsoft Word to perform the conversion. The library is currently at version 0.1.8 and sees updates on an as-needed basis.","status":"active","version":"0.1.8","language":"python","source_language":"en","source_url":"https://github.com/AlJohri/docx2pdf","tags":["document conversion","docx","pdf","microsoft word","windows","macos"],"install":[{"cmd":"pip install docx2pdf","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"convert","correct":"from docx2pdf import convert"}],"quickstart":{"code":"import os\nfrom docx2pdf import convert\n\n# This example demonstrates the API usage. For a full test,\n# you need an actual 'example.docx' file in the current directory\n# and Microsoft Word installed on your system (Windows/macOS).\n\n# Example 1: Convert a single file\ninput_file = \"example.docx\" # Replace with your .docx file path\noutput_file = \"example.pdf\"\n\n# Uncomment the following block to run if 'example.docx' exists\n# if os.path.exists(input_file):\n#     print(f\"Converting {input_file} to {output_file}...\")\n#     try:\n#         convert(input_file, output_file)\n#         print(\"Conversion complete.\")\n#     except Exception as e:\n#         print(f\"Error during conversion: {e}\")\n# else:\n#     print(f\"Skipping single file conversion: '{input_file}' not found.\")\n\n# Example 2: Convert all docx files in a directory\n# For this, create a directory like './input_docs' with .docx files.\n# input_dir = \"./input_docs\"\n# output_dir = \"./output_pdfs\"\n\n# if os.path.exists(input_dir):\n#     if not os.path.exists(output_dir):\n#         os.makedirs(output_dir)\n#     print(f\"Converting all .docx files in '{input_dir}' to '{output_dir}'...\")\n#     try:\n#         convert(input_dir, output_dir)\n#         print(\"Directory conversion complete.\")\n#     except Exception as e:\n#         print(f\"Error during directory conversion: {e}\")\n# else:\n#     print(f\"Skipping directory conversion: '{input_dir}' not found.\")\n","lang":"python","description":"This quickstart demonstrates how to use the `convert` function for both single file and directory conversions. To run this code successfully, you must have Microsoft Word installed (on Windows or macOS) and provide actual .docx files/directories as input. The actual conversion calls are commented out to prevent errors in environments without Word or input files."},"warnings":[{"fix":"Ensure Microsoft Word is installed, properly licensed, and runnable on the machine where the code is executed.","message":"The library *requires* Microsoft Word to be installed on the system (Windows or macOS). It is not a standalone converter. If Word is not installed, the conversion will fail with a COM error on Windows or an AppleScript error on macOS.","severity":"breaking","affected_versions":"All versions"},{"fix":"For cross-platform or server-side conversion, consider cloud-based APIs (e.g., Google Docs API, Adobe PDF Services) or tools that use LibreOffice/OpenOffice (e.g., `unoconv`) for headless conversions.","message":"docx2pdf is platform-specific and only works on Windows and macOS. It cannot be used on Linux servers or environments without a graphical interface and an installed copy of Microsoft Word.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For bulk conversions, consider processing documents in batches or with delays between calls to allow Word to close properly. Implement robust error handling for Word process failures.","message":"Performance can vary significantly. Starting Microsoft Word, opening the document, and saving it as PDF can be slow, especially for the first conversion or with complex documents. Multiple conversions can also lead to Word instances accumulating.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always create the output directory using `os.makedirs(output_dir, exist_ok=True)` before calling `convert` for directory conversions.","message":"When converting entire directories, ensure the output directory exists before calling `convert`. If the target output directory does not exist, the function might fail.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'0.1.8':44 'as-need':50 'basi':53 'convers':37,55 'convert':12 'current':41 'document':54 'docx':15,56 'docx2pdf':1,4 'exclus':22 'file':16 'format':19 'instal':29 'leverag':27 'librari':2,5,39 'maco':26,61 'microsoft':13,32,58 'need':52 'pdf':18,57 'perform':35 'provid':6 'python':9 'see':46 'simpl':8 'updat':47 'version':30,43 'way':10 'window':24,60 'word':14,33,59 'work':21","created_at":"2026-04-14T01:23:25.214377+00:00","updated_at":"2026-04-17T14:37:54.891398+00:00","problems":[{"fix":"Run the conversion on a Windows or macOS machine with Microsoft Word installed, or use a different library/approach that supports Linux (e.g., LibreOffice, Pandoc).","cause":"The `docx2pdf` library relies on a locally installed version of Microsoft Word to perform conversions and therefore does not support Linux or other non-Windows/macOS environments.","error":"NotImplementedError: docx2pdf is not implemented for linux as it requires Microsoft Word to be installed"},{"fix":"Ensure a user is logged into the Windows machine, or consider running Word via scheduled tasks with appropriate user context. Alternatively, explore alternative conversion methods that don't require an active user session.","cause":"This error typically occurs on Windows when Microsoft Word cannot be launched by the script, often because no user is logged in, or the script is running as a service without desktop interaction.","error":"'NoneType' object has no attribute 'SaveAs'"},{"fix":"Ensure Microsoft Word is installed and activated, try manually opening the `.docx` file to check for corruption, ensure Word isn't already open and busy, and verify file paths are not excessively long.","cause":"This is a general COM (Component Object Model) error on Windows, indicating a problem with Microsoft Word's automation interface. Common causes include Word not being installed, a corrupted or unopenable `.docx` file, Word being busy, or licensing issues.","error":"pywintypes.com_error"},{"fix":"Reinstall `pywin32` (e.g., `pip install pywin32`) and run `python -m post_install` from an elevated command prompt to ensure COM components are correctly registered.","cause":"This error on Windows indicates that the `pywin32` library, a core dependency for `docx2pdf`'s Windows implementation, is not correctly installed or its DLLs cannot be found by Python.","error":"ImportError: DLL load failed while importing win32api: The specified module could not be found."},{"fix":"Install the library using pip: `pip install docx2pdf`","cause":"The 'docx2pdf' package has not been installed in your current Python environment.","error":"ModuleNotFoundError: No module named 'docx2pdf'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.1.8","cli_name":"docx2pdf","cli_version":"0.1.8","type":"library","homepage":null,"github":"https://github.com/AlJohri/docx2pdf","docs":null,"changelog":null,"pypi":"https://pypi.org/project/docx2pdf/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-30","next_check":"2026-07-28","install_tag":null}}