Document Conversion Library for PHP

Experience ConvertAPI’s PHP SDK to streamline file conversions, data extraction and document management. Integrate a wide array of features to convert, combine, compress, and securely redact PDFs and multiple other formats, all within your PHP-based applications.

Composer GitHub

Integrate within minutes

The ConvertAPI PHP library provides an all-in-one, developer-friendly toolkit for high-quality document conversion and manipulation. With support for hundreds of file formats, you can quickly transform PDFs, Office documents, images, and more. Whether you need to merge files, compress large documents, extract data, or apply redactions, this flexible library seamlessly integrates with your PHP environment.

It is easy to start converting documents using PHP in a few simple steps:

1

Sign up for a free account

Sign up for free and receive 250 conversions to try and evaluate our service. You will receive a free trial with no credit card required upon registration!

2

Set up the conversion online

On your account dashboard you will access an intuitive UI tool that allows you to set up the conversion, adjust the parameters, and try the conversion online with zero code.

3

Copy auto-generated code snippet

Once you have set up the conversion parameters and are happy with the conversion results, you will receive an auto-generated PHP code snippet with your custom parameters!

Get started now

Enterprise-Grade Document Processing

Document management toolkit for PHP

With a simple integration in PHP, you can convert documents not only to PDF, but also to images, text files, spreadsheets, ZIP archives, HTML, and many other destination formats, making it easy to automate file processing within your applications.

Select from 300+ converters and tools!

File Converter Suite

High-performance and unbeatable accuracy document converter suite with support for over 300+ conversion.

Document Builder using PHP

Generate dynamic DOCX and PDF documents like invoices, contracts, reports, on the fly.

Document Management tools

Protect, redact, compare, watermark, flatten, compress and modify your documents using ConvertAPI PHP SDK.

Security and Decryption

Protect and unprotect PDFs, MS Office Powerpoint and MS Office Word documents.

AI Data Extractor

Built to scale with your business, whether you're handling a few conversions or thousands.

Archiving & Optimization

Reduce file sizes without losing quality. Archive converters are designed to handle over 100 different file formats.

Configure it online - we will generate the PHP code for you!

Configure your file conversion directly online using our intuitive interface. Select the desired parameters and see the results in real-time. Once you're satisfied, we’ll automatically generate the PHP code for you, making integration into your project effortless. No need to start from scratch - just copy the code and implement it seamlessly into your PHP application!

Get started now

File conversion example using PHP

Converting documents using our PHP SDK has never been simpler. By reducing complex tasks to just a few lines of code, our library saves valuable time and effort, ensuring secure, reliable, and efficient document processing within your PHP environment. From straightforward conversions to advanced document manipulations, the ConvertAPI PHP library streamlines the entire process for maximum efficiency. To get started, install the ConvertAPI PHP package using Composer:

composer require convertapi/convertapi-php

Or install it manually using ConvertApi autoloader (curl and json extensions are required):

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

PDF to JPG conversion example

With the ConvertAPI PHP Client, you can configure and perform document conversions with just a few lines of code. Fine-tune your PDF-to-JPG transformation by adjusting properties such as page ranges, cropping parameters, image resolution, width, quality, and color space settings.

Under the hood, the library manages all the complexity, freeing you to integrate powerful, customizable document conversions directly into your PHP application’s workflow. Here’s an example of converting a PDF into a series of JPG images with detailed parameters:

// Code snippet is using the ConvertAPI JavaScript Client: https://github.com/ConvertAPI/convertapi-library-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 -->

Convert File Stream

This example demonstrates how to execute a document conversion directly within memory using streams. This bypasses the need to write input or output files to disk.

Key Features:

  • Reads the source file into a stream.
  • Performs the conversion entirely in memory.
  • Writes the converted file to another stream.

Use case is efficient for applications that handle files dynamically without intermediate storage.

# set your api token
ConvertApi::setApiCredentials(getenv('CONVERT_API_TOKEN'));

# Example of converting content stream to PDF
# https://www.convertapi.com/txt-to-pdf

$dir = sys_get_temp_dir();
$content = 'Test file body';

$stream = fopen('php://memory', 'rwb');
fwrite($stream, $content);
rewind($stream);

$upload = new \ConvertApi\FileUpload($stream, 'test.txt');

$result = ConvertApi::convert('pdf', ['File' => $upload]);
$savedFiles = $result->saveFiles($dir);

echo "The PDF saved to:\n";
print_r($savedFiles);

Convert URL to PDF

The following example illustrates how to convert a web page to a PDF by providing its URL. This is beneficial for archiving web content or generating PDF versions of web pages.

Key Features:

  • Inputs the web page URL.
  • Converts the web page content into a PDF document.
  • Writes the converted PDF file to disk.
# set your api token
ConvertApi::setApiCredentials(getenv('API_TOKEN'));

# Example of converting Web Page URL to PDF file
# https://www.convertapi.com/web-to-pdf

$fromFormat = 'web';
$conversionTimeout = 180;
$dir = sys_get_temp_dir();

$result = ConvertApi::convert(
    'pdf',
    [
        'Url' => 'https://en.wikipedia.org/wiki/Data_conversion',
        'FileName' => 'web-example'
    ],
    $fromFormat,
    $conversionTimeout
);

$savedFiles = $result->saveFiles($dir);

echo "The web page PDF saved to\n";

