PDF to DOCX using PHP

Transform PDFs into Well-Formatted Editable Word Documents

Try for FREE

PDF to DOCX features

Effortlessly Convert PDFs to MS Word DOCX with the PDF to Word PHP SDK. Our PHP SDK offers robust features such as layout preservation, formatting retention, table handling, and OCR-powered text extraction from scanned PDFs. Experience the convenience of a clean, user-friendly Word document. What sets us apart is our RESTful PHP SDK design, ensuring seamless integration into your applications or websites. Just make a simple PDF to DOCX PHP SDK call, and watch your PDFs transform into editable Word documents quickly and efficiently.

File conversion library for PHP

ConvertAPI provides a PHP library that allows you to perform a PDF to DOCX conversion with just a few lines of code. Convert PDF to DOCX documents using PHP programming language with no effort at all!

Execute the following command in your project root:
composer require convertapi/convertapi-php

Or install it manually using ConvertApi autoloader:

Following extensions are required: curl & json
require_once('/path/to/convertapi-php/lib/ConvertApi/autoload.php');

How To Convert PDF to DOCX using PHP?

You can convert PDF to DOCX in a few simple steps:

PDF to DOCX - complete code snippet for PHP

Once you have your authentication in place, simply copy-paste this pdf to docx conversion code snippet into your PHP project:

// Code snippet is using the ConvertAPI JavaScript Client: https://github.com/ConvertAPI/convertapi-js

// Code snippet is using the ConvertAPI Node.js Client: https://github.com/ConvertAPI/convertapi-nodejs

// Code snippet is using the ConvertAPI PHP Client: https://github.com/ConvertAPI/convertapi-php

// Code snippet is using the ConvertAPI Java Client: https://github.com/ConvertAPI/convertapi-java

// Code snippet is using the ConvertAPI C# Client: https://github.com/ConvertAPI/convertapi-dotnet

# Code snippet is using the ConvertAPI Ruby Client: https://github.com/ConvertAPI/convertapi-ruby

# Code snippet is using the ConvertAPI Python Client: https://github.com/ConvertAPI/convertapi-python

// Code snippet is using the ConvertAPI Go Client: https://github.com/ConvertAPI/convertapi-go

REM Code snippet is using the command line utility program: https://github.com/ConvertAPI/convertapi-cli

<!-- For conversions with the multiple file result please refer to this example: https://repl.it/@ConvertAPI/HTML-Form-with-multiple-file-result -->

Try the conversion online - no coding required!

You can try out advanced conversion parameters and test the conversion result online using our interactive demo tool. This tool will produce the same conversion output as if you were using the library from your solution, and it will auto-generate the code snippet for you!

Try for FREE!

Convert PDF to DOCX using PHP: A detailed guide

Our PDF to DOCX converter is a powerful API tool that enables users to convert PDF (Portable Document Format) files into editable DOCX (Microsoft Word) documents. With this tool, you can easily manipulate and edit the content of a PDF document in a docx processing program like Microsoft Word. Not only does this tool simplify converting PDF documents into Microsoft Word-compatible DOCX files, but it also preserves the layout and formatting of the original document as closely as possible.

Install the ConvertAPI library to any PHP project

Our PDF to DOCX converter is available as a REST API service, but we also offer a PHP library that can be easily integrated into your project. You can access the ConvertAPI library through Composer, and the source code is available on GitHub. To install the library, simply run the following command in your project's root directory:

composer require convertapi/convertapi-php

Should you wish to install ConvertApi manually, you'll need to require the ConvertApi autoloader:

require_once('/path/to/convertapi-php/src/ConvertApi/autoload.php');

If you choose not to use the Composer, it's important to install the following dependencies for our library to work properly:

Convert PDF to DOCX using PHP

If you have the library installed, you can use this PHP code snippet to convert a PDF to a DOCX:

<?php
require __DIR__ . '/../lib/ConvertApi/autoload.php';

use \ConvertApi\ConvertApi;

# Code snippet is using the ConvertAPI PHP Client: https://github.com/ConvertAPI/convertapi-php
# Read more about PDF to DOCX API: https://www.convertapi.com/pdf-to-docx

ConvertApi::setApiSecret('your-api-secret');
$result = ConvertApi::convert('docx', [
        'File' => '/path/to/my_file.pdf',
    ], 'pdf'
);
$result->saveFiles('/path/to/result/dir');

Converting PDF to DOCX has never been easier with the help of the ConvertAPI library for PHP. It is effortless and straightforward! The library allows you to convert local files, documents hosted on a server accessible through a public URL, and files uploaded to our server that are accessible by FileId.

Conclusion

By converting PDF to DOCX you gain the ability to modify the contents of the document, extract data from your original file, or create new documents based on the existing layout and formatting. Turning static PDF documents into MS Office Word using PHP has never been simpler!

You can find the conversion parameters on our interactive demo page, where you can fine-tune the conversion to output the best result possible. If you want to master our library like a PRO, we encourage you to check our advanced techniques and examples on GitHub, which covers every possible case you can think of!

Conversion parameters

Password String

Sets the password to open protected documents.

PageRange String

Set page range. Example 1-10 or 1,2,5.

Wysiwyg Bool

Persist exact formatting using text boxes.

OcrLanguage Collection

Configure the OCR language for text recognition. If auto-detection fails, manually specify the language.

Values:   automatic ca da de en es fi fr it ja nl no pl pt ro ru sl sv tr

EnableOcr Bool

Enable optical character recognition(OCR).

Try PDF to DOCX for free!