PHPackages                             docsdk/docsdk-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. docsdk/docsdk-php

ActiveLibrary

docsdk/docsdk-php
=================

PHP SDK for DocSDK APIs

1.0.0(5y ago)277MITPHPPHP ^7.1

Since Dec 15Pushed 4y ago3 watchersCompare

[ Source](https://github.com/docsdk/docsdk-php)[ Packagist](https://packagist.org/packages/docsdk/docsdk-php)[ Docs](https://github.com/docsdk/docsdk-php)[ RSS](/packages/docsdk-docsdk-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (14)Versions (2)Used By (0)

 [![](https://camo.githubusercontent.com/98c04ff830e1dacdbdec9a6ad70cdc8b6a5b59a1fffa30465ed127dbfceba60c/68747470733a2f2f79756e74752d646f776e6c6f61642e6f73732d636e2d68616e677a686f752e616c6979756e63732e636f6d2f4769745265736f757263652f786c6f676f2e6a7067)](https://camo.githubusercontent.com/98c04ff830e1dacdbdec9a6ad70cdc8b6a5b59a1fffa30465ed127dbfceba60c/68747470733a2f2f79756e74752d646f776e6c6f61642e6f73732d636e2d68616e677a686f752e616c6979756e63732e636f6d2f4769745265736f757263652f786c6f676f2e6a7067)

DocSDK
======

[](#docsdk)

English | [中文](doc/README-zh-CN.md)

About DocSDK
------------

[](#about-docsdk)

> DocSDK is a development kit for smart file conversion. We support the conversion of various types of documents, including pdf, doc, docx, xls, xlsx, ppt, pptx, dwg, caj, svg, html, json, png, jpg, gif and other formats, more conversion formats can be viewed on our [website](https://www.docsdk.com/). There are 8 kinds of SDK support, including Java, Node.js, PHP, Python, Swift, CLI, AWS-Lambda and Laravel.
>
> **Keywords: document conversion, file conversion, PDF to Word, PDF to PPT, PDF to HTML**

docsdk-php
----------

[](#docsdk-php)

> This is the official PHP SDK for the DocSDK API.

### Install

[](#install)

To install the PHP SDK you will need to be using [Composer](https://getcomposer.org) in your project.

Install the SDK alongside Guzzle 7:

```
composer require docsdk/docsdk-php php-http/guzzle7-adapter
```

This package is not tied to any specific HTTP client. Instead, it uses [Httplug](https://github.com/php-http/httplug) to let users choose whichever HTTP client they want to use.

If you want to use Guzzle 6 instead, use:

```
composer require docSDK/docSDK-php php-http/guzzle6-adapter
```

### Creating Jobs

[](#creating-jobs)

```
use \DocSDK\DocSDK;
use \DocSDK\Models\Job;
use \DocSDK\Models\Task;

$docsdk = new DocSDK([
    'api_key' => 'API_KEY',
    'sandbox' => false
]);

$job = (new Job())
    ->setTag('myjob-1')
    ->addTask(
        (new Task('import/url', 'ImportURL'))
            ->set('url','https://file-url')
    )
    ->addTask(
        (new Task('convert', 'ConvertFile'))
            ->set('input', 'ImportURL')
            ->set('output_format', 'pdf')
    )
    ->addTask(
        (new Task('export/url', 'ExportResult'))
            ->set('input', 'ConvertFile')
    );

$docsdk->jobs()->create($job)
```

### Uploading Files

[](#uploading-files)

Uploads to DocSDK are done via `import/upload` tasks. This SDK offers a convenient upload method:

```
use \DocSDK\Models\Job;
use \DocSDK\Models\ImportUploadTask;

$job = (new Job())
    ->addTask(new Task('import/upload','UploadFile'))
    ->addTask(
        (new Task('convert', 'ConvertFile'))
            ->set('input', 'ImportFile')
            ->set('output_format', 'pdf')
    )
    ->addTask(
        (new Task('export/url', 'ExportResult'))
            ->set('input', 'ConvertFile')
    );

$docsdk->jobs()->create($job);

$uploadTask = $job->getTasks()->whereName('UploadFile')[0];

$docsdk->tasks()->upload($uploadTask, fopen('./file.pdf', 'r'));
```

The `upload()` method accepts a string, PHP resource or PSR-7 `StreamInterface` as second parameter.

You can also directly allow clients to upload files to DocSDK:

```
