Git Product home page Git Product logo

convertapi-php's Introduction

ConvertAPI PHP Client

PHP version Build Status

Convert your files with our online file conversion API

ConvertAPI helps in 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 other file manipulations. You can integrate it into your application in just a few minutes and use it easily.

Requirements

PHP 8.1.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 the Composer, you must require ConvertApi autoloader:

require_once('/path/to/convertapi-php/lib/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

Convert file to PDF example. 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');

# get file contents (without saving the file locally)
$contents = $result->getFile()->getContents();

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 additional conversion parameters depending on selected 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 your remaining seconds amount programmatically by fetching user information.

$info = ConvertApi::getUser();

echo $info['SecondsLeft'];

Alternative domain

Use setApiBase method to set alternative service domain. Dedicated to the region domain list.

ConvertApi::setApiBase('https://eu-v2.convertapi.com/');

More examples

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.

convertapi-php's People

Contributors

danielgsoftware avatar jonasjasas avatar kostas-jonauskas avatar laurynas-convertapi avatar mijohen avatar paulius-petkus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

convertapi-php's Issues

Conversion problem in Laravel Queue

When I am running conversions in a Queue I get the following error :

ConvertApi\Error\Client: SSL certificate problem: unable to get local issuer certificate in C:\laragon\www\webapp_adminLTE\vendor\convertapi\convertapi-php\lib\ConvertApi\Client.php:119 Stack trace: #0 C:\laragon\www\webapp_adminLTE\vendor\convertapi\convertapi-php\lib\ConvertApi\Client.php(103): ConvertApi\Client->handleCurlError(Resource id #902) #1 C:\laragon\www\webapp_adminLTE\vendor\convertapi\convertapi-php\lib\ConvertApi\Client.php(44): ConvertApi\Client->execute(Resource id #902) #2 C:\laragon\www\webapp_adminLTE\vendor\convertapi\convertapi-php\lib\ConvertApi\FileUpload.php(31): ConvertApi\Client->upload('C:\\laragon\\www\\...', '2019-11-29-troy...') #3 C:\laragon\www\webapp_adminLTE\vendor\convertapi\convertapi-php\lib\ConvertApi\FileUpload.php(25): ConvertApi\FileUpload->result() #4 C:\laragon\www\webapp_adminLTE\vendor\convertapi\convertapi-php\lib\ConvertApi\FormatDetector.php(15): ConvertApi\FileUpload->getFileExt() #5 C:\laragon\www\webapp_adminLTE\vendor\convertapi\convertapi-php\lib\ConvertApi\Task.php(86): ConvertApi\FormatDetector->run() #6 C:\laragon\www\webapp_adminLTE\vendor\convertapi\convertapi-php\lib\ConvertApi\Task.php(27): ConvertApi\Task->detectFormat(Array) #7 C:\laragon\www\webapp_adminLTE\vendor\convertapi\convertapi-php\lib\ConvertApi\ConvertApi.php(74): ConvertApi\Task->run() #8 C:\laragon\www\webapp_adminLTE\app\Http\Controllers\MenusController.php(611): ConvertApi\ConvertApi::convert('pdf', Array) #9 C:\laragon\www\webapp_adminLTE\app\Jobs\SendMenus.php(43): App\Http\Controllers\MenusController->convertMenuToPDF('C:\\laragon\\www\\...') #10 [internal function]: App\Jobs\SendMenus->handle() #11 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(32): call_user_func_array(Array, Array) #12 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Container\Util.php(34): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() #13 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(90): Illuminate\Container\Util::unwrapIfClosure(Object(Closure)) #14 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure)) #15 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Container\Container.php(590): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL) #16 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(94): Illuminate\Container\Container->call(Array) #17 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(130): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}(Object(App\Jobs\SendMenus)) #18 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(105): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(App\Jobs\SendMenus)) #19 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(98): Illuminate\Pipeline\Pipeline->then(Object(Closure)) #20 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Queue\CallQueuedHandler.php(83): Illuminate\Bus\Dispatcher->dispatchNow(Object(App\Jobs\SendMenus), false) #21 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(130): Illuminate\Queue\CallQueuedHandler->Illuminate\Queue\{closure}(Object(App\Jobs\SendMenus)) #22 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(105): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(App\Jobs\SendMenus)) #23 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Queue\CallQueuedHandler.php(85): Illuminate\Pipeline\Pipeline->then(Object(Closure)) #24 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Queue\CallQueuedHandler.php(59): Illuminate\Queue\CallQueuedHandler->dispatchThroughMiddleware(Object(Illuminate\Queue\Jobs\DatabaseJob), Object(App\Jobs\SendMenus)) #25 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Queue\Jobs\Job.php(88): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\DatabaseJob), Array) #26 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(348): Illuminate\Queue\Jobs\Job->fire() #27 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(294): Illuminate\Queue\Worker->process('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Queue\WorkerOptions)) #28 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(129): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\DatabaseJob), 'database', Object(Illuminate\Queue\WorkerOptions)) #29 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(112): Illuminate\Queue\Worker->daemon('database', 'default', Object(Illuminate\Queue\WorkerOptions)) #30 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(96): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'default') #31 [internal function]: Illuminate\Queue\Console\WorkCommand->handle() #32 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(32): call_user_func_array(Array, Array) #33 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Container\Util.php(34): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() #34 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(90): Illuminate\Container\Util::unwrapIfClosure(Object(Closure)) #35 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure)) #36 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Container\Container.php(590): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL) #37 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Console\Command.php(202): Illuminate\Container\Container->call(Array) #38 C:\laragon\www\webapp_adminLTE\vendor\symfony\console\Command\Command.php(255): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle)) #39 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Console\Command.php(189): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle)) #40 C:\laragon\www\webapp_adminLTE\vendor\symfony\console\Application.php(934): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #41 C:\laragon\www\webapp_adminLTE\vendor\symfony\console\Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #42 C:\laragon\www\webapp_adminLTE\vendor\symfony\console\Application.php(149): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #43 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Console\Application.php(90): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #44 C:\laragon\www\webapp_adminLTE\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(131): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #45 C:\laragon\www\webapp_adminLTE\artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #46 {main} --

This is the conversion method from my controller :

`<?php

namespace App\Http\Controllers;

use App\Dish;
use App\Ingredient;
use App\MealPlan;
use App\MealPlanItemCategory;
use App\Menu;
use App\NutritionalValue;
use Illuminate\Bus\Queueable;
use Illuminate\Http\Request;
use DB;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Artisan;
use PhpOffice\PhpSpreadsheet\Calculation\Category;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use Illuminate\Support\Facades\Mail;

use Illuminate\Support\Facades\Storage;
use Illuminate\Http\File;

use Illuminate\Contracts\Queue\ShouldQueue;

use \ConvertApi\ConvertApi;

class MenusController extends Controller
{

public function convertMenuToPDF($file){
    $result = ConvertApi::convert('pdf', ['File' => $file]);
    # save to file
    $pdf = str_replace('docx','pdf',$file);

    $result->getFile()->save($pdf);

    return $pdf;
}

}`

And this is my Job :

`<?php

namespace App\Jobs;

use App\Http\Controllers\MenusController;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Mail;

class SendMenus implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

protected $menu,$when;

/**
 * Create a new job instance.
 *
 * @return void
 */
public function __construct($menu,$when)
{
    $this->menu = $menu;
    $this->when = $when;
}

/**
 * Execute the job.
 *
 * @return void
 */
public function handle(MenusController $menusController)
{
    $menuFile = $menusController->templateEdition($this->menu->id);

    $menu = $this->menu;
    $when = $this->when;
    $pdfFile = $menusController->convertMenuToPDF($menuFile);

}

}`

Spaces in filenames become +'s

The PHP client uses cURL under the hood, which converts filenames with spaces in them to have +es instead.

As a result of this, Word and Excel files that have the FILENAME special property (when using the 'Direct' converter) will have the filename with spaces in them, i.e. AC+1+report+template.docx. It's the same for the API request logs.

This is related to a series of support requests to [email protected], so please refer there for more information and file examples.

Getting Issue

Hi Support Team,

As I discussed with your support team member Jonas I'm generating ticket for the issue with API. Please check the attachment for the errors.
website URL: https://typetester.dk/

After filling the forms at the last on result page I'm getting error.It was working properly before but suddenly I'm getting the errors.

Here is the code I'm using:

setApiSecret('XXXXXXXX'); $result = $res->convert('pdf', [ 'File' => $template_path1, 'BreakAfterElements' => 'section', ], 'html' ); $pdf_path = get_template_directory(); $result->saveFiles($pdf_path); if($lang == 'english'){ $pdf_path = get_template_directory() . '/Personality test results.pdf'; }else { $pdf_path = get_template_directory() . '/Personlighedstest resultater.pdf'; } $to = $email; if($lang == 'english'){ $subject = 'Personality Test result'; $body = 'Find your personality result in attachment'; }else{ $subject = 'Personlighedstest resultat'; $body = ' Tak fordi du tog vores personlighedstest. Se dine resultater i den vedhæftede PDF.'; } // Create an array of headers if($lang == 'english'){ $headers = array( 'Content-Type: text/html; charset=UTF-8', 'From: "Artlinco Personality test" ', ); }else{ $headers = array( 'Content-Type: text/html; charset=UTF-8', 'From: "Artlinco Personlighedstest" ', ); } //Check if the PDF file exists if (file_exists($pdf_path)) { // Add the PDF file as an attachment $attachments = array($pdf_path); // Send the email with the PDF attachment $mail_sent = wp_mail($to, $subject, $body, $headers, $attachments); if ($mail_sent) { if($lang == 'english'){ echo 'Email sent successfully with PDF attachment.
Please note, this mail might end up in your spam folder. Please check your spam folder for your results.'; }else{ echo 'E-mail blev sendt med PDF-vedhæftet fil.
Bemærk, at den tilsendte mail muligvis kan ende i din spamfolder. Tjek derfor din spamfolder for mail med dine resultater.'; } } else { if($lang == 'english'){ echo 'Email sending failed.'; }else{ echo 'Afsendelse af e-mail mislykkedes.'; } } } else { echo 'PDF file not found.'; } } }

Issue about docx convert

error code 5001 if try to convert docx with an image inside document.
It works with curl.
It seems an issue abut sdk

Get file contents method

I can not get the converted file contents. I can only save the file. Getting the contents directly is really needed

Conversion failed. Code: 5001

I followed this link to convert doc to pdf (https://www.convertapi.com/docx-to-pdf)

This is my code

<?php

namespace App\Http\Controllers;

use ConvertApi\ConvertApi;

class ViewerController extends Controller
{

    public function check_viewer()
    {

        ConvertApi::setApiSecret('my-secret-key');
        $result = ConvertApi::convert('pdf', [
                'File' => public_path().'/files/converted/test.docx',
            ], 'docx'
        );
        $result->saveFiles(public_path().'/files/converted/');
    }

}

PHP -v 7.4
Laravel version 7.15

Here is the error
Screenshot 2020-06-10 at 1 56 19 PM

Footer value not pick

I have a doc file having mergefields when I convert that into pdf its not picking the value of merge filed infooter.

Converting XLXS with date values to PDF

When converting an XLXS file to PDF that includes a date field the output of the field becomes #############.

Example: I have a timestamp value in a column as so -
7/4/2019 0:00

Converting results in - #############.

All other fields are correct

Handle non-json errors

Hello, I am getting the following error:
TypeError Cannot access offset of type string on string
from the file:
lib/ConvertApi/Client.php:156

This is because the server returns a non-json string.
This case should throw an Error\Api just like a json-error.
Just add this before using the $json as an array, on line 156:
if (is_string($json)) throw new Error\Api($json);

report the convert api not working

I am using the API pdf to jpg but the API returns null from your side. and I already talked about this issue with convertapi supporting team but they say it is still an issue in the PHP library and do report it here please fix this issue ASAP because our project totally depends on your API response. thanks
image
my code-----------

all(), [ 'pdf' => 'required|file|mimes:pdf|max:2048', // Adjust the maximum file size as needed ]); // Check if the validation fails if ($validator->fails()) { $errorMessage = $validator->errors()->first(); return response()->json(['error' => $errorMessage], Response::HTTP_NOT_FOUND); } // Set your ConvertAPI.com API secret key ConvertApi::setApiSecret('R13KzvjgO2EGTY86'); // Retrieve the uploaded PDF file $pdfFile = $request->file('pdf'); if (!$pdfFile instanceof UploadedFile) { return response()->json(['error' => 'PDF file not found.'], Response::HTTP_NOT_FOUND); } // Specify the desired image format $imageFormat = 'jpg'; // Change it to your preferred image format // Convert the PDF to an image $result = ConvertApi::convert('pdf', [ 'File' => $pdfFile->path(), ], $imageFormat); // Get the converted image data as a string $imageData = $result->getFileData(); // Set the appropriate headers for the image response $headers = [ 'Content-Type' => 'image/' . $imageFormat, 'Content-Disposition' => 'inline; filename="converted_image.' . $imageFormat . '"', ]; // Return the image response return response($imageData, Response::HTTP_OK, $headers); } catch (ApiError $e) { // Log the error Log::error('ConvertAPI Error: ' . $e->getMessage()); // Return an error response return response()->json(['error' => 'An error occurred during the conversion process.'], Response::HTTP_INTERNAL_SERVER_ERROR); } } }

cURL connection error causes ErrorException

When our connection to ConvertAPI failed for some reason, the API client caused an error:

ErrorException
Warning: Trying to access array offset on value of type null

/vendor/convertapi/convertapi-php/lib/ConvertApi/Client.php in ConvertApi\Client::checkResponse at line 159

        catch (\Exception $e)
        {
            throw new Error\Api($response);
        }
        $message = $json['Message'] . ' Code: ' . $json['Code'];
        if (!empty($json['InvalidParameters']))
            $message .= ' '. json_encode($json['InvalidParameters']);
        throw new Error\Api($message, $json['Code']);

ch: Object CurlHandle
response: upstream connect error or disconnect/reset before headers. reset reason: connection termination

Screenshot 2023-01-12 at 14 00 38

If possible the client should handle cURL errors rather than assuming the response always has valid $json with Message and Code keys.

Download corrupts the response content

When you download a file via the Client::download method CURL dumps the content of the file into the php output buffer, which then gets sent ahead of any response from the PHP script.

e.g. We're using ConvertAPI to convert a file to Pdf when its uploaded via an AJAX request. We found that the ajax call was returning a dump of the PDF file ahead of the JSON we were expecting. Adding a single line into client.php fixed it.

I've created a pull request to address this issue. #11

Conversion error

I noticed that the conversion didn't give the same result depending on the machine running the ConvertAPI PHP library. I found that this was due to the encoding when the file was uploaded.

I haven't investigated this in depth but it's a possibility. I managed to correct the problem by changing the header to ‘Transfer-Encoding: gzip,deflate’.

File:
lib/ConvertApi/Client.php
Line:
30
Original:
‘Transfer-Encoding: chunked’,
Fix:
‘Transfer-Encoding: gzip,deflate’,

Error while merging two PDF files

Conversion:

`$result = ConvertApi::convert('merge', [
'Files[0]' => new \ConvertApi\FileUpload('files/test.pdf'),
'Files[1]' => new \ConvertApi\FileUpload('files/test.pdf'),
], 'pdf'
);

$result->saveFiles('/tmp');`

Error:
PHP Catchable fatal error: Method ConvertApi\FileUpload::__toString() must return a string value in convertapi-php/lib/ConvertApi/Client.php on line 19

Add possibility authenticate by token

Currently library does not have ability to authenticate by Access token:

image

User can only authenticate with secret:
image

Need to add support for access tokens and an example would be great, too.

Failed to open stream: HTTP request failed! HTTP/1.1 426 Upgrade Required

The problem consists of two cases:

  1. The PHP library lacks a method to get file content as a stream, I only find the Save method to file system:

    function save($path)

  2. Due to the lack of a method to get file stream developers using the file_get_contents method to read files from URL as a stream.

The problem:

We have depreciated the HTTP/1.0 version for internal technical reasons and file_get_contents started throwing exceptions:

failed to open stream: HTTP request failed! HTTP/1.1 426 Upgrade Required

To fix this issue we need to set HTTP version using context:

$context = stream_context_create(array('http'=>array('protocol_version'=>'1.1')));
file_get_contents('http://ip:port/?light=on', false, $context);

See also the full list of context options http://www.php.net/manual/en/context.http.php

Suggested solution:

  1. Add the save to stream method to the library.

  2. Switch automatically to HTTP 1.1. version when Library is used to prevent an error if a developer still decides to use the file_get_contents method. I am not certain if that possible to switch the HTTP version globally in PHP.

ConvertApi::convert is showing Fatal error. Method ConvertApi\FileUpload::__toString() must not throw an exception

Each time it is ending up in a fatal error.

Fatal error: Method ConvertApi\FileUpload::__toString() must not throw an exception, caught ConvertApi\Error\Api: Code lib\ConvertApi\FileParam.php on line 12

While tracking down the error, I reached Client.php file, function execute($ch) where curl_exec($ch) is returning 400 Bad Request.

Please help me to get the result.

This is my code

require __DIR__ . '/lib/ConvertApi/autoload.php';
use \ConvertApi\ConvertApi;
ConvertApi::setApiSecret('<THIS IS SECRET>');
$dir = sys_get_temp_dir();

$upload = new \ConvertApi\FileUpload('files/pdf.pdf');
$result = ConvertApi::convert('tc', ['File' => $upload]);
$savedFile = $result->saveFiles($dir);

Please let me know what can be done from my side.

PowerPoint conversions fail if any elements use transparency

The conversion process will end abruptly when converting PowerPoint slides with transparency.

For example: If a 5 page PowerPoint uses transparency on page 3 only, ConvertAPI will return 3 images instead of the expected 5, and the 3rd image will be corrupt. No errors are thrown.

Do not pass any TimeOut property to ConvertAPI and set HTTP Client timeout to 1800 seconds

Do not pass any default TimeOut property to ConvertAPI and set HTTP Client timeout to 1800 seconds. The idea is to use the default converter timeout of ConvertAPI if no timeout is set and to prevent HTTP Client request deadlock and set the default HTTPClient timeout to 1800 seconds.

If, however, timeout is set we handle it as before, pass a timeout to ConvertAPI and set HTTPClient Timeout to: ConvertAPITimeOut+conversion_timeout_delta

conversion_timeout_delta = 10

PDF Content Issue

Hello,

I'm encountering an issue while converting HTML to PDF. I'm passing an HTML file with the content "Hello Test. How are you...?" but the generated PDF contains the content "7b Hello Sandeep. How are you...? 0". I've attached PDF file for your review.

Could you please assist me in identifying the issue as soon as possible?

Thank you.
test2.pdf

Add get + set for `$apiBase` to increase testability

We're currently integrating the ConvertAPI into our project. When writing a unit test, we tried to mock the ConvertApi class. This works fine to a certain extend. In a piece of code we have the following:

ConvertApi::$apiBase = 'eu-v2.convertapi.com';

We use PhpUnit and Mockery to write tests, and currently mocking static properties is not supported. After some experimenting, we found the best solution would be to add a setter (like setApiSecret) so that we can finish our unit test. I think other people can also benefit from this, as it's not possible to write a unit test if you set a custom apiBase.

Thoughts about this? I can open a PR if there's interest in this.
PR here: #28

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.