PHP code example of josh / laravel-phantomjs

1. Go to this page and download the library: Download josh/laravel-phantomjs 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/ */

    

josh / laravel-phantomjs example snippets


Josh\Component\PhantomJs\PhantomJsServiceProvider::class

'PhantomJs' => Josh\Component\PhantomJs\Facade\PhantomJs::class

// Tells the client to wait for all resources before rendering

$request = \PhantomJs::get('https://www.google.com/');

\PhantomJs::isLazy()->send($request);

// you can use Facade or app make function to use phantomjs
// ex: app('phantomjs') or \PhantomJs

$request = \PhantomJs::get('https://www.google.com/');

$response = \PhantomJs::send($request);

if($response->getStatus() === 200) {

    // Dump the requested page content
    echo $response->getContent();
}


$request = \PhantomJs::createImage('https://www.google.com/', 'GET');

$request->setOutputFile(public_path('file.jpg'));

$request->setViewportSize(800, 600);

$request->setCaptureDimensions(800, 600, 0, 0);

$response = \PhantomJs::send($request);

if($response->getStatus() === 200) {

    // Dump the requested page content
    echo $response->getContent();
}

$request = \PhantomJs::createPdf('https://www.google.com/', 'GET');
$request->setOutputFile(public_path('document.pdf'));
$request->setFormat('A4');
$request->setOrientation('landscape');
$request->setMargin('1cm');

$response = \PhantomJs::send($request);

if($response->getStatus() === 200) {

    // Dump the requested page content
    echo $response->getContent();
}
bash
 $ php artisan vendor:publish --provider="Josh\Component\PhantomJs\PhantomJsServiceProvider"
 
config/phantomjs.php