PHP code example of kandorlab / phantommagick

1. Go to this page and download the library: Download kandorlab/phantommagick library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kandorlab / phantommagick example snippets


'Anam\PhantomMagick\ConverterServiceProvider'

'Converter' => 'Anam\PhantomMagick\Facades\Converter'

$conv = new \Anam\PhantomMagick\Converter();
$conv->source('http://google.com')
    ->toPdf()
    ->save('/your/destination/path/google.pdf');

use Anam\PhantomMagick\Converter;

$conv = new Converter();
$conv->addPage('<html><body><h1>Welcome to PhantomMagick</h1></body></html>')
    ->addPage('http://facebook.com')
    ->addPage('/html/file/from/local/drive/example.html')
    ->save('/your/destination/path/multipage.pdf');

$conv = new \Anam\PhantomMagick\Converter();
$conv->source('http://google.com')
    ->toPng()
    ->save('/your/destination/path/google.png');

$conv->toPng()

$conv->toJpg()

$conv->toGif()

use Anam\PhantomMagick\Converter;

Converter::make('http://google.com')
    ->toPdf()
    ->download('google.pdf');

Converter::make('http://yahoo.com')
    ->toPng()
    ->download('yahoo.png');

$conv->download('google.pdf', true);

$conv->serve();

use Anam\PhantomMagick\Converter;
use Aws\S3\S3Client;

$client = S3Client::factory([
    'credentials' => [
        'key'    => 'AWS_KEY',
        'secret' => 'AWS_SECRET',
    ],
    'region' => 'your-region',
    'version' => 'latest',
]);

$conv = new Converter();
$conv->adapter($client, 'bucket-name', 'optional/path/prefix')
    ->acl('public')
    ->source('http://google.com')
    ->toPdf()
    ->save('google.pdf');

use Anam\PhantomMagick\Converter;
use Dropbox\Client;

$client = new Client('DROPBOX_TOKEN', 'DROPBOX_APP');

$conv = new Converter();
$conv->adapter($client)
    ->source('https://google.com')
    ->toPdf()
    ->save('dropbox_example.pdf');

use Anam\PhantomMagick\Converter;
use OpenCloud\OpenStack;
use OpenCloud\Rackspace;

$client = new OpenStack(Rackspace::US_IDENTITY_ENDPOINT, array(
    'username' => 'RACKSPACE_USERNAME',
    'password' => 'RACKSPACE_PASSWORD'
));

$store = $client->objectStoreService('cloudFiles', 'SYD');
$container = $store->getContainer('phantom-magick');

$conv = new Converter();
$conv->adapter($container)
    ->source('https://google.com')
    ->toPdf()
    ->save('rackspace_example.pdf');

$conv->setBinary('/phantomjs/binary/path/phantomjs');

new Converter('/Path/to/file/example.html');
// or
Converter::make('/Path/to/file/example.html');
//or
$conv->source('/Path/to/file/example.html');
// or
$conv->source('http://google.com');

$conv->addPage('<html><body><h1>Raw HTML</h1></body></html>');

$conv->format('A4');

array('margin' => '1cm')

$conv->portrait();
$conv->landscape();

array('zoomfactor' => 1)

array('width' => '900px', height => '700px')

$options = [
  'format' => 'A4',
  'zoomfactor' => 1,
  'orientation' => 'portrait',
  'margin' => '1cm'
];

$conv->setPdfOptions($options);
// or
$conv->pdfOptions($options);
// or
$conv->toPdf($options);


$conv->width(1280);

$conv->height(1280);

$conv->quality(90);

$options = [
  'width' => 1280,
  'quality' => 90
];

$conv->setImageOptions($options);
// or
$conv->imageOptions($options);
// or
$conv->toPng($options);
// or
$conv->toJpg($options);
// or
$conv->toGif($options);