A PHP library for the ConvertAPI
Clone or download
Latest commit 76d523b Sep 30, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples Add PDF split and merge example Aug 28, 2018
lib/ConvertApi Bump version Sep 30, 2018
tests/ConvertApi Fix format detection when url includes params Sep 30, 2018
.gitignore Initial commit Jun 16, 2018
.travis.yml Test with PHP nightly build Jun 23, 2018
LICENSE Initial commit Jun 16, 2018
README.md Update README.md Aug 23, 2018
composer.json Add installation instructions Jun 23, 2018
phpunit.xml.dist Adjust structure Jun 18, 2018

README.md

ConvertAPI PHP Client

PHP version Build Status

Convert your files with our online file conversion API

The ConvertAPI helps converting various file formats. Creating PDF and Images from various sources like Word, Excel, Powerpoint, images, web pages or raw HTML codes. Merge, Encrypt, Split, Repair and Decrypt PDF files. And many others files manipulations. In just few minutes you can integrate it into your application and use it easily.

Requirements

PHP 5.4.0 and later.

Installation

The preferred method is via composer. Follow the installation instructions if you do not already have composer installed.

Once composer is installed, execute the following command in your project root to install this library:

composer require convertapi/convertapi-php

Manual Installation

If you do not wish to use Composer, you must require ConvertApi autoloader:

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

Dependencies

Library requires the following extensions in order to work properly:

If you use Composer, these dependencies should be handled automatically. If you install manually, you'll want to make sure that these extensions are available.

Usage

Configuration

You can get your secret at https://www.convertapi.com/a

use \ConvertApi\ConvertApi;

ConvertApi::setApiSecret('your-api-secret');

File conversion

Example to convert file to PDF. All supported formats and options can be found here.

$result = ConvertApi::convert('pdf', ['File' => '/path/to/my_file.docx']);

# save to file
$result->getFile()->save('/path/to/save/file.pdf');

Other result operations:

# save all result files to folder
$result->saveFiles('/path/to/save/files');

# get conversion cost
$cost = $result->getConversionCost();

Convert file url

$result = ConvertApi::convert('pdf', ['File' => 'https://website/my_file.docx']);

Specifying from format

$result = ConvertApi::convert(
    'pdf',
    ['File' => '/path/to/my_file'],
    'docx'
);

Additional conversion parameters

ConvertAPI accepts extra conversion parameters depending on converted formats. All conversion parameters and explanations can be found here.

$result = ConvertApi::convert(
    'pdf',
    [
        'File' => '/path/to/my_file.docx',
        'PageRange' => '1-10',
        'PdfResolution' => '150',
    ]
);

User information

You can always check remaining seconds amount by fetching user information.

$info = ConvertApi::getUser();

echo $info['SecondsLeft'];

More examples

You can find more advanced examples in the examples/ folder.

Development

Testing is done with PHPUnit:

CONVERT_API_SECRET=your-api-secret ./bin/phpunit

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ConvertAPI/convertapi-php. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

ConvertAPI PHP Client is available as open source under the terms of the MIT License.