print_r($savedFiles);

Conversion workflows

In this example we will demonstrate a a chained conversion process, where a file is passed through multiple format transformations in sequence.

Key Features:

  • Performs a series of conversions (e.g., PDF → JPG → compressed ZIP).
  • Utilizes intermediate results between steps.
  • Returns the final output after all actions.

Useful for building automated workflows that require more than one conversion operation.

# set your api token
ConvertApi::setApiCredentials(getenv('API_TOKEN'));

# Short example of conversions chaining, the PDF pages extracted and saved as separated JPGs and then ZIP'ed
# https://www.convertapi.com/doc/chaining

$dir = sys_get_temp_dir();

echo "Converting PDF to JPG and compressing result files with ZIP\n";

$jpgResult = ConvertApi::convert('jpg', ['File' => 'files/test.pdf']);

$cost = $jpgResult->getConversionCost();
$count = count($jpgResult->getFiles());

echo "Conversions done. Cost: {$cost}. Total files created: {$count}\n";

$zipResult = ConvertApi::convert('zip', ['Files' => $jpgResult->getFiles()], 'any');

$cost = $zipResult->getConversionCost();
$count = count($zipResult->getFiles());

echo "Conversions done. Cost: {$cost}. Total files created: {$count}\n";

$savedFiles = $zipResult->saveFiles($dir);

echo "File saved to\n";

print_r($savedFiles);

Retrieve user information

The following example demonstrates how to retrieve user account information, such as usage limits, current balance, and activity statistics.

# set your api token
ConvertApi::setApiCredentials(getenv('API_TOKEN'));

# Retrieve user information
# https://www.convertapi.com/doc/user

$info = ConvertApi::getUser();

print_r($info);

Error handling

The following example demonstrates how to handle common errors and exceptions that may arise during file conversions.

# set your api token
ConvertApi::setApiCredentials(getenv('API_TOKEN'));

try {
    $result = ConvertApi::convert('svg', ['File' => 'files/test.docx']);
} catch (\ConvertApi\Error\Api $error) {
    echo "Got API error code: " . $error->getCode() . "\n";
    echo $error->getMessage();
}

With our PHP SDK, you’ll have access to over 300+ converters and document management features - all available through one unified platform.

You can pass the documents by specifying URLs, reading file streams, or simply referencing local file paths, ensuring that file handling integrates smoothly into your existing setup. To boost productivity even further, consider leveraging conversion workflows to handle multiple tasks efficiently.

For detailed examples and advanced usage tips, be sure to check out our GitHub repository.

Take a look at PHP code samples

View on GitHub

Automate Your Document Management using PHP

Take control of your documents with our PHP document management SDK. From basic conversions to full workflow automation, we provide the expertise and tools you need to manage your documents efficiently.

Enterprise-Grade Security

We ensure that all document processing is handled securely in the cloud, adhering to industry-leading standards like ISO 27001, GDPR, and HIPAA. To enhance security even further, we can ensure that no files or data are stored on our servers and never leave your country.

Learn more about security

Businesses trust us

Highest rated File Conversion API on major B2B software listing platforms: Capterra, G2, and Trustpilot.

"ConvertAPI has been a game-changer for our document automation workflows. Their conversion accuracy and API reliability are unmatched in the industry for over 7 years."

"ConvertAPI is a reliable, cost-effective solution with a proven track record of stability. It has grown significantly in maturity, adopting enterprise-grade practices over the years."

"We've integrated ConvertAPI across our entire document processing platform. The performance is exceptional and the support team is always responsive. Highly recommended!"

Frequently Asked Questions

What can the ConvertAPI PHP SDK do for my application?

The ConvertAPI PHP SDK enables developers to incorporate robust document conversion and manipulation features directly into PHP projects. Whether you need to transform PDFs, extract data from DOCX, or merge multiple files into one, this SDK covers a wide range of formats and operations.

Which file formats does the ConvertAPI PHP SDK support?

It supports an extensive list of formats, over 300+ types - including PDFs, Office documents, images, and various other file types. This versatility makes it suitable for a diverse range of document processing tasks.

Is it difficult to integrate the ConvertAPI PHP SDK?

Not at all. The SDK simplifies complex operations into just a few lines of PHP code, allowing you to handle document transformations, apply custom parameters, and retrieve results quickly without diving into low-level details.

Can I process large or numerous files with the ConvertAPI PHP SDK?

Yes. The SDK is built to handle large documents efficiently. While performance depends on file complexity and server resources, you can implement asynchronous calls or break down tasks into manageable workflows for optimum performance.

Can I fine-tune conversion settings?

Absolutely. The SDK gives you the freedom to adjust parameters such as resolution, image quality, page ranges, metadata handling, and more. This customization lets you produce exactly the output you need.

Does the SDK support automated workflows?

Yes. You can chain multiple operations together to form automated conversion pipelines. This approach helps streamline repetitive tasks, improving overall productivity in your document processing routines.

Where can I find additional guidance or advanced usage examples?

Explore our GitHub repository for sample code, tips, and best practices. We regularly update the repository to ensure you have access to the latest information and techniques.

What kind of support is available for the ConvertAPI PHP SDK?

We provide a dedicated support live-chat to assist with integration questions, performance tuning, and troubleshooting. You can also check our docs or engage with our developer community to find solutions tailored to your use case.

Try our PHP library for free!