Skip to content

conversiontools/conversiontools-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Conversion Tools API PHP Client

Conversion Tools is an online service that offers a fast and easy way to convert documents between different formats, like XML, Excel, PDF, Word, Text, CSV and others.

This client allows to integrate the conversion of the files into PHP applications.

To convert the files PHP Client uses the public Conversion Tools REST API.

Installation

Installation using Composer

composer require conversiontools/conversiontools-php

or without composer:

require_once('conversiontools-php/src/autoload.php');

Examples

To use REST API - get API Token from the Profile page at https://conversiontools.io/profile.

Converting file

See example convert-file.php in the ./examples/ folder.

<?php

require_once __DIR__ . '/vendor/autoload.php';

use \ConversionTools\ConversionClient;

// put token here from your Profile page at https://conversiontools.io/profile
$token = '';

$fileOrUrlInput = 'test.xml';
$fileOutput = 'test.csv';

$options = ['delimiter' => 'tabulation'];

$client = new ConversionClient($token);
try {
    $client->convert('convert.xml_to_csv', $fileOrUrlInput, $fileOutput, $options);
} catch (Exception $e) {
    print 'Exception: ' . $e->getMessage() . "\n";
}

Converting URL

See example convert-url.php in the ./examples/ folder.

<?php

require_once __DIR__ . '/vendor/autoload.php';

use \ConversionTools\ConversionClient;

// put token here from your Profile page at https://conversiontools.io/profile
$token = '';

$fileOrUrlInput = 'https://google.com';
$fileOutput = 'result.pdf';

$options = [];

$client = new ConversionClient($token);
try {
    $client->convert('convert.website_to_pdf', $fileOrUrlInput, $fileOutput, $options);
} catch (Exception $e) {
    print 'Exception: ' . $e->getMessage() . "\n";
}

API

Create ConversionClient instance with a token.

use \ConversionTools\ConversionClient;

$client = new ConversionClient('<token>');

Where <token> is API token from the account's Profile page https://conversiontools.io/profile.

Convert input file and download the result

$client = new ConversionClient($token);
try {
    $client->convert('<conversion type>', $fileOrUrlInput, $fileOutput, $options);
} catch (Exception $e) {
    print 'Exception: ' . $e->getMessage() . "\n";
}

Where

  • <conversion type> is a specific type of conversion, from API Documentation.
  • $fileOrUrlInput is the filename of the input file, or URL of the file to convert (when applicable)
  • $fileOutput is the filename of the output file
  • $options is a PHP array with options for a corresponding converter, for example:
$options = ['delimiter' => 'tabulation'];

Requirements

PHP version 5.4.0 or later.

Documentation

List of available Conversion Types and corresponding conversion options can be found on the Conversion Tools API Documentation page.

License

Licensed under MIT.

Copyright (c) 2021 Conversion Tools